string_escape.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
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
3// found in the LICENSE file.
4//
5// This file defines utility functions for escaping strings.
6
7#ifndef BASE_JSON_STRING_ESCAPE_H_
8#define BASE_JSON_STRING_ESCAPE_H_
9
10#include <string>
11
12#include "base/string16.h"
13
14namespace base {
15
16// Escape |str| appropriately for a JSON string literal, _appending_ the
17// result to |dst|. This will create unicode escape sequences (\uXXXX).
18// If |put_in_quotes| is true, the result will be surrounded in double quotes.
19// The outputted literal, when interpreted by the browser, should result in a
20// javascript string that is identical and the same length as the input |str|.
21void JsonDoubleQuote(const std::string& str,
22                     bool put_in_quotes,
23                     std::string* dst);
24
25// Same as above, but always returns the result double quoted.
26std::string GetDoubleQuotedJson(const std::string& str);
27
28void JsonDoubleQuote(const string16& str,
29                     bool put_in_quotes,
30                     std::string* dst);
31
32// Same as above, but always returns the result double quoted.
33std::string GetDoubleQuotedJson(const string16& str);
34
35}  // namespace base
36
37#endif  // BASE_JSON_STRING_ESCAPE_H_
38