arabica/include/XML/strings.hpp

78 lines
2.3 KiB
C++
Raw Permalink Normal View History

#ifndef ARABICA_XML_STRINGS_HPP
#define ARABICA_XML_STRINGS_HPP
#include <XML/XMLCharacterClasses.hpp>
#include <text/UnicodeCharacters.hpp>
2008-08-01 14:02:41 +02:00
// QName
//[7] QName ::= PrefixedName | UnprefixedName
//[8] PrefixedName ::= Prefix ':' LocalPart
//[9] UnprefixedName ::= LocalPart
//[10] Prefix ::= NCName
//[11] LocalPart ::= NCName
// NCName
// [4] NCName ::= NCNameStartChar NCNameChar* //An XML Name, minus the ":"
// [5] NCNameChar ::= NameChar - ':'
// [6] NCNameStartChar ::= Letter | '_' } // namespace XML
namespace Arabica
{
namespace XML
{
template<typename string_adaptor>
inline bool is_ncname(const typename string_adaptor::const_iterator& b,
const typename string_adaptor::const_iterator& e)
{
using namespace Arabica::text;
typedef typename string_adaptor::const_iterator const_iterator;
typedef typename string_adaptor::value_type value_type;
2008-08-01 14:02:41 +02:00
if(b == e)
return false; // zero length
const_iterator s = b;
if(!(is_letter(*s) || (*s == Unicode<value_type>::LOW_LINE)))
return false;
++s;
2008-08-01 14:02:41 +02:00
for( ; s != e; ++s)
{
value_type c = *s;
2008-08-01 14:02:41 +02:00
if(!is_ncname_char(c))
return false;
}
return true;
} // is_ncname
template<typename string_adaptor>
inline bool is_ncname(const typename string_adaptor::string_type& str)
{
return is_ncname<string_adaptor>(string_adaptor::begin(str),
string_adaptor::end(str));
} // is_ncname
template<typename string_adaptor>
inline bool is_qname(const typename string_adaptor::string_type& str)
2008-08-01 14:02:41 +02:00
{
using namespace Arabica::text;
typedef typename string_adaptor::const_iterator const_iterator;
typedef typename string_adaptor::value_type value_type;
2008-08-01 14:02:41 +02:00
size_t colon_index = string_adaptor::find(str, Unicode<value_type>::COLON);
2008-08-01 14:02:41 +02:00
if(colon_index == string_adaptor::npos())
return is_ncname<string_adaptor>(str);
2008-08-01 14:02:41 +02:00
const_iterator b = string_adaptor::begin(str);
const_iterator e = string_adaptor::end(str);
return is_ncname<string_adaptor>(b, b+colon_index) &&
is_ncname<string_adaptor>(b+(colon_index+1), e);
2008-08-01 14:02:41 +02:00
} // is_qname
} // namespace XML
} // namespace Arabica
#endif