OLD | NEW |
(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 if |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 if |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 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 // Removes 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 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. |
| 50 // Return value: 2*|length| characters of ASCII string. |
| 51 static std::string HexEncode(const char* data, size_t length) { |
| 52 return HexEncode(base::StringPiece(data, length)); |
| 53 } |
| 54 |
| 55 // This converts |data.length()| bytes of binary to a |
| 56 // 2*|data.length()|-character hexadecimal representation. |
| 57 // Return value: 2*|data.length()| characters of ASCII string. |
| 58 static std::string HexEncode(base::StringPiece data) { |
| 59 return QuicTextUtilsImpl::HexEncode(data); |
| 60 } |
| 61 |
| 62 // Converts |data| from a hexadecimal ASCII string to a binary string |
| 63 // that is |data.length()/2| bytes long. |
| 64 static std::string HexDecode(base::StringPiece data) { |
| 65 return QuicTextUtilsImpl::HexDecode(data); |
| 66 } |
| 67 |
| 68 // Base64 encodes with no padding |data_len| bytes of |data| into |output|. |
| 69 static void Base64Encode(const uint8_t* data, |
| 70 size_t data_len, |
| 71 std::string* output) { |
| 72 return QuicTextUtilsImpl::Base64Encode(data, data_len, output); |
| 73 } |
| 74 |
| 75 // Returns a string containing hex and ASCII representations of |binary|, |
| 76 // side-by-side in the style of hexdump. Non-printable characters will be |
| 77 // printed as '.' in the ASCII output. |
| 78 // For example, given the input "Hello, QUIC!\01\02\03\04", returns: |
| 79 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...." |
| 80 static std::string HexDump(base::StringPiece binary_data) { |
| 81 return QuicTextUtilsImpl::HexDump(binary_data); |
| 82 } |
| 83 |
| 84 // Returns true if |data| contains any uppercase characters. |
| 85 static bool ContainsUpperCase(base::StringPiece data) { |
| 86 return QuicTextUtilsImpl::ContainsUpperCase(data); |
| 87 } |
| 88 |
| 89 // Splits |data| into a vector of pieces delimited by |delim|. |
| 90 static std::vector<base::StringPiece> Split(base::StringPiece data, |
| 91 char delim) { |
| 92 return QuicTextUtilsImpl::Split(data, delim); |
| 93 } |
| 94 }; |
| 95 |
| 96 } // namespace net |
| 97 |
| 98 #endif // NET_QUIC_PLATFORM_API_QUIC_TEXT_UTILS_H_ |
OLD | NEW |