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

Side by Side Diff: base/json/string_escape.h

Issue 2903773003: Escape invalid code points (Closed)
Patch Set: Update documentation and signed/unsigned comparison Created 3 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
« no previous file with comments | « no previous file | base/json/string_escape.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 escaping strings suitable for JSON. 5 // This file defines utility functions for escaping strings suitable for JSON.
6 6
7 #ifndef BASE_JSON_STRING_ESCAPE_H_ 7 #ifndef BASE_JSON_STRING_ESCAPE_H_
8 #define BASE_JSON_STRING_ESCAPE_H_ 8 #define BASE_JSON_STRING_ESCAPE_H_
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 // Appends to |dest| an escaped version of |str|. Valid UTF-8 code units will 17 // Appends to |dest| an escaped version of |str|. Valid UTF-8 code units and
18 // pass through from the input to the output. Invalid code units will be 18 // characters will pass through from the input to the output. Invalid code
19 // replaced with the U+FFFD replacement character. This function returns true 19 // units and characters will be replaced with the U+FFFD replacement character.
20 // if no replacement was necessary and false if there was a lossy replacement. 20 // This function returns true if no replacement was necessary and false if
21 // On return, |dest| will contain a valid UTF-8 JSON string. 21 // there was a lossy replacement. On return, |dest| will contain a valid UTF-8
22 // JSON string.
22 // 23 //
23 // Non-printing control characters will be escaped as \uXXXX sequences for 24 // Non-printing control characters will be escaped as \uXXXX sequences for
24 // readability. 25 // readability.
25 // 26 //
26 // If |put_in_quotes| is true, then a leading and trailing double-quote mark 27 // If |put_in_quotes| is true, then a leading and trailing double-quote mark
27 // will be appended to |dest| as well. 28 // will be appended to |dest| as well.
28 BASE_EXPORT bool EscapeJSONString(const StringPiece& str, 29 BASE_EXPORT bool EscapeJSONString(const StringPiece& str,
29 bool put_in_quotes, 30 bool put_in_quotes,
30 std::string* dest); 31 std::string* dest);
31 32
(...skipping 19 matching lines...) Expand all
51 // interpret it as UTF-16 and convert it to UTF-8. 52 // interpret it as UTF-16 and convert it to UTF-8.
52 // 53 //
53 // The output of this function takes the *appearance* of JSON but is not in 54 // The output of this function takes the *appearance* of JSON but is not in
54 // fact valid according to RFC 4627. 55 // fact valid according to RFC 4627.
55 BASE_EXPORT std::string EscapeBytesAsInvalidJSONString(const StringPiece& str, 56 BASE_EXPORT std::string EscapeBytesAsInvalidJSONString(const StringPiece& str,
56 bool put_in_quotes); 57 bool put_in_quotes);
57 58
58 } // namespace base 59 } // namespace base
59 60
60 #endif // BASE_JSON_STRING_ESCAPE_H_ 61 #endif // BASE_JSON_STRING_ESCAPE_H_
OLDNEW
« no previous file with comments | « no previous file | base/json/string_escape.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698