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

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

Issue 2603723002: Add a new QUIC platform API for text utilities. (Closed)
Patch Set: Tests Created 3 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_
6 #define NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_
7
8 #include "base/strings/string_piece.h"
9 #include "net/quic/platform/impl/quic_text_utils_impl.h"
10
11 namespace net {
12
13 // Various utilities for manipulating text.
14 class QuicTextUtils {
15 public:
16 // Returns true of |data| starts with |prefix|, case sensitively.
17 static bool StartsWith(base::StringPiece data, base::StringPiece prefix) {
18 return QuicTextUtilsImpl::StartsWith(data, prefix);
19 }
20
21 // Returns true of |data| ends with |suffix|, case insensitively.
22 static bool EndsWithIgnoreCase(base::StringPiece data,
23 base::StringPiece suffix) {
24 return QuicTextUtilsImpl::EndsWithIgnoreCase(data, suffix);
25 }
26
27 // Returns a new std::string in which |data| has been converted to lower case.
28 static std::string ToLower(base::StringPiece data) {
29 return QuicTextUtilsImpl::ToLower(data);
30 }
31
32 // Remove leading and trailing whitespace from |data|.
33 static void RemoveLeadingAndTrailingWhitespace(base::StringPiece* data) {
34 QuicTextUtilsImpl::RemoveLeadingAndTrailingWhitespace(data);
35 }
36
37 // Returns true if |in| represents a valid uint64, and stores that value in
38 // |out|.
39 static bool StringToUint64(base::StringPiece in, uint64_t* out) {
40 return QuicTextUtilsImpl::StringToUint64(in, out);
41 }
42
43 // Returns a new std::string representing |in|.
44 static std::string Uint64ToString(uint64_t in) {
45 return QuicTextUtilsImpl::Uint64ToString(in);
46 }
47
48 // This converts |length| bytes of binary to a 2*|length|-character
49 // hexadecimal representation.
Jana 2016/12/27 23:52:48 How does the conversion cause the output to be 2*|
Ryan Hamilton 2016/12/28 01:48:38 'cause each byte turns into two ascii bytes: H =>
Jana 2016/12/28 03:11:51 Ah, right. I think the comment should probably say
Ryan Hamilton 2016/12/28 19:15:04 No, the input is a sequence of bytes, each of whic
50 // Return value: 2*|length| characters of ASCII std::string.
51 static std::string HexEncode(const char* data, size_t length) {
52 return HexEncode(base::StringPiece(data, length));
53 }
54
55 // This converts |length| bytes of binary to a 2*|length|-character
56 // hexadecimal representation.
57 // Return value: 2*|length| characters of ASCII std::string.
58 static std::string HexEncode(base::StringPiece data) {
59 return QuicTextUtilsImpl::HexEncode(data);
60 }
61
62 // Converts |data| from a hexadecimal ASCII std::string to binary.
Jana 2016/12/27 23:52:48 nit: "from a hexadecimal number in ASCII std::str
Ryan Hamilton 2016/12/28 01:48:38 But it doesn't take a "number", does it? It just t
63 static std::string HexDecode(base::StringPiece data) {
64 return QuicTextUtilsImpl::HexDecode(data);
65 }
66
67 // Base64 encodes with no padding |data_len| bytes of |data| into |output|.
68 static void Base64Encode(uint8_t* data,
69 size_t data_len,
70 std::string* output) {
71 return QuicTextUtilsImpl::Base64Encode(data, data_len, output);
72 }
73
74 // Returns a std::string containing hex and ASCII representations of |binary|,
75 // side-by-side in the style of hexdump. Non-printable characters will be
76 // printed as '.' in the ASCII output.
77 // For example:
78 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...."
79 static std::string HexDump(base::StringPiece binary_data) {
80 return QuicTextUtilsImpl::HexDump(binary_data);
81 }
82
83 // Returns true if |data| contains any uppercase characters.
84 static bool ContainsUpperCase(base::StringPiece data) {
85 return QuicTextUtilsImpl::ContainsUpperCase(data);
86 }
87
88 // Splits |data| into a vector of pieces delimited by |delim|.
89 static std::vector<base::StringPiece> Split(base::StringPiece data,
90 char delim) {
91 return QuicTextUtilsImpl::Split(data, delim);
92 }
93 };
94
95 } // namespace net
96
97 #endif // NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698