blob: 9af64518cf41d5b43e9b8024bb485270db69e52f [file] [log] [blame]
Ben Kellyad8343ba2020-10-28 18:48:531// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by an MIT-style license that can be
3// found in the LICENSE file or at https://opensource.org/licenses/MIT.
4
5#ifndef THIRD_PARTY_LIBURLPATTERN_PARSE_H_
6#define THIRD_PARTY_LIBURLPATTERN_PARSE_H_
7
Ben Kellyd18c0e822021-03-05 22:42:178#include <functional>
Ben Kellyad8343ba2020-10-28 18:48:539#include "base/component_export.h"
10#include "third_party/abseil-cpp/absl/status/statusor.h"
11#include "third_party/abseil-cpp/absl/strings/string_view.h"
Ben Kelly36f7ba32020-11-24 19:48:4612#include "third_party/liburlpattern/options.h"
Ben Kellyad8343ba2020-10-28 18:48:5313
Ben Kellyad8343ba2020-10-28 18:48:5314namespace liburlpattern {
15
16class Pattern;
17
Ben Kellyd18c0e822021-03-05 22:42:1718// Define a functor-style callback that will be invoked synchronously by the
19// Parse() method. It will be called for each part of the pattern consisting
20// of text to match strictly against an input. For example, for the pattern:
21//
22// `/foo/:bar.html`
23//
24// The callback will be invoked with `/foo`, `/`, and `.html` separately.
25//
26// The callback should validate the input and potentially perform any encoding
27// necessary. For example, some characters could be percent encoded. The
28// final encoded value for the input should be returned.
29typedef std::function<absl::StatusOr<std::string>(absl::string_view)>
30 EncodeCallback;
31
Dan McArdleb1b92692021-10-28 13:57:2432// Parse a pattern string and return the result. The parse will fail if the
33// input |pattern| is not valid UTF-8. Currently only group names may actually
34// contain non-ASCII characters, however. Unicode characters in other parts of
35// the pattern will cause an error to be returned. A |callback| must be
Ben Kellyd18c0e822021-03-05 22:42:1736// provided to validate and encode plain text parts of the pattern. An
37// |options| value may be provided to override default behavior.
Ben Kellyad8343ba2020-10-28 18:48:5338COMPONENT_EXPORT(LIBURLPATTERN)
Ben Kelly0e5c63e82020-11-12 21:24:0839absl::StatusOr<Pattern> Parse(absl::string_view pattern,
Ben Kellyd18c0e822021-03-05 22:42:1740 EncodeCallback callback,
Ben Kelly36f7ba32020-11-24 19:48:4641 const Options& options = Options());
Ben Kellyad8343ba2020-10-28 18:48:5342
43} // namespace liburlpattern
44
45#endif // THIRD_PARTY_LIBURLPATTERN_PARSE_H_