Skip to content

Ticket 10272 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7adb242
Full merge from trunk at revision 41356 of entire boost-root tree.
Beman Nov 25, 2007
88ee5f0
Full merge from trunk at revision 41356 of entire boost-root tree.
Beman Nov 25, 2007
f9ea6a1
Copy property_tree to release branch.
Oct 3, 2009
235fedb
rm cmake from the release branch before it goes out broken. Policy d…
straszheim Oct 17, 2009
750d471
Merge standards conformance fixes for Boost.PropertyTree
DougGregor May 9, 2010
db59ef4
Merge documentation fixes.
danieljames Jun 26, 2010
d1d123d
Merged r59734 and r61606 from trunk; fixes #3594 and #4092
jewillco Jul 3, 2010
ab64e13
Merge long-overdue PTree changes to release (boost)
Oct 15, 2010
d0d7145
Merge long-overdue PTree changes to release (libs)
Oct 15, 2010
61c44fd
Merge more PTree fixes to release (boost)
Oct 15, 2010
5cbf7ea
Make PTree's parser_writer_settings fields non-const, so that the str…
Nov 10, 2010
043ec14
Merge simple fix for non-ascii XML parsing to release. Fixes bug 4340.
Nov 10, 2010
1f20512
Merged revisions 66498 via svnmerge from
Nov 11, 2010
6386e5f
Merge r68990 to release just before 2.46.1, because it's a critical a…
Mar 8, 2011
3e9c566
Merge r68990-68993, several fixes to PTree. Fixes bug 1678. Fixes bug…
May 16, 2011
b183df1
Merge r68990-68993, several fixes to PTree. Fixes bug 1678. Fixes bug…
May 16, 2011
afb7767
Merge UTF-8 XML support improvements (r69622) to release. Fixes bug 5…
May 16, 2011
56cfb6b
Merge r70664-70666 to release. Improves INI parser and brings improve…
May 16, 2011
9b707a0
Merge [72000],[72001],[72003], [74691], [75587], [75589], [75590], an…
Jan 13, 2012
c3e6430
Merge r78550 to release. Fixes an outdated test to work again. Fixes …
May 27, 2012
23d8e7b
Delete files that shouldn't have been there. These are either SVN con…
Dec 20, 2013
bd1b832
Create first merge point for Git.
Dec 20, 2013
e6958d6
Include recent bugfixes in release: #4391, #8879, #8776.
Feb 10, 2014
85f8d88
Merge branch 'develop'.
Feb 24, 2014
8af8b6b
support for non-std::string keys
sanderbog Apr 15, 2014
4e16d57
Ticket 10272
sanderbog Jul 31, 2014
540f5d2
superfluous typename's
sanderbog Aug 24, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions include/boost/property_tree/detail/info_parser_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,13 @@ namespace boost { namespace property_tree { namespace info_parser
}
return result;
}

// Detect whitespace in a not very smart way.
template <class Ch>
bool is_ascii_space(Ch c)
{
// Everything outside ASCII is not space.
unsigned n = c;
if (n > 127)
return false;
return isspace(c);
}

// Advance pointer past whitespace
template<class Ch>
void skip_whitespace(const Ch *&text)
{
using namespace std;
while (is_ascii_space(*text))
while (isspace(*text))
++text;
}

