| 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 #include "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <ctype.h> | 9 #include <ctype.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| 11 #include <math.h> | 11 #include <math.h> |
| 12 #include <stdarg.h> | 12 #include <stdarg.h> |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <stdlib.h> | 14 #include <stdlib.h> |
| 15 #include <string.h> | 15 #include <string.h> |
| 16 #include <time.h> | 16 #include <time.h> |
| 17 #include <wchar.h> | 17 #include <wchar.h> |
| 18 #include <wctype.h> | 18 #include <wctype.h> |
| 19 | 19 |
| 20 #include <algorithm> | 20 #include <algorithm> |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/singleton.h" | 25 #include "base/singleton.h" |
| 26 #include "base/third_party/dmg_fp/dmg_fp.h" | 26 #include "base/third_party/dmg_fp/dmg_fp.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Force the singleton used by Empty[W]String[16] to be a unique type. This |
| 31 // prevents other code that might accidentally use Singleton<string> from |
| 32 // getting our internal one. |
| 33 struct EmptyStrings { |
| 34 EmptyStrings() {} |
| 35 const std::string s; |
| 36 const std::wstring ws; |
| 37 const string16 s16; |
| 38 }; |
| 39 |
| 30 // Hack to convert any char-like type to its unsigned counterpart. | 40 // Hack to convert any char-like type to its unsigned counterpart. |
| 31 // For example, it will convert char, signed char and unsigned char to unsigned | 41 // For example, it will convert char, signed char and unsigned char to unsigned |
| 32 // char. | 42 // char. |
| 33 template<typename T> | 43 template<typename T> |
| 34 struct ToUnsigned { | 44 struct ToUnsigned { |
| 35 typedef T Unsigned; | 45 typedef T Unsigned; |
| 36 }; | 46 }; |
| 37 | 47 |
| 38 template<> | 48 template<> |
| 39 struct ToUnsigned<char> { | 49 struct ToUnsigned<char> { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 326 } |
| 317 | 327 |
| 318 return true; | 328 return true; |
| 319 } | 329 } |
| 320 | 330 |
| 321 | 331 |
| 322 } // namespace base | 332 } // namespace base |
| 323 | 333 |
| 324 | 334 |
| 325 const std::string& EmptyString() { | 335 const std::string& EmptyString() { |
| 326 return *Singleton<std::string>::get(); | 336 return Singleton<EmptyStrings>::get()->s; |
| 327 } | 337 } |
| 328 | 338 |
| 329 const std::wstring& EmptyWString() { | 339 const std::wstring& EmptyWString() { |
| 330 return *Singleton<std::wstring>::get(); | 340 return Singleton<EmptyStrings>::get()->ws; |
| 341 } |
| 342 |
| 343 const string16& EmptyString16() { |
| 344 return Singleton<EmptyStrings>::get()->s16; |
| 331 } | 345 } |
| 332 | 346 |
| 333 const wchar_t kWhitespaceWide[] = { | 347 const wchar_t kWhitespaceWide[] = { |
| 334 0x0009, // <control-0009> to <control-000D> | 348 0x0009, // <control-0009> to <control-000D> |
| 335 0x000A, | 349 0x000A, |
| 336 0x000B, | 350 0x000B, |
| 337 0x000C, | 351 0x000C, |
| 338 0x000D, | 352 0x000D, |
| 339 0x0020, // Space | 353 0x0020, // Space |
| 340 0x0085, // <control-0085> | 354 0x0085, // <control-0085> |
| (...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 // Each input byte creates two output hex characters. | 1668 // Each input byte creates two output hex characters. |
| 1655 std::string ret(size * 2, '\0'); | 1669 std::string ret(size * 2, '\0'); |
| 1656 | 1670 |
| 1657 for (size_t i = 0; i < size; ++i) { | 1671 for (size_t i = 0; i < size; ++i) { |
| 1658 char b = reinterpret_cast<const char*>(bytes)[i]; | 1672 char b = reinterpret_cast<const char*>(bytes)[i]; |
| 1659 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; | 1673 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; |
| 1660 ret[(i * 2) + 1] = kHexChars[b & 0xf]; | 1674 ret[(i * 2) + 1] = kHexChars[b & 0xf]; |
| 1661 } | 1675 } |
| 1662 return ret; | 1676 return ret; |
| 1663 } | 1677 } |
| OLD | NEW |