| 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 <stdarg.h>   // va_list | 10 #include <stdarg.h>   // va_list | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 122 // Removes characters in trim_chars from the beginning and end of input. | 122 // Removes characters in trim_chars from the beginning and end of input. | 
| 123 // NOTE: Safe to use the same variable for both input and output. | 123 // NOTE: Safe to use the same variable for both input and output. | 
| 124 bool TrimString(const std::wstring& input, | 124 bool TrimString(const std::wstring& input, | 
| 125                 const wchar_t trim_chars[], | 125                 const wchar_t trim_chars[], | 
| 126                 std::wstring* output); | 126                 std::wstring* output); | 
| 127 bool TrimString(const std::string& input, | 127 bool TrimString(const std::string& input, | 
| 128                 const char trim_chars[], | 128                 const char trim_chars[], | 
| 129                 std::string* output); | 129                 std::string* output); | 
| 130 | 130 | 
| 131 // Trims any whitespace from either end of the input string.  Returns where | 131 // Trims any whitespace from either end of the input string.  Returns where | 
| 132 // whitespace was found.  The non-wide version of this function only looks for | 132 // whitespace was found. | 
| 133 // ASCII whitespace; UTF-8 code-points are not searched for (use the wide | 133 // The non-wide version has two functions: | 
| 134 // version instead). | 134 // * TrimWhitespaceASCII() | 
|  | 135 //   This function is for ASCII strings and only looks for ASCII whitespace; | 
|  | 136 // * TrimWhitespaceUTF8() | 
|  | 137 //   This function is for UTF-8 strings and looks for Unicode whitespace. | 
|  | 138 // Please choose the best one according to your usage. | 
| 135 // NOTE: Safe to use the same variable for both input and output. | 139 // NOTE: Safe to use the same variable for both input and output. | 
| 136 enum TrimPositions { | 140 enum TrimPositions { | 
| 137   TRIM_NONE     = 0, | 141   TRIM_NONE     = 0, | 
| 138   TRIM_LEADING  = 1 << 0, | 142   TRIM_LEADING  = 1 << 0, | 
| 139   TRIM_TRAILING = 1 << 1, | 143   TRIM_TRAILING = 1 << 1, | 
| 140   TRIM_ALL      = TRIM_LEADING | TRIM_TRAILING, | 144   TRIM_ALL      = TRIM_LEADING | TRIM_TRAILING, | 
| 141 }; | 145 }; | 
| 142 TrimPositions TrimWhitespace(const std::wstring& input, | 146 TrimPositions TrimWhitespace(const std::wstring& input, | 
| 143                              TrimPositions positions, | 147                              TrimPositions positions, | 
| 144                              std::wstring* output); | 148                              std::wstring* output); | 
|  | 149 TrimPositions TrimWhitespaceASCII(const std::string& input, | 
|  | 150                                   TrimPositions positions, | 
|  | 151                                   std::string* output); | 
|  | 152 TrimPositions TrimWhitespaceUTF8(const std::string& input, | 
|  | 153                                  TrimPositions positions, | 
|  | 154                                  std::string* output); | 
|  | 155 | 
|  | 156 // Deprecated. This function is only for backward compatibility and calls | 
|  | 157 // TrimWhitespaceASCII(). | 
| 145 TrimPositions TrimWhitespace(const std::string& input, | 158 TrimPositions TrimWhitespace(const std::string& input, | 
| 146                              TrimPositions positions, | 159                              TrimPositions positions, | 
| 147                              std::string* output); | 160                              std::string* output); | 
| 148 | 161 | 
| 149 // Searches  for CR or LF characters.  Removes all contiguous whitespace | 162 // Searches  for CR or LF characters.  Removes all contiguous whitespace | 
| 150 // strings that contain them.  This is useful when trying to deal with text | 163 // strings that contain them.  This is useful when trying to deal with text | 
| 151 // copied from terminals. | 164 // copied from terminals. | 
| 152 // Returns |text, with the following three transformations: | 165 // Returns |text, with the following three transformations: | 
| 153 // (1) Leading and trailing whitespace is trimmed. | 166 // (1) Leading and trailing whitespace is trimmed. | 
| 154 // (2) If |trim_sequences_with_line_breaks| is true, any other whitespace | 167 // (2) If |trim_sequences_with_line_breaks| is true, any other whitespace | 
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 590 // Returns a hex string representation of a binary buffer. | 603 // Returns a hex string representation of a binary buffer. | 
| 591 // The returned hex string will be in upper case. | 604 // The returned hex string will be in upper case. | 
| 592 // This function does not check if |size| is within reasonable limits since | 605 // This function does not check if |size| is within reasonable limits since | 
| 593 // it's written with trusted data in mind. | 606 // it's written with trusted data in mind. | 
| 594 // If you suspect that the data you want to format might be large, | 607 // If you suspect that the data you want to format might be large, | 
| 595 // the absolute max size for |size| should be is | 608 // the absolute max size for |size| should be is | 
| 596 //   std::numeric_limits<size_t>::max() / 2 | 609 //   std::numeric_limits<size_t>::max() / 2 | 
| 597 std::string HexEncode(const void* bytes, size_t size); | 610 std::string HexEncode(const void* bytes, size_t size); | 
| 598 | 611 | 
| 599 #endif  // BASE_STRING_UTIL_H_ | 612 #endif  // BASE_STRING_UTIL_H_ | 
| OLD | NEW | 
|---|