| 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 escaping strings. | 5 // This file defines utility functions for escaping strings. |
| 6 | 6 |
| 7 #ifndef BASE_STRING_ESCAPE_H__ | 7 #ifndef BASE_STRING_ESCAPE_H__ |
| 8 #define BASE_STRING_ESCAPE_H__ | 8 #define BASE_STRING_ESCAPE_H__ |
| 9 | 9 |
| 10 #include <string> |
| 11 |
| 10 #include "base/string16.h" | 12 #include "base/string16.h" |
| 11 | 13 |
| 12 namespace string_escape { | 14 namespace string_escape { |
| 13 | 15 |
| 14 // Escape |str| appropriately for a javascript string litereal, _appending_ the | 16 // Escape |str| appropriately for a JSON string litereal, _appending_ the |
| 15 // result to |dst|. This will create standard escape sequences (\b, \n), | 17 // result to |dst|. This will create unicode escape sequences (\uXXXX). |
| 16 // hex escape sequences (\x00), and unicode escape sequences (\uXXXX). | |
| 17 // If |put_in_quotes| is true, the result will be surrounded in double quotes. | 18 // If |put_in_quotes| is true, the result will be surrounded in double quotes. |
| 18 // The outputted literal, when interpreted by the browser, should result in a | 19 // The outputted literal, when interpreted by the browser, should result in a |
| 19 // javascript string that is identical and the same length as the input |str|. | 20 // javascript string that is identical and the same length as the input |str|. |
| 20 void JavascriptDoubleQuote(const string16& str, | 21 void JsonDoubleQuote(const std::string& str, |
| 21 bool put_in_quotes, | 22 bool put_in_quotes, |
| 22 std::string* dst); | 23 std::string* dst); |
| 23 | 24 |
| 24 // Similar to the wide version, but for narrow strings. It will not use | 25 void JsonDoubleQuote(const string16& str, |
| 25 // \uXXXX unicode escape sequences. It will pass non-7bit characters directly | 26 bool put_in_quotes, |
| 26 // into the string unencoded, allowing the browser to interpret the encoding. | 27 std::string* dst); |
| 27 // The outputted literal, when interpreted by the browser, could result in a | 28 |
| 28 // javascript string of a different length than the input |str|. | |
| 29 void JavascriptDoubleQuote(const std::string& str, | |
| 30 bool put_in_quotes, | |
| 31 std::string* dst); | |
| 32 | 29 |
| 33 } // namespace string_escape | 30 } // namespace string_escape |
| 34 | 31 |
| 35 #endif // BASE_STRING_ESCAPE_H__ | 32 #endif // BASE_STRING_ESCAPE_H__ |
| OLD | NEW |