• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
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 NET_CERT_PKI_STRING_UTIL_H_
6 #define NET_CERT_PKI_STRING_UTIL_H_
7 
8 #include "net/base/net_export.h"
9 
10 #include <stdint.h>
11 
12 #include <string_view>
13 #include <vector>
14 
15 namespace net::string_util {
16 
17 // Returns true if the characters in |str| are all ASCII, false otherwise.
18 NET_EXPORT_PRIVATE bool IsAscii(std::string_view str);
19 
20 // Compares |str1| and |str2| ASCII case insensitively (independent of locale).
21 // Returns true if |str1| and |str2| match.
22 NET_EXPORT_PRIVATE bool IsEqualNoCase(std::string_view str1,
23                                       std::string_view str2);
24 
25 // Compares |str1| and |prefix| ASCII case insensitively (independent of
26 // locale). Returns true if |str1| starts with |prefix|.
27 NET_EXPORT_PRIVATE bool StartsWithNoCase(std::string_view str,
28                                          std::string_view prefix);
29 
30 // Compares |str1| and |suffix| ASCII case insensitively (independent of
31 // locale). Returns true if |str1| starts with |suffix|.
32 NET_EXPORT_PRIVATE bool EndsWithNoCase(std::string_view str,
33                                        std::string_view suffix);
34 
35 // Finds and replaces all occurrences of |find| of non zero length with
36 // |replace| in |str|, returning the result.
37 NET_EXPORT_PRIVATE std::string FindAndReplace(std::string_view str,
38                                               std::string_view find,
39                                               std::string_view replace);
40 
41 // TODO(bbe) transition below to c++20
42 // Compares |str1| and |prefix|. Returns true if |str1| starts with |prefix|.
43 NET_EXPORT_PRIVATE bool StartsWith(std::string_view str,
44                                    std::string_view prefix);
45 
46 // TODO(bbe) transition below to c++20
47 // Compares |str1| and |suffix|. Returns true if |str1| ends with |suffix|.
48 NET_EXPORT_PRIVATE bool EndsWith(std::string_view str, std::string_view suffix);
49 
50 // Returns a hexadecimal string encoding |data| of length |length|.
51 NET_EXPORT_PRIVATE std::string HexEncode(const uint8_t* data, size_t length);
52 
53 // Returns a decimal string representation of |i|.
54 NET_EXPORT_PRIVATE std::string NumberToDecimalString(int i);
55 
56 // Splits |str| on |split_char| returning the list of resulting strings.
57 NET_EXPORT_PRIVATE std::vector<std::string_view> SplitString(
58     std::string_view str,
59     char split_char);
60 
61 }  // namespace net::string_util
62 
63 #endif  // NET_CERT_PKI_STRING_UTIL_H_
64