Removed last of the std::string-isms.

This commit is contained in:
Jez Higgins 2012-11-21 06:59:40 +00:00
parent bdc7db5da8
commit 51f1912534
28 changed files with 1182 additions and 1126 deletions

View file

@ -1,18 +1,14 @@
#ifdef _MSC_VER
#pragma warning(disable : 4250)
#pragma warning(disable : 4250 4244)
#endif
#include <iostream>
#include <string>
#include <sstream>
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <DOM/io/Stream.hpp>
#include <XSLT/XSLT.hpp>
Arabica::DOM::Document<std::wstring> buildDOM(const std::wstring& xml);
typedef Arabica::default_string_adaptor<std::wstring> adaptor;
Arabica::DOM::Document<std::string> buildDOM(const std::string & xml);
int main(int argc, const char* argv[])
{
@ -24,12 +20,12 @@ int main(int argc, const char* argv[])
return 0;
} // if ...
Arabica::XSLT::StylesheetCompiler<std::wstring> compiler;
std::wostringstream errors;
Arabica::XSLT::StylesheetCompiler<std::string> compiler;
std::ostringstream errors;
try
{
Arabica::SAX::InputSource<std::wstring> source(adaptor::construct_from_utf8(argv[2]));
std::auto_ptr<Arabica::XSLT::Stylesheet<std::wstring> > stylesheet = compiler.compile(source);
Arabica::SAX::InputSource<std::string> source(argv[2]);
std::auto_ptr<Arabica::XSLT::Stylesheet<std::string> > stylesheet = compiler.compile(source);
if(stylesheet.get() == 0)
{
std::cerr << "Couldn't compile stylesheet: " << compiler.error() << std::endl;
@ -38,41 +34,28 @@ int main(int argc, const char* argv[])
stylesheet->set_error_output(errors);
Arabica::DOM::Document<std::wstring> document = buildDOM(adaptor::construct_from_utf8(argv[1]));
Arabica::DOM::Document<std::string> document = buildDOM(argv[1]);
if(document == 0)
{
std::cerr << "Could not parse XML source" << std::endl;
return 0;
} // if ...
//document.normalize();
stylesheet->execute(document);
/*
std::cout << "\n==============" << std::endl;
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
stylesheet->execute(document);
Arabica::DOM::Node<std::wstring> node = output.node();
std::cout << node << std::endl;
*/
}
catch(const std::runtime_error& ex)
{
std::cerr << ex.what() << std::endl;
} // catch
std::wcerr << "\n\n" << errors.str() << std::endl;
std::cerr << "\n\n" << errors.str() << std::endl;
return 0;
} // main
Arabica::DOM::Document<std::wstring> buildDOM(const std::wstring& filename)
Arabica::DOM::Document<std::string> buildDOM(const std::string & filename)
{
Arabica::SAX::InputSource<std::wstring> is(filename);
Arabica::SAX2DOM::Parser<std::wstring> parser;
Arabica::SAX::InputSource<std::string> is(filename);
Arabica::SAX2DOM::Parser<std::string> parser;
parser.parse(is);
return parser.getDocument();

View file

@ -19,6 +19,7 @@ public:
typedef stringT string_type;
typedef typename string_type::const_iterator const_iterator;
typedef typename string_type::iterator mutable_iterator;
typedef typename string_type::const_reverse_iterator const_reverse_iterator;
typedef typename string_type::iterator iterator;
typedef typename string_type::value_type value_type;
typedef typename string_type::size_type size_type;
@ -42,6 +43,10 @@ public:
return string_type(from, to);
}
static inline string_type construct(const std::basic_string<value_type>& str)
{
return construct(str.begin(), str.end());
} // construct
static string_type construct(const value_type* str)
{
@ -62,6 +67,9 @@ public:
static string_type substr(const string_type& str, const size_type& offset) { return str.substr(offset); }
static string_type substr(const string_type& str, const size_type& offset, const size_type& count) { return str.substr(offset, count); }
static void append(string_type& str, const string_type& a) { str.append(a); }
static void append(string_type& str, const value_type& a) { str += a; }
static string_type concat(const string_type& str, const string_type& a) { return str + a; }
static string_type concat(const string_type& str, const value_type& a) { return str + a; }
static void insert(string_type& str, size_type offset, const string_type& a) { str.insert(offset, a); }
static void replace(string_type& str, size_type offset, size_type count, const string_type& a) { str.replace(offset, count, a); }
@ -71,6 +79,7 @@ public:
static iterator begin(string_type& str) { return str.begin(); }
static iterator end(string_type& str) { return str.end(); }
static const_reverse_iterator rbegin(const string_type& str) { return str.rbegin(); }
// only used to constuct error strings - don't have to be highly efficient!
static std::string asStdString(const string_type& str);

View file

@ -304,7 +304,7 @@ class NamespaceSupport
for(typename contextListT::const_reverse_iterator i = contexts_.rbegin(); i != contexts_.rend(); ++i)
{
for(typename stringMapT::const_iterator u = i->begin(); u != i->end(); ++u)
if(!u->first.empty())
if(!string_adaptor::empty(u->first))
prefixes.push_back(u->first);
} // for ...

View file

@ -63,7 +63,7 @@ public:
{
++depth_;
string_type base = atts.getValue(xbc_.xml_uri, xbc_.base);
if(base.empty())
if(string_adaptor::empty(base))
return;
string_type baseURI = absolutise(currentBase(), base);

View file

@ -107,7 +107,7 @@ public:
virtual void characters(const string_type& ch)
{
if(no_content_)
verifyNoCharacterData<string_type, string_adaptor>(ch, SC::include + SC::import);
verifyNoCharacterData<string_type, string_adaptor>(ch, SC::include); // + SC::import
context_->parentHandler().characters(ch);
} // characters

View file

@ -31,7 +31,7 @@ protected:
std::vector<InlineAttribute<string_type, string_adaptor> > inlineAtts;
for(int i = 0; i != atts.getLength(); ++i)
{
if(atts.getQName(i).find(SC::xmlns_colon) == 0)
if(string_adaptor::find(atts.getQName(i), SC::xmlns_colon) == 0)
continue;
if(atts.getURI(i) == StylesheetConstant<string_type, string_adaptor>::NamespaceURI)
continue;
@ -42,9 +42,9 @@ protected:
else
{
std::pair<string_type, string_type> remap = baseT::context().remappedNamespace(atts.getURI(i));
if(remap.first.empty() && !remap.second.empty())
if(string_adaptor::empty(remap.first) && !string_adaptor::empty(remap.second))
remap.first = baseT::context().autoNamespacePrefix();
string_type name = remap.first + SC::COLON + atts.getLocalName(i);
string_type name = makeName(remap.first, atts.getLocalName(i));
inlineAtts.push_back(InlineAttribute<string_type, string_adaptor>(name,
remap.second,
baseT::context().xpath_attribute_value_template(atts.getValue(i))));
@ -55,9 +55,18 @@ protected:
return new InlineElement<string_type, string_adaptor>(qName, namespaceURI, inlineAtts);
const std::pair<string_type, string_type>& remap = baseT::context().remappedNamespace(namespaceURI);
string_type name = remap.first + SC::COLON + localName;
string_type name = makeName(remap.first, localName);
return new InlineElement<string_type, string_adaptor>(name, remap.second, inlineAtts);
} // createContainer
private:
string_type makeName(const string_type prefix, const string_type localName) const
{
string_type n = prefix;
string_adaptor::append(n, SC::COLON);
string_adaptor::append(n, localName);
return n;
} // makeName
}; // class InlineElementHandler

View file

@ -71,7 +71,7 @@ public:
virtual void characters(const string_type& ch)
{
for(typename string_type::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
for(typename string_adaptor::const_iterator i = string_adaptor::begin(ch), e = string_adaptor::end(ch); i != e; ++i)
if(!Arabica::XML::is_space(*i))
{
container_->add_item(new Text<string_type, string_adaptor>(ch));

View file

@ -44,10 +44,10 @@ public:
std::map<string_type, string_type> namespaces = context_.inScopeNamespaces();
if((namespaces.find(stylesheet_prefix) == namespaces.end()) &&
(!stylesheet_prefix.empty()))
(!string_adaptor::empty(stylesheet_prefix)))
throw SAX::SAXException(string_adaptor::asStdString(SC::namespace_alias) + " " + string_adaptor::asStdString(stylesheet_prefix) + " is not a declared namespace prefix");
if((namespaces.find(result_prefix) == namespaces.end()) &&
(!result_prefix.empty()))
(!string_adaptor::empty(result_prefix)))
throw SAX::SAXException(string_adaptor::asStdString(SC::namespace_alias) + " " + string_adaptor::asStdString(result_prefix) + " is not a declared namespace prefix");
context_.addNamespaceAlias(namespaces[stylesheet_prefix], result_prefix, namespaces[result_prefix]);

View file

@ -66,17 +66,17 @@ private:
{
CDATAElements elements;
if(cdata_section_elements.empty())
if(string_adaptor::empty(cdata_section_elements))
return elements;
std::basic_istringstream<typename string_adaptor::value_type>
is(text::normalize_whitespace<string_type, string_adaptor>(cdata_section_elements));
string_type norm_cdata_sec_elements = text::normalize_whitespace<string_type, string_adaptor>(cdata_section_elements);
std::basic_istringstream<typename string_adaptor::value_type> is(string_adaptor::asStdString(norm_cdata_sec_elements));
while(!is.eof())
{
string_type e;
std::basic_string<typename string_adaptor::value_type> e;
is >> e;
XML::QualifiedName<string_type, string_adaptor> qualifiedName = context_.processElementQName(e);
XML::QualifiedName<string_type, string_adaptor> qualifiedName = context_.processElementQName(string_adaptor::construct(e));
elements.insert(QName<string_type, string_adaptor>::create(qualifiedName));
} // while

View file

@ -43,7 +43,7 @@ public:
order = context_.xpath_attribute_value_template(attr[SC::order]);
caseorder = context_.xpath_attribute_value_template(attr[SC::case_order]);
if(attr[SC::lang].length() != 0)
if(string_adaptor::length(attr[SC::lang]) != 0)
std::cerr << "Sorry! Don't support xsl:sort lang attribute yet" << std::endl;
sort_ = new Sort<string_type, string_adaptor>(select,

View file

@ -26,7 +26,7 @@ public:
{
if(!done_params_)
{
for(typename string_type::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
for(typename string_adaptor::const_iterator i = string_adaptor::begin(ch), e = string_adaptor::end(ch); i != e; ++i)
if(!Arabica::XML::is_space(*i))
{
done_params_ = true;

View file

@ -46,7 +46,7 @@ public:
virtual void characters(const string_type& ch)
{
buffer_ += ch;
string_adaptor::append(buffer_, ch);
} // characters
private:

View file

@ -144,7 +144,7 @@ public:
{
const string_type& name = r->first;
const AttributeValidator<string_type, string_adaptor>& av = r->second;
if((av.mandatory()) && (atts.getValue(name).empty()))
if((av.mandatory()) && (string_adaptor::empty(atts.getValue(name))))
throw SAX::SAXException(string_adaptor::asStdString(parentElement) + ": Attribute " + string_adaptor::asStdString(name) + " must be specified");
if(av.has_default())
results[name] = av.default_value();
@ -300,7 +300,7 @@ template<class string_type, class string_adaptor>
void verifyNoCharacterData(const string_type& ch,
const string_type& name)
{
for(typename string_type::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
for(typename string_adaptor::const_iterator i = string_adaptor::begin(ch), e = string_adaptor::end(ch); i != e; ++i)
if(!Arabica::XML::is_space(*i))
throw SAX::SAXException(string_adaptor::asStdString(name) + " element can not contain character data.");
} // verifyNoCharacterContent

View file

@ -63,7 +63,7 @@ protected:
{
if(has_select_)
{
for(typename string_type::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i)
for(typename string_adaptor::const_iterator i = string_adaptor::begin(ch), e = string_adaptor::end(ch); i != e; ++i)
if(!Arabica::XML::is_space(*i))
throw SAX::SAXException("A variable or param can not have both a select attribute and text context");
}

View file

@ -35,7 +35,7 @@ public:
ExecutionContext<string_type, string_adaptor>& context) const
{
string_type name = name_->evaluateAsString(node, context.xpathContext());
if(name.empty())
if(string_adaptor::empty(name))
throw SAX::SAXException("xsl:attribute name attribute must evaluate to a valid element name");
string_type namesp;
@ -45,7 +45,7 @@ public:
else
{
QName<string_type, string_adaptor> qn = QName<string_type, string_adaptor>::create(name);
if(!qn.prefix.empty())
if(!string_adaptor::empty(qn.prefix))
{
typename std::map<string_type, string_type>::const_iterator ns = namespaces_.find(qn.prefix);
if(ns == namespaces_.end())

View file

@ -171,7 +171,7 @@ public:
{
std::basic_ostringstream<typename string_adaptor::value_type> ss;
ss << SC::auto_ns << autoNs_++;
return ss.str();
return string_adaptor::construct(ss.str());
} // autoNamespacePrefix
void set_precedence(const Precedence& prec)
@ -204,7 +204,7 @@ private:
const string_type& name,
const std::vector<Arabica::XPath::XPathExpression<string_type> >& argExprs) const
{
if(!namespace_uri.empty())
if(!string_adaptor::empty(namespace_uri))
return new UndefinedFunction<string_type, string_adaptor>(namespace_uri, name, argExprs);
// document

View file

@ -236,7 +236,7 @@ protected:
std::basic_ostringstream<typename string_adaptor::value_type> os;
os << node.underlying_impl();
return os.str();
return string_adaptor::construct(os.str());
} // doEvaluate
}; // class GenerateIdFunction
@ -315,7 +315,7 @@ protected:
const QualifiedName expandedName = QualifiedName::parseQName(functionName, true, namespaces_);
if((expandedName.namespaceUri() != StylesheetConstant<string_type, string_adaptor>::NamespaceURI) &&
(!expandedName.namespaceUri().empty()))
(!string_adaptor::empty(expandedName.namespaceUri())))
return false;
static string_type XSLTNames[] = { SC::apply_imports,
@ -414,14 +414,14 @@ public:
{
typedef Arabica::text::Unicode<typename string_adaptor::value_type> UnicodeT;
if(!namespace_uri.empty())
if(!string_adaptor::empty(namespace_uri))
{
error_ += UnicodeT::LEFT_SQUARE_BRACKET;
error_ += namespace_uri;
error_ += UnicodeT::RIGHT_SQUARE_BRACKET;
string_adaptor::append(error_, UnicodeT::LEFT_SQUARE_BRACKET);
string_adaptor::append(error_, namespace_uri);
string_adaptor::append(error_, UnicodeT::RIGHT_SQUARE_BRACKET);
} // if ..
error_ += name;
string_adaptor::append(error_, name);
} // UndefinedFunction
protected:

View file

@ -42,7 +42,7 @@ public:
if(findPrefix(namespaceURI) != EMPTY_STRING)
return;
bool remap = (attr && given_prefix.empty()) || (given_prefix == SC::xmlns);
bool remap = (attr && string_adaptor::empty(given_prefix)) || (given_prefix == SC::xmlns);
string_type prefix = !remap ? given_prefix : autoNamespacePrefix();
@ -81,7 +81,7 @@ private:
{
std::basic_ostringstream<typename string_adaptor::value_type> ss;
ss << SC::auto_ns << autoNs_++;
return ss.str();
return string_adaptor::construct(ss.str());
} // autoNamespacePrefix
ScopeStack prefixStack_;

View file

@ -65,7 +65,7 @@ public:
flush_current();
namespaceStack_.pushScope();
if(!namespaceURI.empty())
if(!string_adaptor::empty(namespaceURI))
namespaceStack_.declareNamespace(prefix, namespaceURI);
string_type mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
@ -95,13 +95,21 @@ public:
if(!text_mode_)
{
string_type mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
do_end_element((!mapped_prefix.empty()) ? mapped_prefix + SC::COLON + localName : localName, namespaceURI);
do_end_element((!string_adaptor::empty(mapped_prefix)) ? makeName(mapped_prefix, localName) : localName, namespaceURI);
element_stack_.pop();
} // end_element
namespaceStack_.popScope();
} // end_element
string_type makeName(const string_type& prefix, const string_type& localName) const
{
string_type n = prefix;
string_adaptor::append(n, SC::COLON);
string_adaptor::append(n, localName);
return n;
} // makeName
void start_attribute(const string_type& qName, const string_type& namespaceURI)
{
QName<string_type, string_adaptor> qn = QName<string_type, string_adaptor>::create(qName, namespaceURI);
@ -119,11 +127,11 @@ public:
return;
} // if ...
if(!namespaceURI.empty())
if(!string_adaptor::empty(namespaceURI))
namespaceStack_.declareNamespace(prefix, namespaceURI, true);
string_type mapped_prefix = namespaceStack_.findPrefix(namespaceURI);
string_type qName = (!mapped_prefix.empty()) ? mapped_prefix + SC::COLON + localName : localName;
string_type qName = (!string_adaptor::empty(mapped_prefix)) ? makeName(mapped_prefix, localName) : localName;
atts_.addOrReplaceAttribute(namespaceURI,
localName,
@ -141,7 +149,6 @@ public:
if(pending_attribute_ == -1)
return;
atts_.setValue(pending_attribute_, buffer_.str());
pending_attribute_ = -1;
} // end_attribute
@ -173,7 +180,7 @@ public:
if(pending_attribute_ != -1)
{
atts_.setValue(pending_attribute_, atts_.getValue(pending_attribute_) + ch);
atts_.setValue(pending_attribute_, string_adaptor::concat(atts_.getValue(pending_attribute_), ch));
return;
} // if ...
@ -204,9 +211,9 @@ public:
if(!text_mode_)
{
string_type comment = escape(buffer_.str(), SC::double_hyphen, SC::escaped_double_hyphen);
if(comment.length() && *(comment.rbegin()) == SC::HYPHEN_MINUS)
comment += SC::SPACE;
string_type comment = escape(string_adaptor::construct(buffer_.str()), SC::double_hyphen, SC::escaped_double_hyphen);
if(string_adaptor::length(comment) && *(string_adaptor::rbegin(comment)) == SC::HYPHEN_MINUS)
string_adaptor::append(comment, SC::SPACE);
do_comment(comment);
} // if ...
} // end_comment
@ -228,7 +235,7 @@ public:
if(!text_mode_)
{
string_type data = escape(buffer_.str(), SC::PIEnd, SC::escaped_pi_end);
string_type data = escape(string_adaptor::construct(buffer_.str()), SC::PIEnd, SC::escaped_pi_end);
do_processing_instruction(target_, data);
} // if ...
} // end_processing_instruction
@ -260,11 +267,14 @@ protected:
private:
string_type escape(string_type str, const string_type& t, const string_type& r) const
{
typename string_type::size_type naughty = str.find(t);
while(naughty != string_type::npos)
typename string_adaptor::size_type naughty = string_adaptor::find(str, t);
while(naughty != string_adaptor::npos())
{
str.replace(naughty, t.length(), r, 0, r.length());
naughty = str.find(t, naughty);
string_type newstr = string_adaptor::substr(str, 0, naughty);
string_adaptor::append(newstr, r);
string_adaptor::append(newstr, string_adaptor::substr(str, naughty + string_adaptor::length(t)));
str = newstr;
naughty = string_adaptor::find(str, t, naughty);
} // while
return str;
} // escape
@ -277,7 +287,7 @@ private:
if(is_buf)
return true;
buffer_.str(string_adaptor::empty_string());
buffer_.str(std::basic_string<typename string_adaptor::value_type>());
return false;
} // push_buffering
@ -349,7 +359,7 @@ private:
if(n->first == SC::xml)
continue;
string_type qName = (n->first.empty()) ? SC::xmlns : SC::xmlns_colon + n->first;
string_type qName = (string_adaptor::empty(n->first)) ? SC::xmlns : string_adaptor::concat(SC::xmlns_colon, n->first);
atts_.addAttribute(SC::xmlns_uri,
n->first,
qName,

View file

@ -37,25 +37,29 @@ public:
private:
void validate_name(const string_type& name) const
{
if(name.empty())
if(string_adaptor::empty(name))
throw SAX::SAXException("xsl:processing-instruction : name attribute must evaluate to a valid name");
if(!Arabica::XML::is_ncname<string_adaptor>(name))
throw SAX::SAXException("xsl:processing-instruction : '" + string_adaptor::asStdString(name) + "' is not valid as the name");
if(name.length() != 3)
if(string_adaptor::length(name) != 3)
return;
typedef Arabica::text::Unicode<char> UnicodeT;
if((name[0] != UnicodeT::CAPITAL_X) &&
(name[0] != UnicodeT::LOWERCASE_X))
typename string_adaptor::const_iterator i = string_adaptor::begin(name);
if((*i != UnicodeT::CAPITAL_X) &&
(*i != UnicodeT::LOWERCASE_X))
return;
if((name[1] != UnicodeT::CAPITAL_M) &&
(name[1] != UnicodeT::LOWERCASE_M))
++i;
if((*i != UnicodeT::CAPITAL_M) &&
(*i != UnicodeT::LOWERCASE_M))
return;
if((name[2] != UnicodeT::CAPITAL_L) &&
(name[2] != UnicodeT::LOWERCASE_L))
++i;
if((*i != UnicodeT::CAPITAL_L) &&
(*i != UnicodeT::LOWERCASE_L))
return;
throw SAX::SAXException("xsl:processing-instruction name can not be 'xml'");

View file

@ -25,13 +25,19 @@ struct QName
prefix(p),
localName(lN),
namespaceURI(uri),
qname(p.empty() ? lN : (p + SC::COLON + lN))
qname()
{
if(!string_adaptor::empty(p))
{
string_adaptor::append(qname, p);
string_adaptor::append(qname, SC::COLON);
} // if ...
string_adaptor::append(qname, lN);
} // QName
static QName create(const XML::QualifiedName<string_type>& qName)
{
if(qName.prefix().length() && qName.namespaceUri().empty())
if(string_adaptor::length(qName.prefix()) && string_adaptor::empty(qName.namespaceUri()))
throw SAX::SAXException("Prefix " + string_adaptor::asStdString(qName.prefix()) + " is not declared.");
return QName(qName.prefix(), qName.localName(), qName.namespaceUri());
} // create
@ -49,14 +55,14 @@ struct QName
string_type prefix;
string_type localName;
size_t colon = qName.find(SC::COLON);
size_t colon = string_adaptor::find(qName, SC::COLON);
if(colon == string_type::npos)
if(colon == string_adaptor::npos())
localName = qName;
else
{
prefix = qName.substr(0, colon);
localName = qName.substr(colon+1);
prefix = string_adaptor::substr(qName, 0, colon);
localName = string_adaptor::substr(qName, colon+1);
}
return QName(prefix, localName, namespaceURI);
} // create

View file

@ -146,7 +146,7 @@ protected:
{
stream_ << ' ' << atts.getQName(a) << '=' << '\"';
string_type ch = atts.getValue(a);
std::for_each(ch.begin(), ch.end(), Arabica::XML::attribute_escaper<typename string_adaptor::value_type>(stream_));
std::for_each(string_adaptor::begin(ch), string_adaptor::end(ch), Arabica::XML::attribute_escaper<typename string_adaptor::value_type>(stream_));
stream_ << '\"';
}
empty_ = true;
@ -175,11 +175,11 @@ protected:
close_element_if_empty();
if(!disable_output_escaping_ && !in_cdata_)
std::for_each(ch.begin(), ch.end(), Arabica::XML::text_escaper<typename string_adaptor::value_type>(stream_));
std::for_each(string_adaptor::begin(ch), string_adaptor::end(ch), Arabica::XML::text_escaper<typename string_adaptor::value_type>(stream_));
else if(in_cdata_)
{
size_t breakAt = ch.find(SC::CDATAEnd);
if(breakAt == string_type::npos)
size_t breakAt = string_adaptor::find(ch, SC::CDATAEnd);
if(breakAt == string_adaptor::npos())
{
stream_ << ch;
return;
@ -188,14 +188,14 @@ protected:
do
{
breakAt += 2;
stream_ << ch.substr(start, breakAt);
stream_ << string_adaptor::substr(ch, start, breakAt);
do_end_CDATA();
start = breakAt;
do_start_CDATA();
breakAt = ch.find(SC::CDATAEnd, breakAt);
breakAt = string_adaptor::find(ch, SC::CDATAEnd, breakAt);
}
while(breakAt != string_type::npos);
stream_ << ch.substr(start);
while(breakAt != string_adaptor::npos());
stream_ << string_adaptor::substr(ch, start);
}
else
stream_ << ch;
@ -294,26 +294,26 @@ private:
{
string_type version = setting(SC::version);
if(version.empty())
if(string_adaptor::empty(version))
version = SC::Version;
stream_ << "<?xml version=\"" << version << "\"";
}
{
string_type s = setting(SC::standalone);
if(!s.empty())
if(!string_adaptor::empty(s))
stream_ << " standalone=\"" << s << "\"";
}
stream_ << "?>\n";
if(!qName.empty())
if(!string_adaptor::empty(qName))
{
string_type pub = setting(SC::doctype_public);
string_type sys = setting(SC::doctype_system);
if(!sys.empty())
if(!string_adaptor::empty(sys))
{
stream_ << "<!DOCTYPE " << qName << "\n";
if(!pub.empty())
if(!string_adaptor::empty(pub))
stream_ << " PUBLIC \"" << pub << "\" \"" << sys << "\">\n";
else
stream_ << " SYSTEM \"" << sys << "\">\n";
@ -382,7 +382,7 @@ protected:
if(lc == 0 || lc.getNodeType() != DOM::Node_base::TEXT_NODE)
current().appendChild(document().createTextNode(ch));
else
lc.setNodeValue(lc.getNodeValue() + ch);
lc.setNodeValue(string_adaptor::concat(lc.getNodeValue(), ch));
} // do_characters
void do_start_CDATA()
@ -462,9 +462,10 @@ private:
string_type sps;
if(indent_ != 0)
{
sps += '\n';
std::fill_n(std::back_inserter<string_type>(sps), indent_, ' ');
do_characters(sps);
std::basic_string<typename string_adaptor::value_type> sps;
sps += SC::CARRIAGE_RETURN;
std::fill_n(std::back_inserter<std::basic_string<typename string_adaptor::value_type> >(sps), indent_, SC::SPACE);
do_characters(string_adaptor::construct(sps));
} // if ...
indent_ += 2;

View file

@ -63,7 +63,7 @@ public:
if(namespaceURI == SC::NamespaceURI)
startXSLTElement(namespaceURI, localName, qName, atts);
else if(!namespaceURI.empty())
else if(!string_adaptor::empty(namespaceURI))
startForeignElement(namespaceURI, localName, qName, atts);
else
oops(qName);
@ -103,7 +103,7 @@ private:
std::map<string_type, string_type> attributes = rules.gather(qName, atts);
if(attributes[SC::version] != SC::Version)
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");
if(!attributes[SC::extension_element_prefixes].empty())
if(!string_adaptor::empty(attributes[SC::extension_element_prefixes]))
throw SAX::SAXException("Haven't implemented extension-element-prefixes yet");
} // startStylesheet
@ -121,7 +121,7 @@ private:
break;
}
if(version.empty())
if(string_adaptor::empty(version))
throw SAX::SAXException("The source file does not look like a stylesheet.");
if(version != SC::Version)
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");

View file

@ -40,7 +40,7 @@ public:
mode_(mode),
precedence_(precedence)
{
if(!priority.empty())
if(!string_adaptor::empty(priority))
{
double p = boost::lexical_cast<double>(Arabica::text::normalize_whitespace<string_type, string_adaptor>(priority));
for(typename MatchExprList::iterator m = matches_.begin(), me = matches_.end(); m != me; ++m)
@ -58,7 +58,7 @@ public:
} // execute
const MatchExprList& compiled_matches() const { return matches_; }
bool has_name() const { return !name_.empty(); }
bool has_name() const { return !string_adaptor::empty(name_); }
const string_type& name() const { return name_; }
const string_type& mode() const { return mode_; }
const Precedence& precedence() const { return precedence_; }

View file

@ -159,7 +159,7 @@ public:
{
typedef Arabica::text::Unicode<typename string_adaptor::value_type> UnicodeT;
string_type clarkName = namespace_uri.empty() ? name : make_clark_name(namespace_uri, name);
string_type clarkName = string_adaptor::empty(namespace_uri) ? name : make_clark_name(namespace_uri, name);
if(std::find(resolutionStack_.begin(), resolutionStack_.end(), clarkName) != resolutionStack_.end())
throw std::runtime_error("Circular dependency: " + string_adaptor::asStdString(clarkName) + " refers to itself directly or indirectly.");

View file

@ -33,6 +33,11 @@ bool operator<(const silly_string& lhs, const silly_string& rhs)
return lhs.s_ < rhs.s_;
} // operator<
bool operator>(const silly_string& lhs, const silly_string& rhs)
{
return lhs.s_ > rhs.s_;
} // operator<
////////////////////////////////////////
////////////////////////////////////////
char silly_string_adaptor::convert_from_utf8(char c)
@ -125,6 +130,22 @@ void silly_string_adaptor::append(silly_string& str, const silly_string& a)
str.s_.append(a.s_);
} // append
void silly_string_adaptor::append(silly_string& str, const char& a)
{
str.s_ += a;
} // append
silly_string silly_string_adaptor::concat(const silly_string& str, const silly_string& a)
{
return construct(str.s_ + a.s_);
}
silly_string silly_string_adaptor::concat(const silly_string& str, const char& a)
{
return construct(str.s_ + a);
}
void silly_string_adaptor::insert(silly_string& str, size_type offset, const silly_string& a)
{
str.s_.insert(offset, a.s_);

View file

@ -26,9 +26,12 @@ private:
friend class silly_string_adaptor;
friend bool operator<(const silly_string& lhs,
const silly_string& rhs);
friend bool operator>(const silly_string& lhs,
const silly_string& rhs);
}; // class silly_string
bool operator<(const silly_string& lhs, const silly_string& rhs);
bool operator>(const silly_string& lhs, const silly_string& rhs);
class silly_string_adaptor : public Arabica::string_adaptor_tag
{
@ -36,6 +39,7 @@ public:
typedef silly_string string_type;
typedef std::string::const_iterator const_iterator;
typedef std::string::iterator mutable_iterator;
typedef std::string::const_reverse_iterator const_reverse_iterator;
typedef char value_type;
typedef std::string::size_type size_type;
static size_type npos()
@ -60,6 +64,11 @@ public:
return ss;
} // construct
static silly_string construct(const std::basic_string<value_type>& str)
{
return construct(str.c_str());
} // construct
static char convert_from_utf8(char c);
static silly_string construct_from_utf8(const char* str);
static silly_string construct_from_utf8(const char* str, int length);
@ -78,12 +87,16 @@ public:
static silly_string substr(const silly_string& str, const size_type& offset, const size_type& count);
static size_type length(const silly_string& str);
static void append(silly_string& str, const silly_string& a);
static void append(silly_string& str, const char& a);
static silly_string concat(const silly_string& str, const silly_string& a);
static silly_string concat(const silly_string& str, const char& a);
static void insert(silly_string& str, size_type offset, const silly_string& a);
static void replace(silly_string& str, size_type offset, size_type count, const silly_string& a);
static const_iterator begin(const silly_string& str) { return str.s_.begin(); }
static mutable_iterator begin(silly_string& str) { return str.s_.begin(); }
static const_iterator end(const silly_string& str) { return str.s_.end(); }
static mutable_iterator end(silly_string& str) { return str.s_.end(); }
static const_reverse_iterator rbegin(const silly_string& str) { return str.s_.rbegin(); }
// mainly used to constuct error strings - don't have to be highly efficient!
static std::string asStdString(const silly_string& str);

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -40,10 +40,10 @@
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\..\bin\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug_test_xslt\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug_test_xslt_wide\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\..\bin\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release_test_xslt\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release_test_xslt_wide\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">xslt_test_wide</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">xslt_test_wide</TargetName>