From: Sean Middleditch Date: Tue, 19 Jan 2010 02:37:13 +0000 (-0800) Subject: rename jansson namespace to json X-Git-Tag: v1.3~21^2~3^2~2 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=jansson.git;a=commitdiff_plain;h=95bf762eebf3f3c2ed2d690eaf30e6c3885143d4 rename jansson namespace to json --- diff --git a/jansson-impl.hpp b/jansson-impl.hpp index b275eb1..6c2e134 100644 --- a/jansson-impl.hpp +++ b/jansson-impl.hpp @@ -9,7 +9,7 @@ # error "jansson-impl.hpp may only by included from jansson.hpp" #endif -namespace jansson { +namespace json { namespace _private { // assignment operator template @@ -327,7 +327,7 @@ namespace jansson { return json_object_get(_object, _key); } - } // namespace jansson::_private + } // namespace json::_private // construct Value from input Value Value::from(const char* value) { @@ -445,10 +445,10 @@ namespace jansson { return value(); } -} // namespace jansson +} // namespace json // stream JSON value out -std::ostream& operator<<(std::ostream& os, const jansson::Value& value) { +std::ostream& operator<<(std::ostream& os, const json::Value& value) { // get the temporary serialize string char* tmp = value.save_string(); if (tmp != 0) { @@ -460,12 +460,12 @@ std::ostream& operator<<(std::ostream& os, const jansson::Value& value) { } // read JSON value -std::istream& operator>>(std::istream& is, jansson::Value& value) { +std::istream& operator>>(std::istream& is, json::Value& value) { // buffer the remaining bytes into a single string for Jansson std::stringstream tmp; while (is) tmp << static_cast(is.get()); // parse the buffered string - value = jansson::Value::load_string(tmp.str().c_str()); + value = json::Value::load_string(tmp.str().c_str()); return is; } diff --git a/jansson.hpp b/jansson.hpp index 40fb19b..9df3961 100644 --- a/jansson.hpp +++ b/jansson.hpp @@ -14,8 +14,8 @@ #include #include -namespace jansson { - // include Jansson C library in the jansson namespace +namespace json { + // include Jansson C library into the json namespace #include class Iterator; @@ -199,7 +199,7 @@ namespace jansson { const char* _key; }; - } // namespace jansson::_private + } // namespace json::_private // represents any JSON value class Value : public _private::ValueBase<_private::Basic> { @@ -290,13 +290,13 @@ namespace jansson { void* _iter; }; -} // namespace jansson +} // namespace json // stream JSON value out -- inefficient and not recommended for production use -inline std::ostream& operator<<(std::ostream& os, const jansson::Value& value); +inline std::ostream& operator<<(std::ostream& os, const json::Value& value); // read JSON value -- inefficient and not recommended for production use -inline std::istream& operator>>(std::istream& is, jansson::Value& value); +inline std::istream& operator>>(std::istream& is, json::Value& value); // include implementation code #define IN_JANSSON_HPP 1 diff --git a/test.cpp b/test.cpp index 40a6a07..cc10689 100644 --- a/test.cpp +++ b/test.cpp @@ -22,10 +22,10 @@ using namespace std; #define ASSERT_FALSE(p, m) ASSERT_OP(p, true, !=, m) int main() { - jansson::Value e1(jansson::Value::load_file("test.json")); - jansson::Value e2(e1); - jansson::Value e3; - jansson::Value e4(jansson::Value::load_string("{\"foo\": true, \"bar\": \"test\"}")); + json::Value e1(json::Value::load_file("test.json")); + json::Value e2(e1); + json::Value e3; + json::Value e4(json::Value::load_string("{\"foo\": true, \"bar\": \"test\"}")); ASSERT_TRUE(e1.is_object(), "e1 is not an object"); ASSERT_TRUE(e2.is_object(), "e2 is not an object"); @@ -42,7 +42,7 @@ int main() { ASSERT_EQ(e4["foo"].as_boolean(), true, "property has incorrect value"); - jansson::Iterator i(e1.get("web-app")); + json::Iterator i(e1.get("web-app")); ASSERT_EQ(i.key(), "taglib", "first iterator result has incorrect key"); i.next(); ASSERT_EQ(i.key(), "servlet", "first iterator result has incorrect key"); @@ -51,46 +51,46 @@ int main() { i.next(); ASSERT_FALSE(i.valid(), "iterator has more values than expected"); - jansson::Value e5(jansson::Value::from(12.34)); + json::Value e5(json::Value::from(12.34)); ASSERT_TRUE(e5.is_number(), "e5 is not a number after assignment"); ASSERT_EQ(e5.as_real(), 12.34, "e5 has incorrect value after assignment"); - jansson::Value e6(jansson::Value::from(true)); + json::Value e6(json::Value::from(true)); ASSERT_TRUE(e6.is_boolean(), "e6 is not a boolean after assignment"); ASSERT_EQ(e6.as_boolean(), true, "e6 has incorrect value after assignment"); - jansson::Value e7(jansson::Value::from("foobar")); + json::Value e7(json::Value::from("foobar")); ASSERT_TRUE(e7.is_string(), "e7 is not a string after assignment"); ASSERT_EQ(e7.as_string(), "foobar", "e7 has incorrect value after assignment"); - jansson::Value e8(jansson::Value::object()); + json::Value e8(json::Value::object()); ASSERT_TRUE(e8.is_object(), "e8 is not an object after assignment"); - jansson::Value e9(jansson::Value::null()); + json::Value e9(json::Value::null()); ASSERT_TRUE(e9.is_null(), "e9 is not null after assignment"); - jansson::Value e10(jansson::Value::array()); + json::Value e10(json::Value::array()); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); - e10.set_at(0, jansson::Value::from("foobar")); + e10.set_at(0, json::Value::from("foobar")); ASSERT_EQ(e10.size(), 1, "e10 has incorrect number of elements after assignment"); ASSERT_EQ(e10[0].as_string(), "foobar", "e10[0] has incorrect value after assignment"); - e10.set_at(1, jansson::Value::from("foobar")); + e10.set_at(1, json::Value::from("foobar")); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment"); ASSERT_EQ(e10[1].as_string(), "foobar", "e10[0] has incorrect value after assignment"); - e10.set_at(0, jansson::Value::from("barfoo")); + e10.set_at(0, json::Value::from("barfoo")); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment"); ASSERT_EQ(e10[0].as_string(), "barfoo", "e10[0] has incorrect value after assignment"); - e10.set_at(100, jansson::Value::null()); + e10.set_at(100, json::Value::null()); ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment"); ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment"); - e10.insert_at(1, jansson::Value::from("new")); + e10.insert_at(1, json::Value::from("new")); ASSERT_EQ(e10.size(), 3, "e10 has incorrect size after insert"); ASSERT_EQ(e10[1].as_string(), "new", "e10[1] has incorrect value after insert"); ASSERT_EQ(e10[2].as_string(), "foobar", "e10[2] has incorrect value after insert"); @@ -102,19 +102,19 @@ int main() { e10.clear(); ASSERT_EQ(e10.size(), 0, "e10 has incorrect number of elements after clear"); - jansson::Value e11(jansson::Value::object()); + json::Value e11(json::Value::object()); ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment"); - e11.set_key("foo", jansson::Value::from("test")); + e11.set_key("foo", json::Value::from("test")); ASSERT_EQ(e11.size(), 1, "e11 has incorrect number of properties after assignment"); ASSERT_EQ(e11["foo"].as_string(), "test", "e11.foo has incorrect value after assignment"); - e11.set_key("foo", jansson::Value::from("again")); + e11.set_key("foo", json::Value::from("again")); ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment"); ASSERT_EQ(e11.size(), 1, "e11 has incorrect number of properties after assignment"); ASSERT_EQ(e11["foo"].as_string(), "again", "e11.foo has incorrect value after assignment"); - e11.set_key("bar", jansson::Value::from("test")); + e11.set_key("bar", json::Value::from("test")); ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment"); ASSERT_EQ(e11.size(), 2, "e11 has incorrect number of properties after assignment"); ASSERT_EQ(e11["bar"].as_string(), "test", "e11.foo has incorrect value after assignment"); @@ -122,9 +122,9 @@ int main() { e11.clear(); ASSERT_EQ(e11.size(), 0, "e11 has incorrect number of properties after clear"); - jansson::Value e12(jansson::Value::object()); - e12.set_key("foo", jansson::Value::from("test")); - e12.set_key("bar", jansson::Value::from(3)); + json::Value e12(json::Value::object()); + e12.set_key("foo", json::Value::from("test")); + e12.set_key("bar", json::Value::from(3)); char* out_cstr = e12.save_string(0); string out(out_cstr); free(out_cstr); @@ -141,21 +141,21 @@ int main() { outstr << e12; ASSERT_EQ(instr.str(), "{\"bar\": 3,\"foo\": \"test\"}\n", "object did not serialize as expected"); - const jansson::Value e13(e12); + const json::Value e13(e12); ASSERT_EQ(e13["bar"].as_integer(), 3, "e13.bar has incorrect value after copy"); - jansson::Value e14(jansson::Value::object()); + json::Value e14(json::Value::object()); ASSERT_TRUE(e14.is_object(), "e14 is not an object after construction"); - e14.set_key("foo", jansson::Value::object()); + e14.set_key("foo", json::Value::object()); ASSERT_TRUE(e14["foo"].is_object(), "e14.foo is not an object after assignment"); - e14["foo"]["bar"] = jansson::Value::from(42); + e14["foo"]["bar"] = json::Value::from(42); ASSERT_EQ(e14["foo"]["bar"].as_integer(), 42, "e14.foo.bar has incorrect value after assignment"); - jansson::Value e15(jansson::Value::array()); + json::Value e15(json::Value::array()); ASSERT_TRUE(e15.is_array(), "e15 is not an array after construction"); - e15.set_at(0, jansson::Value::from(42)); + e15.set_at(0, json::Value::from(42)); ASSERT_EQ(e15[0].as_integer(), 42, "e15[0] has incorrect value after assignment"); - e15[0] = jansson::Value::from("foo"); + e15[0] = json::Value::from("foo"); ASSERT_EQ(e15[0].as_string(), "foo", "e15[0] has incorrecy value after assignment"); return 0; }