summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libjsonpp/Jamfile.jam14
-rw-r--r--libjsonpp/json.ll5
-rw-r--r--libjsonpp/testEncoding.cpp34
3 files changed, 51 insertions, 2 deletions
diff --git a/libjsonpp/Jamfile.jam b/libjsonpp/Jamfile.jam
index d97edea..3bc7916 100644
--- a/libjsonpp/Jamfile.jam
+++ b/libjsonpp/Jamfile.jam
@@ -55,4 +55,18 @@ run
testSerialise
;
+run
+ testEncoding.cpp
+ pch
+ : : :
+ <define>ROOT=\"$(me)\"
+ <define>BOOST_TEST_DYN_LINK
+ <library>jsonpp
+ <library>boost_utf
+ <library>boost_system
+ <library>boost_filesystem
+ :
+ testEncoding
+ ;
+
package.install install : <install-source-root>. : : jsonpp : [ glob *.h ] ;
diff --git a/libjsonpp/json.ll b/libjsonpp/json.ll
index 58dff7a..860b98c 100644
--- a/libjsonpp/json.ll
+++ b/libjsonpp/json.ll
@@ -152,8 +152,9 @@ escape "\\"
%%
-json::jsonFlexLexer::jsonFlexLexer(std::istream & in, const std::string &) :
- yyFlexLexer(&in, NULL)
+json::jsonFlexLexer::jsonFlexLexer(std::istream & in, const std::string & enc) :
+ yyFlexLexer(&in, NULL),
+ encoding(enc)
{
yy_push_state(VALUE);
acceptValues.push(boost::bind(&jsonFlexLexer::RootValue, this, _1));
diff --git a/libjsonpp/testEncoding.cpp b/libjsonpp/testEncoding.cpp
new file mode 100644
index 0000000..025de2e
--- /dev/null
+++ b/libjsonpp/testEncoding.cpp
@@ -0,0 +1,34 @@
+#include <pch.hpp>
+
+#define BOOST_TEST_MODULE encoding
+#include <boost/test/unit_test.hpp>
+
+#include "jsonpp.h"
+#include <fstream>
+#include <boost/filesystem/path.hpp>
+
+#define XSTR(s) STR(s)
+#define STR(s) #s
+const boost::filesystem::path root(XSTR(ROOT));
+
+static
+std::string
+writeString(const json::Value & v, const std::string & enc)
+{
+ std::stringstream ss;
+ json::serializeValue(v, ss, enc);
+ return ss.str();
+}
+
+BOOST_AUTO_TEST_CASE( parse_latin1 )
+{
+ std::stringstream ss("\"A \xD9\xF1\xEE\xE7\xF4\xD0\xE8 string.\"");
+ BOOST_REQUIRE_EQUAL(19, ss.str().length());
+ BOOST_REQUIRE_EQUAL("A ÙñîçôÐè string.", boost::get<Glib::ustring>(json::parseValue(ss, "latin1")));
+}
+
+BOOST_AUTO_TEST_CASE( write_latin1 )
+{
+ BOOST_REQUIRE_EQUAL("\"A \xD9\xF1\xEE\xE7\xF4\xD0\xE8 string.\"", writeString(Glib::ustring("A ÙñîçôÐè string."), "latin1"));
+}
+