string_escape.h revision c7f5f8508d98d5952d42ed7648c2a8f30a4da156
1c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Use of this source code is governed by a BSD-style license that can be
3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// found in the LICENSE file.
4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott//
5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// This file defines utility functions for escaping strings.
6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
7c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef BASE_JSON_STRING_ESCAPE_H_
8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define BASE_JSON_STRING_ESCAPE_H_
9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include <string>
11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "base/string16.h"
13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottnamespace base {
15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// Escape |str| appropriately for a JSON string litereal, _appending_ the
17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// result to |dst|. This will create unicode escape sequences (\uXXXX).
18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// If |put_in_quotes| is true, the result will be surrounded in double quotes.
19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// The outputted literal, when interpreted by the browser, should result in a
20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott// javascript string that is identical and the same length as the input |str|.
21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottvoid JsonDoubleQuote(const std::string& str,
22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     bool put_in_quotes,
23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     std::string* dst);
24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottvoid JsonDoubleQuote(const string16& str,
26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     bool put_in_quotes,
27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott                     std::string* dst);
28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}  // namespace base
31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott
32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif  // BASE_JSON_STRING_ESCAPE_H_
33