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

Side by Side Diff: base/string_util.cc

Issue 113606: Add JSON-specific escaping, which has different rules from JS escaping. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « base/string_util.h ('k') | chrome/common/json_value_serializer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 19 matching lines...) Expand all
30 // Force the singleton used by Empty[W]String[16] to be a unique type. This 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 31 // prevents other code that might accidentally use Singleton<string> from
32 // getting our internal one. 32 // getting our internal one.
33 struct EmptyStrings { 33 struct EmptyStrings {
34 EmptyStrings() {} 34 EmptyStrings() {}
35 const std::string s; 35 const std::string s;
36 const std::wstring ws; 36 const std::wstring ws;
37 const string16 s16; 37 const string16 s16;
38 }; 38 };
39 39
40 // Hack to convert any char-like type to its unsigned counterpart.
41 // For example, it will convert char, signed char and unsigned char to unsigned
42 // char.
43 template<typename T>
44 struct ToUnsigned {
45 typedef T Unsigned;
46 };
47
48 template<>
49 struct ToUnsigned<char> {
50 typedef unsigned char Unsigned;
51 };
52 template<>
53 struct ToUnsigned<signed char> {
54 typedef unsigned char Unsigned;
55 };
56 template<>
57 struct ToUnsigned<wchar_t> {
58 #if defined(WCHAR_T_IS_UTF16)
59 typedef unsigned short Unsigned;
60 #elif defined(WCHAR_T_IS_UTF32)
61 typedef uint32 Unsigned;
62 #endif
63 };
64 template<>
65 struct ToUnsigned<short> {
66 typedef unsigned short Unsigned;
67 };
68
69 // Used by ReplaceStringPlaceholders to track the position in the string of 40 // Used by ReplaceStringPlaceholders to track the position in the string of
70 // replaced parameters. 41 // replaced parameters.
71 struct ReplacementOffset { 42 struct ReplacementOffset {
72 ReplacementOffset(int parameter, size_t offset) 43 ReplacementOffset(int parameter, size_t offset)
73 : parameter(parameter), 44 : parameter(parameter),
74 offset(offset) {} 45 offset(offset) {}
75 46
76 // Index of the parameter. 47 // Index of the parameter.
77 int parameter; 48 int parameter;
78 49
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 // Each input byte creates two output hex characters. 1634 // Each input byte creates two output hex characters.
1664 std::string ret(size * 2, '\0'); 1635 std::string ret(size * 2, '\0');
1665 1636
1666 for (size_t i = 0; i < size; ++i) { 1637 for (size_t i = 0; i < size; ++i) {
1667 char b = reinterpret_cast<const char*>(bytes)[i]; 1638 char b = reinterpret_cast<const char*>(bytes)[i];
1668 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; 1639 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf];
1669 ret[(i * 2) + 1] = kHexChars[b & 0xf]; 1640 ret[(i * 2) + 1] = kHexChars[b & 0xf];
1670 } 1641 }
1671 return ret; 1642 return ret;
1672 } 1643 }
OLDNEW
« no previous file with comments | « base/string_util.h ('k') | chrome/common/json_value_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698