Expand All @@ -88,7 +77,7 @@ namespace boost { namespace property_tree { namespace info_parser
using namespace std;
skip_whitespace(text);
const Ch *start = text;
while (!is_ascii_space(*text) && *text != Ch(';') && *text != Ch('\0'))
while (!isspace(*text) && *text != Ch(';') && *text != Ch('\0'))
++text;
return expand_escapes(start, text);
}
Expand All @@ -102,7 +91,7 @@ namespace boost { namespace property_tree { namespace info_parser
const Ch *start = text;
while (*text != Ch('\0') && *text != Ch(';'))
++text;
while (text > start && is_ascii_space(*(text - 1)))
while (text > start && isspace(*(text - 1)))
--text;
return expand_escapes(start, text);
}
Expand Down
14 changes: 7 additions & 7 deletions include/boost/property_tree/detail/json_parser_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ namespace boost { namespace property_tree { namespace json_parser
template<class Ptree>
struct context
{

typedef typename Ptree::key_type::value_type Ch;
typedef std::basic_string<Ch> Str;
typedef typename Ptree::key_type Str;
typedef typename Str::value_type Ch;
typedef typename std::vector<Ch>::iterator It;

Str string;
Expand Down Expand Up @@ -162,7 +161,8 @@ namespace boost { namespace property_tree { namespace json_parser
{

typedef context<Ptree> Context;
typedef typename Ptree::key_type::value_type Ch;
typedef typename Ptree::key_type Str;
typedef typename Str::value_type Ch;

mutable Context c;

Expand Down Expand Up @@ -239,8 +239,8 @@ namespace boost { namespace property_tree { namespace json_parser
= !ch_p("-") >>
(ch_p("0") | (range_p(Ch('1'), Ch('9')) >> *digit_p)) >>
!(ch_p(".") >> +digit_p) >>
!(chset_p(detail::widen<Ch>("eE").c_str()) >>
!chset_p(detail::widen<Ch>("-+").c_str()) >>
!(chset_p(detail::widen<Str>("eE").c_str()) >>
!chset_p(detail::widen<Str>("-+").c_str()) >>
+digit_p)
;

Expand All @@ -255,7 +255,7 @@ namespace boost { namespace property_tree { namespace json_parser
;

escape
= chset_p(detail::widen<Ch>("\"\\/bfnrt").c_str())
= chset_p(detail::widen<Str>("\"\\/bfnrt").c_str())
[typename Context::a_escape(self.c)]
| 'u' >> uint_parser<unsigned long, 16, 4, 4>()
[typename Context::a_unicode(self.c)]
Expand Down
31 changes: 15 additions & 16 deletions include/boost/property_tree/detail/ptree_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,48 @@ namespace boost { namespace property_tree { namespace detail


// Naively convert narrow string to another character type
template<class Ch>
std::basic_string<Ch> widen(const char *text)
template<typename Str>
Str widen(const char *text)
{
std::basic_string<Ch> result;
Str result;
while (*text)
{
result += Ch(*text);
result += typename Str::value_type(*text);
++text;
}
return result;
}

// Naively convert string to narrow character type
template<class Ch>
std::string narrow(const Ch *text)
template<typename Str, typename char_type>
Str narrow(const char_type *text)
{
std::string result;
Str result;
while (*text)
{
if (*text < 0 || *text > (std::numeric_limits<char>::max)())
result += '*';
else
result += char(*text);
result += typename Str::value_type(*text);
++text;
}
return result;
}

// Remove trailing and leading spaces
template<class Ch>
std::basic_string<Ch> trim(const std::basic_string<Ch> &s,
const std::locale &loc = std::locale())
template<class Str>
Str trim(const Str &s, const std::locale &loc = std::locale())
{
typename std::basic_string<Ch>::const_iterator first = s.begin();
typename std::basic_string<Ch>::const_iterator end = s.end();
typename Str::const_iterator first = s.begin();
typename Str::const_iterator end = s.end();
while (first != end && std::isspace(*first, loc))
++first;
if (first == end)
return std::basic_string<Ch>();
typename std::basic_string<Ch>::const_iterator last = end;
return Str();
typename Str::const_iterator last = end;
do --last; while (std::isspace(*last, loc));
if (first != s.begin() || last + 1 != end)
return std::basic_string<Ch>(first, last + 1);
return Str(first, last + 1);
else
return s;
}
Expand Down
15 changes: 6 additions & 9 deletions include/boost/property_tree/detail/xml_parser_read_rapidxml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ namespace boost { namespace property_tree { namespace xml_parser
if (node->first_attribute())
{
Ptree &pt_attr_root = pt_node.push_back(
std::make_pair(xmlattr<Ch>(), Ptree()))->second;
std::make_pair(xmlattr<typename Ptree::key_type>(), Ptree()))->second;
for (xml_attribute<Ch> *attr = node->first_attribute();
attr; attr = attr->next_attribute())
{
Ptree &pt_attr = pt_attr_root.push_back(
std::make_pair(attr->name(), Ptree()))->second;
pt_attr.data() = std::basic_string<Ch>(attr->value(),
attr->value_size());
pt_attr.data() = typename Ptree::key_type(attr->value(), attr->value_size());
}
}

Expand All @@ -61,21 +60,19 @@ namespace boost { namespace property_tree { namespace xml_parser
case node_cdata:
{
if (flags & no_concat_text)
pt.push_back(std::make_pair(xmltext<Ch>(),
pt.push_back(std::make_pair(xmltext<typename Ptree::key_type>(),
Ptree(node->value())));
else
pt.data() += std::basic_string<Ch>(node->value(),
node->value_size());
pt.data() += typename Ptree::key_type(node->value(), node->value_size());
}
break;

// Comment nodes
case node_comment:
{
if (!(flags & no_comments))
pt.push_back(std::make_pair(xmlcomment<Ch>(),
Ptree(std::basic_string<Ch>(node->value(),
node->value_size()))));
pt.push_back(std::make_pair(xmlcomment<typename Ptree::key_type>(),
Ptree(typename Ptree::key_type(node->value(), node->value_size()))));
}
break;

Expand Down
75 changes: 39 additions & 36 deletions include/boost/property_tree/detail/xml_parser_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
namespace boost { namespace property_tree { namespace xml_parser
{

template<class Ch>
std::basic_string<Ch> condense(const std::basic_string<Ch> &s)
template<class Str>
Str condense(const Str &s)
{
std::basic_string<Ch> r;
typedef typename Str::value_type Ch;
Str r;
std::locale loc;
bool space = false;
typename std::basic_string<Ch>::const_iterator end = s.end();
for (typename std::basic_string<Ch>::const_iterator it = s.begin();
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin();
it != end; ++it)
{
if (isspace(*it, loc) || *it == Ch('\n'))
Expand All @@ -41,45 +42,47 @@ namespace boost { namespace property_tree { namespace xml_parser
return r;
}

template<class Ch>
std::basic_string<Ch> encode_char_entities(const std::basic_string<Ch> &s)

template<class Str>
Str encode_char_entities(const Str &s)
{
// Don't do anything for empty strings.
if(s.empty()) return s;

typedef typename std::basic_string<Ch> Str;
typedef typename Str::value_type Ch;

Str r;
// To properly round-trip spaces and not uglify the XML beyond
// recognition, we have to encode them IF the text contains only spaces.
Str sp(1, Ch(' '));
if(s.find_first_not_of(sp) == Str::npos) {
// The first will suffice.
r = detail::widen<Ch>("&#32;");
r = detail::widen<Str>("&#32;");
r += Str(s.size() - 1, Ch(' '));
} else {
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin(); it != end; ++it)
{
switch (*it)
{
case Ch('<'): r += detail::widen<Ch>("&lt;"); break;
case Ch('>'): r += detail::widen<Ch>("&gt;"); break;
case Ch('&'): r += detail::widen<Ch>("&amp;"); break;
case Ch('"'): r += detail::widen<Ch>("&quot;"); break;
case Ch('\''): r += detail::widen<Ch>("&apos;"); break;
case Ch('\t'): r += detail::widen<Ch>("&#9;"); break;
case Ch('\n'): r += detail::widen<Ch>("&#10;"); break;
case Ch('<'): r += detail::widen<Str>("&lt;"); break;
case Ch('>'): r += detail::widen<Str>("&gt;"); break;
case Ch('&'): r += detail::widen<Str>("&amp;"); break;
case Ch('"'): r += detail::widen<Str>("&quot;"); break;
case Ch('\''): r += detail::widen<Str>("&apos;"); break;
case Ch('\t'): r += detail::widen<Str>("&#9;"); break;
case Ch('\n'): r += detail::widen<Str>("&#10;"); break;
default: r += *it; break;
}
}
}
return r;
}

template<class Ch>
std::basic_string<Ch> decode_char_entities(const std::basic_string<Ch> &s)
template<class Str>
Str decode_char_entities(const Str &s)
{
typedef typename std::basic_string<Ch> Str;
typedef typename Str::value_type Ch;
Str r;
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin(); it != end; ++it)
Expand All @@ -90,11 +93,11 @@ namespace boost { namespace property_tree { namespace xml_parser
if (semicolon == end)
BOOST_PROPERTY_TREE_THROW(xml_parser_error("invalid character entity", "", 0));
Str ent(it + 1, semicolon);
if (ent == detail::widen<Ch>("lt")) r += Ch('<');
else if (ent == detail::widen<Ch>("gt")) r += Ch('>');
else if (ent == detail::widen<Ch>("amp")) r += Ch('&');
else if (ent == detail::widen<Ch>("quot")) r += Ch('"');
else if (ent == detail::widen<Ch>("apos")) r += Ch('\'');
if (ent == detail::widen<Str>("lt")) r += Ch('<');
else if (ent == detail::widen<Str>("gt")) r += Ch('>');
else if (ent == detail::widen<Str>("amp")) r += Ch('&');
else if (ent == detail::widen<Str>("quot")) r += Ch('"');
else if (ent == detail::widen<Str>("apos")) r += Ch('\'');
else
BOOST_PROPERTY_TREE_THROW(xml_parser_error("invalid character entity", "", 0));
it = semicolon;
Expand All @@ -105,31 +108,31 @@ namespace boost { namespace property_tree { namespace xml_parser
return r;
}

template<class Ch>
const std::basic_string<Ch> &xmldecl()
template<class Str>
const Str &xmldecl()
{
static std::basic_string<Ch> s = detail::widen<Ch>("<?xml>");
static Str s = detail::widen<Str>("<?xml>");
return s;
}

template<class Ch>
const std::basic_string<Ch> &xmlattr()
template<class Str>
const Str &xmlattr()
{
static std::basic_string<Ch> s = detail::widen<Ch>("<xmlattr>");
static Str s = detail::widen<Str>("<xmlattr>");
return s;
}

template<class Ch>
const std::basic_string<Ch> &xmlcomment()
template<class Str>
const Str &xmlcomment()
{
static std::basic_string<Ch> s = detail::widen<Ch>("<xmlcomment>");
static Str s = detail::widen<Str>("<xmlcomment>");
return s;
}

template<class Ch>
const std::basic_string<Ch> &xmltext()
template<class Str>
const Str &xmltext()
{
static std::basic_string<Ch> s = detail::widen<Ch>("<xmltext>");
static Str s = detail::widen<Str>("<xmltext>");
return s;
}

Expand Down
Loading