blob: 539cb9d7e80ac63cd2e79987f8991a1b016c3644 [file] [log] [blame]
Clemens Arbesserff4559a42020-06-11 12:56:541// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_FIELD_FORMATTER_H_
6#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_FIELD_FORMATTER_H_
7
8#include <map>
9#include <string>
10#include "base/optional.h"
11#include "components/autofill/core/browser/data_model/autofill_profile.h"
12#include "components/autofill/core/browser/data_model/credit_card.h"
13
14namespace autofill_assistant {
15namespace field_formatter {
16
17// Replaces all placeholder occurrences of the form ${key} in |input| with the
18// corresponding value in |mappings|, where |key| is an arbitrary string that
19// does not contain curly braces. Fails if any of the found placeholders is not
20// in |mappings|.
21base::Optional<std::string> FormatString(
22 const std::string& input,
23 const std::map<std::string, std::string>& mappings);
24
25// Same as |FormatString|, but also supports a special case: input patterns
26// containing a single integer are also allowed and implicitly interpreted as
27// ${N}.
28base::Optional<std::string> FormatAutofillString(
29 const std::string& pattern,
30 const std::map<std::string, std::string>& mappings);
31
32// Creates a lookup map for all non-empty autofill and custom
33// AutofillFormatProto::AutofillAssistantCustomField field types in
34// |autofill_data_model|.
35// |locale| should be a locale string such as "en-US".
36template <typename T>
37std::map<std::string, std::string> CreateAutofillMappings(
38 const T& autofill_data_model,
39 const std::string& locale);
40
41} // namespace field_formatter
42} // namespace autofill_assistant
43
44#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_FIELD_FORMATTER_H_