2007-12-22 23:21:26 +01:00
|
|
|
#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
|
|
|
|
|
2007-12-22 23:21:26 +01:00
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XML
|
|
|
|
{
|
2009-02-23 20:23:12 +01:00
|
|
|
template<typename string_adaptor>
|
|
|
|
inline bool is_ncname(const typename string_adaptor::const_iterator& b,
|
|
|
|
const typename string_adaptor::const_iterator& e)
|
2007-12-22 23:21:26 +01:00
|
|
|
{
|
|
|
|
using namespace Arabica::text;
|
2009-02-23 20:23:12 +01:00
|
|
|
typedef typename string_adaptor::const_iterator const_iterator;
|
|
|
|
typedef typename string_adaptor::value_type value_type;
|
2007-12-22 23:21:26 +01:00
|
|
|
|
2008-08-01 14:02:41 +02:00
|
|
|
if(b == e)
|
|
|
|
return false; // zero length
|
|
|
|
|
2009-02-23 20:23:12 +01:00
|
|
|
const_iterator s = b;
|
|
|
|
if(!(is_letter(*s) || (*s == Unicode<value_type>::LOW_LINE)))
|
2007-12-22 23:21:26 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
++s;
|
2008-08-01 14:02:41 +02:00
|
|
|
for( ; s != e; ++s)
|
2007-12-22 23:21:26 +01:00
|
|
|
{
|
2009-02-23 20:23:12 +01:00
|
|
|
value_type c = *s;
|
2008-08-01 14:02:41 +02:00
|
|
|
if(!is_ncname_char(c))
|
2007-12-22 23:21:26 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} // is_ncname
|
|
|
|
|
2009-02-23 20:23:12 +01:00
|
|
|
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;
|
2009-02-23 20:23:12 +01:00
|
|
|
typedef typename string_adaptor::const_iterator const_iterator;
|
|
|
|
typedef typename string_adaptor::value_type value_type;
|
2008-08-01 14:02:41 +02:00
|
|
|
|
2009-02-23 20:23:12 +01:00
|
|
|
size_t colon_index = string_adaptor::find(str, Unicode<value_type>::COLON);
|
2008-08-01 14:02:41 +02:00
|
|
|
|
2009-02-23 20:23:12 +01:00
|
|
|
if(colon_index == string_adaptor::npos())
|
|
|
|
return is_ncname<string_adaptor>(str);
|
2008-08-01 14:02:41 +02:00
|
|
|
|
2009-02-23 20:23:12 +01: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
|
|
|
|
|
2007-12-22 23:21:26 +01:00
|
|
|
} // namespace XML
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|