1 |
// Iffy |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#ifndef _Tag_hpp_ |
8 |
#define _Tag_hpp_ |
9 |
|
10 |
#include "Iffy.hpp" |
11 |
|
12 |
enum TagType { OPEN, CLOSE, STANDALONE }; |
13 |
|
14 |
class Tag |
15 |
{ |
16 |
private: |
17 |
TagType type; |
18 |
ext::String name; |
19 |
ios::String attributes; |
20 |
ext::String lower(const ext::String& string); |
21 |
public: |
22 |
Tag() : type(STANDALONE) {} |
23 |
Tag(const ext::String& segment); |
24 |
Tag(TagType type, const ext::String& name) : type(type), name(name) {} |
25 |
Tag& operator=(TagType type) { this->type = type; return *this; } |
26 |
Tag& operator=(const ext::String& name) { this->name = name; return *this; } |
27 |
bool operator==(TagType type) const { return this->type == type; } |
28 |
bool operator==(const ext::String& name) const { return this->name == name; } |
29 |
bool operator!=(TagType type) const { return this->type != type; } |
30 |
bool operator!=(const ext::String& name) const { return this->name != name; } |
31 |
operator TagType() const { return type; } |
32 |
operator ext::String() const { return name; } |
33 |
// friends: |
34 |
friend ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Tag& tag); |
35 |
}; |
36 |
|
37 |
inline ios::PrintWriter& operator<<(ios::PrintWriter& pout, const Tag& tag) |
38 |
{ |
39 |
pout << (tag == CLOSE ? "</" : "<") << tag.name; |
40 |
|
41 |
if (tag != CLOSE) pout << tag.attributes; |
42 |
|
43 |
return pout << (tag == STANDALONE ? "/>" : ">"); |
44 |
} |
45 |
|
46 |
#endif // _Tag_hpp_ |