xref: /aosp_15_r20/external/icing/icing/query/advanced_query_parser/util/string-util.h (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
1 // Copyright (C) 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_QUERY_ADVANCED_QUERY_PARSER__STRING_UTIL_H_
16 #define ICING_QUERY_ADVANCED_QUERY_PARSER__STRING_UTIL_H_
17 
18 #include <string>
19 #include <string_view>
20 
21 #include "icing/text_classifier/lib3/utils/base/statusor.h"
22 
23 namespace icing {
24 namespace lib {
25 
26 namespace string_util {
27 
28 // Returns:
29 //   - On success, value with the escapes removed.
30 //   - INVALID_ARGUMENT if an non-escaped quote is encountered.
31 //  Ex. "fo\\\\o" -> "fo\\o"
32 libtextclassifier3::StatusOr<std::string> UnescapeStringValue(
33     std::string_view value);
34 
35 // Returns:
36 //   - On success, string_view pointing to the segment of escaped_string that,
37 //     if unescaped, would match unescaped_token.
38 //   - INVALID_ARGUMENT
39 //  Ex. escaped_string="foo b\\a\\\"r baz", unescaped_token="ba\"r"
40 //      returns "b\\a\\\"r"
41 libtextclassifier3::StatusOr<std::string_view> FindEscapedToken(
42     std::string_view escaped_string, std::string_view unescaped_token);
43 
44 }  // namespace string_util
45 
46 }  // namespace lib
47 }  // namespace icing
48 
49 #endif  // ICING_QUERY_ADVANCED_QUERY_PARSER__STRING_UTIL_H_
50