QName.h
1 /*
2  * Copyright (C) 2012 Marc Boris Duerner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef Pt_Xml_QName_h
30 #define Pt_Xml_QName_h
31 
32 #include <Pt/Xml/Api.h>
33 #include <Pt/String.h>
34 #include <cstddef>
35 
36 namespace Pt {
37 
38 namespace Xml {
39 
46 class QName
47 {
48  public:
52  {}
53 
56  void clear()
57  {
58  _name.clear();
59  _prefix.clear();
60  }
61 
64  bool empty() const
65  {
66  return _prefix.empty() && _name.empty();
67  }
68 
71  inline std::size_t size() const
72  {
73  return _prefix.size() + _name.size();
74  }
75 
79  { return _prefix; }
80 
83  const String& prefix() const
84  { return _prefix; }
85 
88  void setPrefix(const String& prefix)
89  { _prefix = prefix; }
90 
93  String& name()
94  { return _name; }
95 
98  const String& name() const
99  { return _name; }
100 
104  { return _name; }
105 
108  const String& local() const
109  { return _name; }
110 
113  void setLocal(const String& name)
114  { _name = name; }
115 
116  private:
117  String _prefix;
118  String _name;
119 };
120 
125 inline bool operator ==(const QName& a, const QName& b)
126 {
127  return a.prefix() == b.prefix() && a.name() == b.name();
128 }
129 
134 inline bool operator !=(const QName& a, const QName& b)
135 {
136  return a.prefix() != b.prefix() || a.name() != b.name();
137 }
138 
143 inline bool operator<(const QName& a, const QName& b)
144 {
145  return a.prefix() < b.prefix() ||
146  ( ! (b.prefix() < a.prefix()) && a.name() < b.name() );
147 }
148 
149 } // namespace Xml
150 
151 } // namespace Pt
152 
153 #endif // Pt_Xml_QName_h
size_type size() const
Returns the length of the string.
Definition: String.h:239
bool operator<(const QName &a, const QName &b)
Returns true if less.
Definition: QName.h:143
const String & local() const
Returns the local name.
Definition: QName.h:108
A qualified XML name.
Definition: QName.h:46
String & prefix()
Returns the namespace prefix.
Definition: QName.h:78
bool empty() const
Returns true if empty.
Definition: QName.h:64
void clear()
Clears the string.
Definition: String.h:367
void setLocal(const String &name)
Sets the local name.
Definition: QName.h:113
QName()
Constructs an empty qualified name.
Definition: QName.h:51
bool empty() const
Returns true if empty.
Definition: String.h:244
const String & prefix() const
Returns the namespace prefix.
Definition: QName.h:83
std::size_t size() const
Returns the size of the prefix and local part.
Definition: QName.h:71
Unicode capable basic_string.
Definition: String.h:42
void setPrefix(const String &prefix)
Sets the namespace prefix.
Definition: QName.h:88
void clear()
Clears all content.
Definition: QName.h:56
String & local()
Returns the local name.
Definition: QName.h:103