Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: net/quic/platform/api/quic_text_utils.h

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_ 5 #ifndef NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_
6 #define NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_ 6 #define NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_
7 7
8 #include "base/strings/string_piece.h" 8 #include "net/quic/platform/api/quic_string_piece.h"
9 #include "net/quic/platform/impl/quic_text_utils_impl.h" 9 #include "net/quic/platform/impl/quic_text_utils_impl.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 // Various utilities for manipulating text. 13 // Various utilities for manipulating text.
14 class QuicTextUtils { 14 class QuicTextUtils {
15 public: 15 public:
16 // Returns true if |data| starts with |prefix|, case sensitively. 16 // Returns true if |data| starts with |prefix|, case sensitively.
17 static bool StartsWith(base::StringPiece data, base::StringPiece prefix) { 17 static bool StartsWith(QuicStringPiece data, QuicStringPiece prefix) {
18 return QuicTextUtilsImpl::StartsWith(data, prefix); 18 return QuicTextUtilsImpl::StartsWith(data, prefix);
19 } 19 }
20 20
21 // Returns true if |data| ends with |suffix|, case insensitively. 21 // Returns true if |data| ends with |suffix|, case insensitively.
22 static bool EndsWithIgnoreCase(base::StringPiece data, 22 static bool EndsWithIgnoreCase(QuicStringPiece data, QuicStringPiece suffix) {
23 base::StringPiece suffix) {
24 return QuicTextUtilsImpl::EndsWithIgnoreCase(data, suffix); 23 return QuicTextUtilsImpl::EndsWithIgnoreCase(data, suffix);
25 } 24 }
26 25
27 // Returns a new string in which |data| has been converted to lower case. 26 // Returns a new string in which |data| has been converted to lower case.
28 static std::string ToLower(base::StringPiece data) { 27 static std::string ToLower(QuicStringPiece data) {
29 return QuicTextUtilsImpl::ToLower(data); 28 return QuicTextUtilsImpl::ToLower(data);
30 } 29 }
31 30
32 // Removes leading and trailing whitespace from |data|. 31 // Removes leading and trailing whitespace from |data|.
33 static void RemoveLeadingAndTrailingWhitespace(base::StringPiece* data) { 32 static void RemoveLeadingAndTrailingWhitespace(QuicStringPiece* data) {
34 QuicTextUtilsImpl::RemoveLeadingAndTrailingWhitespace(data); 33 QuicTextUtilsImpl::RemoveLeadingAndTrailingWhitespace(data);
35 } 34 }
36 35
37 // Returns true if |in| represents a valid uint64, and stores that value in 36 // Returns true if |in| represents a valid uint64, and stores that value in
38 // |out|. 37 // |out|.
39 static bool StringToUint64(base::StringPiece in, uint64_t* out) { 38 static bool StringToUint64(QuicStringPiece in, uint64_t* out) {
40 return QuicTextUtilsImpl::StringToUint64(in, out); 39 return QuicTextUtilsImpl::StringToUint64(in, out);
41 } 40 }
42 41
43 // Returns true if |in| represents a valid int, and stores that value in 42 // Returns true if |in| represents a valid int, and stores that value in
44 // |out|. 43 // |out|.
45 static bool StringToInt(base::StringPiece in, int* out) { 44 static bool StringToInt(QuicStringPiece in, int* out) {
46 return QuicTextUtilsImpl::StringToInt(in, out); 45 return QuicTextUtilsImpl::StringToInt(in, out);
47 } 46 }
48 47
49 // Returns true if |in| represents a valid uint32, and stores that value in 48 // Returns true if |in| represents a valid uint32, and stores that value in
50 // |out|. 49 // |out|.
51 static bool StringToUint32(base::StringPiece in, uint32_t* out) { 50 static bool StringToUint32(QuicStringPiece in, uint32_t* out) {
52 return QuicTextUtilsImpl::StringToUint32(in, out); 51 return QuicTextUtilsImpl::StringToUint32(in, out);
53 } 52 }
54 53
55 // Returns true if |in| represents a valid size_t, and stores that value in 54 // Returns true if |in| represents a valid size_t, and stores that value in
56 // |out|. 55 // |out|.
57 static bool StringToSizeT(base::StringPiece in, size_t* out) { 56 static bool StringToSizeT(QuicStringPiece in, size_t* out) {
58 return QuicTextUtilsImpl::StringToSizeT(in, out); 57 return QuicTextUtilsImpl::StringToSizeT(in, out);
59 } 58 }
60 59
61 // Returns a new string representing |in|. 60 // Returns a new string representing |in|.
62 static std::string Uint64ToString(uint64_t in) { 61 static std::string Uint64ToString(uint64_t in) {
63 return QuicTextUtilsImpl::Uint64ToString(in); 62 return QuicTextUtilsImpl::Uint64ToString(in);
64 } 63 }
65 64
66 // This converts |length| bytes of binary to a 2*|length|-character 65 // This converts |length| bytes of binary to a 2*|length|-character
67 // hexadecimal representation. 66 // hexadecimal representation.
68 // Return value: 2*|length| characters of ASCII string. 67 // Return value: 2*|length| characters of ASCII string.
69 static std::string HexEncode(const char* data, size_t length) { 68 static std::string HexEncode(const char* data, size_t length) {
70 return HexEncode(base::StringPiece(data, length)); 69 return HexEncode(QuicStringPiece(data, length));
71 } 70 }
72 71
73 // This converts |data.length()| bytes of binary to a 72 // This converts |data.length()| bytes of binary to a
74 // 2*|data.length()|-character hexadecimal representation. 73 // 2*|data.length()|-character hexadecimal representation.
75 // Return value: 2*|data.length()| characters of ASCII string. 74 // Return value: 2*|data.length()| characters of ASCII string.
76 static std::string HexEncode(base::StringPiece data) { 75 static std::string HexEncode(QuicStringPiece data) {
77 return QuicTextUtilsImpl::HexEncode(data); 76 return QuicTextUtilsImpl::HexEncode(data);
78 } 77 }
79 78
80 // Converts |data| from a hexadecimal ASCII string to a binary string 79 // Converts |data| from a hexadecimal ASCII string to a binary string
81 // that is |data.length()/2| bytes long. 80 // that is |data.length()/2| bytes long.
82 static std::string HexDecode(base::StringPiece data) { 81 static std::string HexDecode(QuicStringPiece data) {
83 return QuicTextUtilsImpl::HexDecode(data); 82 return QuicTextUtilsImpl::HexDecode(data);
84 } 83 }
85 84
86 // Base64 encodes with no padding |data_len| bytes of |data| into |output|. 85 // Base64 encodes with no padding |data_len| bytes of |data| into |output|.
87 static void Base64Encode(const uint8_t* data, 86 static void Base64Encode(const uint8_t* data,
88 size_t data_len, 87 size_t data_len,
89 std::string* output) { 88 std::string* output) {
90 return QuicTextUtilsImpl::Base64Encode(data, data_len, output); 89 return QuicTextUtilsImpl::Base64Encode(data, data_len, output);
91 } 90 }
92 91
93 // Returns a string containing hex and ASCII representations of |binary|, 92 // Returns a string containing hex and ASCII representations of |binary|,
94 // side-by-side in the style of hexdump. Non-printable characters will be 93 // side-by-side in the style of hexdump. Non-printable characters will be
95 // printed as '.' in the ASCII output. 94 // printed as '.' in the ASCII output.
96 // For example, given the input "Hello, QUIC!\01\02\03\04", returns: 95 // For example, given the input "Hello, QUIC!\01\02\03\04", returns:
97 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...." 96 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...."
98 static std::string HexDump(base::StringPiece binary_data) { 97 static std::string HexDump(QuicStringPiece binary_data) {
99 return QuicTextUtilsImpl::HexDump(binary_data); 98 return QuicTextUtilsImpl::HexDump(binary_data);
100 } 99 }
101 100
102 // Returns true if |data| contains any uppercase characters. 101 // Returns true if |data| contains any uppercase characters.
103 static bool ContainsUpperCase(base::StringPiece data) { 102 static bool ContainsUpperCase(QuicStringPiece data) {
104 return QuicTextUtilsImpl::ContainsUpperCase(data); 103 return QuicTextUtilsImpl::ContainsUpperCase(data);
105 } 104 }
106 105
107 // Splits |data| into a vector of pieces delimited by |delim|. 106 // Splits |data| into a vector of pieces delimited by |delim|.
108 static std::vector<base::StringPiece> Split(base::StringPiece data, 107 static std::vector<QuicStringPiece> Split(QuicStringPiece data, char delim) {
109 char delim) {
110 return QuicTextUtilsImpl::Split(data, delim); 108 return QuicTextUtilsImpl::Split(data, delim);
111 } 109 }
112 }; 110 };
113 111
114 } // namespace net 112 } // namespace net
115 113
116 #endif // NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_ 114 #endif // NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_
OLDNEW
« no previous file with comments | « net/quic/platform/api/quic_string_piece.h ('k') | net/quic/platform/api/quic_text_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698