summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp18
-rw-r--r--base/json/json_reader.cc (renamed from base/json_reader.cc)6
-rw-r--r--base/json/json_reader.h (renamed from base/json_reader.h)12
-rw-r--r--base/json/json_reader_unittest.cc (renamed from base/json_reader_unittest.cc)6
-rw-r--r--base/json/json_writer.cc (renamed from base/json_writer.cc)18
-rw-r--r--base/json/json_writer.h (renamed from base/json_writer.h)10
-rw-r--r--base/json/json_writer_unittest.cc (renamed from base/json_writer_unittest.cc)8
-rw-r--r--base/json/string_escape.cc (renamed from base/string_escape.cc)10
-rw-r--r--base/json/string_escape.h (renamed from base/string_escape.h)10
-rw-r--r--base/json/string_escape_unittest.cc (renamed from base/string_escape_unittest.cc)24
10 files changed, 75 insertions, 47 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 2ca5cfb..6f6790c 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -149,10 +149,12 @@
'id_map.h',
'image_util.cc',
'image_util.h',
- 'json_reader.cc',
- 'json_reader.h',
- 'json_writer.cc',
- 'json_writer.h',
+ 'json/json_reader.cc',
+ 'json/json_reader.h',
+ 'json/json_writer.cc',
+ 'json/json_writer.h',
+ 'json/string_escape.cc',
+ 'json/string_escape.h',
'keyboard_code_conversion_gtk.cc',
'keyboard_code_conversion_gtk.h',
'keyboard_codes.h',
@@ -279,8 +281,6 @@
'stl_util-inl.h',
'string16.cc',
'string16.h',
- 'string_escape.cc',
- 'string_escape.h',
'string_piece.cc',
'string_piece.h',
'string_tokenizer.h',
@@ -578,8 +578,9 @@
'i18n/file_util_icu_unittest.cc',
'i18n/icu_string_conversions_unittest.cc',
'i18n/word_iterator_unittest.cc',
- 'json_reader_unittest.cc',
- 'json_writer_unittest.cc',
+ 'json/json_reader_unittest.cc',
+ 'json/json_writer_unittest.cc',
+ 'json/string_escape_unittest.cc',
'lazy_instance_unittest.cc',
'leak_tracker_unittest.cc',
'linked_list_unittest.cc',
@@ -607,7 +608,6 @@
'singleton_unittest.cc',
'stack_container_unittest.cc',
'stats_table_unittest.cc',
- 'string_escape_unittest.cc',
'string_piece_unittest.cc',
'string_tokenizer_unittest.cc',
'string_util_unittest.cc',
diff --git a/base/json_reader.cc b/base/json/json_reader.cc
index ca33cb2..06d790c 100644
--- a/base/json_reader.cc
+++ b/base/json/json_reader.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/json_reader.h"
+#include "base/json/json_reader.h"
#include "base/float_util.h"
#include "base/logging.h"
@@ -11,6 +11,8 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
+namespace base {
+
static const JSONReader::Token kInvalidToken(JSONReader::Token::INVALID_TOKEN,
0, 0);
static const int kStackLimit = 100;
@@ -636,3 +638,5 @@ void JSONReader::SetErrorMessage(const char* description,
error_message_ = FormatErrorMessage(line_number, column_number, description);
}
+
+} // namespace base
diff --git a/base/json_reader.h b/base/json/json_reader.h
index 9c4065b..9a82e7f 100644
--- a/base/json_reader.h
+++ b/base/json/json_reader.h
@@ -28,8 +28,8 @@
// only a convenience for the common uses with more complex configuration going
// on the instance.
-#ifndef BASE_JSON_READER_H_
-#define BASE_JSON_READER_H_
+#ifndef BASE_JSON_JSON_READER_H_
+#define BASE_JSON_JSON_READER_H_
#include <string>
@@ -38,6 +38,8 @@
class Value;
+namespace base {
+
class JSONReader {
public:
// A struct to hold a JS token.
@@ -119,7 +121,7 @@ class JSONReader {
static std::string FormatErrorMessage(int line, int column,
const char* description);
- DISALLOW_EVIL_CONSTRUCTORS(JSONReader);
+ DISALLOW_COPY_AND_ASSIGN(JSONReader);
FRIEND_TEST(JSONReaderTest, Reading);
FRIEND_TEST(JSONReaderTest, ErrorMessages);
@@ -183,4 +185,6 @@ class JSONReader {
std::string error_message_;
};
-#endif // BASE_JSON_READER_H_
+} // namespace base
+
+#endif // BASE_JSON_JSON_READER_H_
diff --git a/base/json_reader_unittest.cc b/base/json/json_reader_unittest.cc
index 7f47b8e..8ae51c5 100644
--- a/base/json_reader_unittest.cc
+++ b/base/json/json_reader_unittest.cc
@@ -3,11 +3,13 @@
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
-#include "base/json_reader.h"
+#include "base/json/json_reader.h"
#include "base/scoped_ptr.h"
#include "base/values.h"
#include "build/build_config.h"
+namespace base {
+
TEST(JSONReaderTest, Reading) {
// some whitespace checking
scoped_ptr<Value> root;
@@ -514,3 +516,5 @@ TEST(JSONReaderTest, ErrorMessages) {
error_message);
}
+
+} // namespace base
diff --git a/base/json_writer.cc b/base/json/json_writer.cc
index 25df120..dffa3da 100644
--- a/base/json_writer.cc
+++ b/base/json/json_writer.cc
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/json_writer.h"
+#include "base/json/json_writer.h"
+#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/values.h"
-#include "base/string_escape.h"
#include "base/utf_string_conversions.h"
+namespace base {
+
#if defined(OS_WIN)
static const char kPrettyPrintLineEnding[] = "\r\n";
#else
@@ -101,11 +103,9 @@ void JSONWriter::BuildJSONString(const Value* const node,
bool result = node->GetAsString(&value);
DCHECK(result);
if (escape) {
- string_escape::JsonDoubleQuote(UTF8ToUTF16(value),
- true,
- json_string_);
+ JsonDoubleQuote(UTF8ToUTF16(value), true, json_string_);
} else {
- string_escape::JsonDoubleQuote(value, true, json_string_);
+ JsonDoubleQuote(value, true, json_string_);
}
break;
}
@@ -186,9 +186,7 @@ void JSONWriter::BuildJSONString(const Value* const node,
}
void JSONWriter::AppendQuotedString(const std::wstring& str) {
- string_escape::JsonDoubleQuote(WideToUTF16Hack(str),
- true,
- json_string_);
+ JsonDoubleQuote(WideToUTF16Hack(str), true, json_string_);
}
void JSONWriter::IndentLine(int depth) {
@@ -196,3 +194,5 @@ void JSONWriter::IndentLine(int depth) {
// reallocating.
json_string_->append(std::string(depth * 3, ' '));
}
+
+} // namespace base
diff --git a/base/json_writer.h b/base/json/json_writer.h
index f8d0241..29aa69d 100644
--- a/base/json_writer.h
+++ b/base/json/json_writer.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_JSON_WRITER_H_
-#define BASE_JSON_WRITER_H_
+#ifndef BASE_JSON_JSON_WRITER_H_
+#define BASE_JSON_JSON_WRITER_H_
#include <string>
@@ -11,6 +11,8 @@
class Value;
+namespace base {
+
class JSONWriter {
public:
// Given a root node, generates a JSON string and puts it into |json|.
@@ -52,4 +54,6 @@ class JSONWriter {
DISALLOW_COPY_AND_ASSIGN(JSONWriter);
};
-#endif // BASE_JSON_WRITER_H_
+} // namespace base
+
+#endif // BASE_JSON_JSON_WRITER_H_
diff --git a/base/json_writer_unittest.cc b/base/json/json_writer_unittest.cc
index 2792982..cd2a6fe 100644
--- a/base/json_writer_unittest.cc
+++ b/base/json/json_writer_unittest.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "testing/gtest/include/gtest/gtest.h"
-#include "base/json_writer.h"
+#include "base/json/json_writer.h"
#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
TEST(JSONWriterTest, Writing) {
// Test null
@@ -75,3 +77,5 @@ TEST(JSONWriterTest, Writing) {
output_js);
#undef JSON_NEWLINE
}
+
+} // namespace base
diff --git a/base/string_escape.cc b/base/json/string_escape.cc
index 0fecfa1..4e1418c 100644
--- a/base/string_escape.cc
+++ b/base/json/string_escape.cc
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/string_escape.h"
+#include "base/json/string_escape.h"
#include <string>
#include "base/string_util.h"
-namespace string_escape {
+namespace base {
+
+namespace {
// Try to escape |c| as a "SingleEscapeCharacter" (\n, etc). If successful,
// returns true and appends the escape sequence to |dst|. This isn't required
@@ -72,6 +74,8 @@ void JsonDoubleQuoteT(const STR& str,
dst->push_back('"');
}
+} // namespace
+
void JsonDoubleQuote(const std::string& str,
bool put_in_quotes,
std::string* dst) {
@@ -84,4 +88,4 @@ void JsonDoubleQuote(const string16& str,
JsonDoubleQuoteT(str, put_in_quotes, dst);
}
-} // namespace string_escape
+} // namespace base
diff --git a/base/string_escape.h b/base/json/string_escape.h
index 3f0bf3f..7d74021 100644
--- a/base/string_escape.h
+++ b/base/json/string_escape.h
@@ -4,14 +4,14 @@
//
// This file defines utility functions for escaping strings.
-#ifndef BASE_STRING_ESCAPE_H__
-#define BASE_STRING_ESCAPE_H__
+#ifndef BASE_JSON_STRING_ESCAPE_H_
+#define BASE_JSON_STRING_ESCAPE_H_
#include <string>
#include "base/string16.h"
-namespace string_escape {
+namespace base {
// Escape |str| appropriately for a JSON string litereal, _appending_ the
// result to |dst|. This will create unicode escape sequences (\uXXXX).
@@ -27,6 +27,6 @@ void JsonDoubleQuote(const string16& str,
std::string* dst);
-} // namespace string_escape
+} // namespace base
-#endif // BASE_STRING_ESCAPE_H__
+#endif // BASE_JSON_STRING_ESCAPE_H_
diff --git a/base/string_escape_unittest.cc b/base/json/string_escape_unittest.cc
index d731dc1..a3d6262 100644
--- a/base/string_escape_unittest.cc
+++ b/base/json/string_escape_unittest.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "testing/gtest/include/gtest/gtest.h"
-#include "base/string_escape.h"
+#include "base/json/string_escape.h"
#include "base/string_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
namespace {
@@ -24,17 +26,17 @@ TEST(StringEscapeTest, JsonDoubleQuoteNarrow) {
for (size_t i = 0; i < arraysize(json_narrow_cases); ++i) {
std::string in = json_narrow_cases[i].to_escape;
std::string out;
- string_escape::JsonDoubleQuote(in, false, &out);
+ JsonDoubleQuote(in, false, &out);
EXPECT_EQ(std::string(json_narrow_cases[i].escaped), out);
}
std::string in = json_narrow_cases[0].to_escape;
std::string out;
- string_escape::JsonDoubleQuote(in, false, &out);
+ JsonDoubleQuote(in, false, &out);
// test quoting
std::string out_quoted;
- string_escape::JsonDoubleQuote(in, true, &out_quoted);
+ JsonDoubleQuote(in, true, &out_quoted);
EXPECT_EQ(out.length() + 2, out_quoted.length());
EXPECT_EQ(out_quoted.find(out), 1U);
@@ -45,7 +47,7 @@ TEST(StringEscapeTest, JsonDoubleQuoteNarrow) {
std::string expected = "test\\u0000";
expected += json_narrow_cases[0].escaped;
out.clear();
- string_escape::JsonDoubleQuote(in, false, &out);
+ JsonDoubleQuote(in, false, &out);
EXPECT_EQ(expected, out);
}
@@ -69,17 +71,17 @@ TEST(StringEscapeTest, JsonDoubleQuoteWide) {
for (size_t i = 0; i < arraysize(json_wide_cases); ++i) {
std::string out;
string16 in = WideToUTF16(json_wide_cases[i].to_escape);
- string_escape::JsonDoubleQuote(in, false, &out);
+ JsonDoubleQuote(in, false, &out);
EXPECT_EQ(std::string(json_wide_cases[i].escaped), out);
}
string16 in = WideToUTF16(json_wide_cases[0].to_escape);
std::string out;
- string_escape::JsonDoubleQuote(in, false, &out);
+ JsonDoubleQuote(in, false, &out);
// test quoting
std::string out_quoted;
- string_escape::JsonDoubleQuote(in, true, &out_quoted);
+ JsonDoubleQuote(in, true, &out_quoted);
EXPECT_EQ(out.length() + 2, out_quoted.length());
EXPECT_EQ(out_quoted.find(out), 1U);
@@ -90,6 +92,8 @@ TEST(StringEscapeTest, JsonDoubleQuoteWide) {
std::string expected = "test\\u0000";
expected += json_wide_cases[0].escaped;
out.clear();
- string_escape::JsonDoubleQuote(in, false, &out);
+ JsonDoubleQuote(in, false, &out);
EXPECT_EQ(expected, out);
}
+
+} // namespace base