| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file defines utility functions for working with strings. | 5 // This file defines utility functions for working with strings. |
| 6 | 6 |
| 7 #ifndef BASE_STRING_UTIL_H_ | 7 #ifndef BASE_STRING_UTIL_H_ |
| 8 #define BASE_STRING_UTIL_H_ | 8 #define BASE_STRING_UTIL_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Removes characters in trim_chars from the beginning and end of input. | 121 // Removes characters in trim_chars from the beginning and end of input. |
| 122 // NOTE: Safe to use the same variable for both input and output. | 122 // NOTE: Safe to use the same variable for both input and output. |
| 123 bool TrimString(const std::wstring& input, | 123 bool TrimString(const std::wstring& input, |
| 124 const wchar_t trim_chars[], | 124 const wchar_t trim_chars[], |
| 125 std::wstring* output); | 125 std::wstring* output); |
| 126 bool TrimString(const std::string& input, | 126 bool TrimString(const std::string& input, |
| 127 const char trim_chars[], | 127 const char trim_chars[], |
| 128 std::string* output); | 128 std::string* output); |
| 129 | 129 |
| 130 // Trims any whitespace from either end of the input string. Returns where | 130 // Trims any whitespace from either end of the input string. Returns where |
| 131 // whitespace was found. The non-wide version of this function only looks for | 131 // whitespace was found. |
| 132 // ASCII whitespace; UTF-8 code-points are not searched for (use the wide | 132 // The non-wide version has two functions: |
| 133 // version instead). | 133 // * TrimWhitespaceASCII() |
| 134 // This function is for ASCII strings and only looks for ASCII whitespace; |
| 135 // * TrimWhitespaceUTF8() |
| 136 // This function is for UTF-8 strings and looks for Unicode whitespace. |
| 137 // Please choose the best one according to your usage. |
| 134 // NOTE: Safe to use the same variable for both input and output. | 138 // NOTE: Safe to use the same variable for both input and output. |
| 135 enum TrimPositions { | 139 enum TrimPositions { |
| 136 TRIM_NONE = 0, | 140 TRIM_NONE = 0, |
| 137 TRIM_LEADING = 1 << 0, | 141 TRIM_LEADING = 1 << 0, |
| 138 TRIM_TRAILING = 1 << 1, | 142 TRIM_TRAILING = 1 << 1, |
| 139 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, | 143 TRIM_ALL = TRIM_LEADING | TRIM_TRAILING, |
| 140 }; | 144 }; |
| 141 TrimPositions TrimWhitespace(const std::wstring& input, | 145 TrimPositions TrimWhitespace(const std::wstring& input, |
| 142 TrimPositions positions, | 146 TrimPositions positions, |
| 143 std::wstring* output); | 147 std::wstring* output); |
| 148 TrimPositions TrimWhitespaceASCII(const std::string& input, |
| 149 TrimPositions positions, |
| 150 std::string* output); |
| 151 TrimPositions TrimWhitespaceUTF8(const std::string& input, |
| 152 TrimPositions positions, |
| 153 std::string* output); |
| 154 |
| 155 // Deprecated. This function is only for backward compatibility and calls |
| 156 // TrimWhitespaceASCII(). |
| 144 TrimPositions TrimWhitespace(const std::string& input, | 157 TrimPositions TrimWhitespace(const std::string& input, |
| 145 TrimPositions positions, | 158 TrimPositions positions, |
| 146 std::string* output); | 159 std::string* output); |
| 147 | 160 |
| 148 // Searches for CR or LF characters. Removes all contiguous whitespace | 161 // Searches for CR or LF characters. Removes all contiguous whitespace |
| 149 // strings that contain them. This is useful when trying to deal with text | 162 // strings that contain them. This is useful when trying to deal with text |
| 150 // copied from terminals. | 163 // copied from terminals. |
| 151 // Returns |text, with the following three transformations: | 164 // Returns |text, with the following three transformations: |
| 152 // (1) Leading and trailing whitespace is trimmed. | 165 // (1) Leading and trailing whitespace is trimmed. |
| 153 // (2) If |trim_sequences_with_line_breaks| is true, any other whitespace | 166 // (2) If |trim_sequences_with_line_breaks| is true, any other whitespace |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // Returns a hex string representation of a binary buffer. | 579 // Returns a hex string representation of a binary buffer. |
| 567 // The returned hex string will be in upper case. | 580 // The returned hex string will be in upper case. |
| 568 // This function does not check if |size| is within reasonable limits since | 581 // This function does not check if |size| is within reasonable limits since |
| 569 // it's written with trusted data in mind. | 582 // it's written with trusted data in mind. |
| 570 // If you suspect that the data you want to format might be large, | 583 // If you suspect that the data you want to format might be large, |
| 571 // the absolute max size for |size| should be is | 584 // the absolute max size for |size| should be is |
| 572 // std::numeric_limits<size_t>::max() / 2 | 585 // std::numeric_limits<size_t>::max() / 2 |
| 573 std::string HexEncode(const void* bytes, size_t size); | 586 std::string HexEncode(const void* bytes, size_t size); |
| 574 | 587 |
| 575 #endif // BASE_STRING_UTIL_H_ | 588 #endif // BASE_STRING_UTIL_H_ |
| OLD | NEW |