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

Side by Side Diff: base/string_util.h

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_escape_unittest.cc ('k') | base/string_util.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 // 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 588
589 // Returns a hex string representation of a binary buffer. 589 // Returns a hex string representation of a binary buffer.
590 // The returned hex string will be in upper case. 590 // The returned hex string will be in upper case.
591 // This function does not check if |size| is within reasonable limits since 591 // This function does not check if |size| is within reasonable limits since
592 // it's written with trusted data in mind. 592 // it's written with trusted data in mind.
593 // If you suspect that the data you want to format might be large, 593 // If you suspect that the data you want to format might be large,
594 // the absolute max size for |size| should be is 594 // the absolute max size for |size| should be is
595 // std::numeric_limits<size_t>::max() / 2 595 // std::numeric_limits<size_t>::max() / 2
596 std::string HexEncode(const void* bytes, size_t size); 596 std::string HexEncode(const void* bytes, size_t size);
597 597
598 // Hack to convert any char-like type to its unsigned counterpart.
599 // For example, it will convert char, signed char and unsigned char to unsigned
600 // char.
601 template<typename T>
602 struct ToUnsigned {
603 typedef T Unsigned;
604 };
605
606 template<>
607 struct ToUnsigned<char> {
608 typedef unsigned char Unsigned;
609 };
610 template<>
611 struct ToUnsigned<signed char> {
612 typedef unsigned char Unsigned;
613 };
614 template<>
615 struct ToUnsigned<wchar_t> {
616 #if defined(WCHAR_T_IS_UTF16)
617 typedef unsigned short Unsigned;
618 #elif defined(WCHAR_T_IS_UTF32)
619 typedef uint32 Unsigned;
620 #endif
621 };
622 template<>
623 struct ToUnsigned<short> {
624 typedef unsigned short Unsigned;
625 };
598 626
599 #endif // BASE_STRING_UTIL_H_ 627 #endif // BASE_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « base/string_escape_unittest.cc ('k') | base/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698