ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Iffy/Tag.cpp
Revision: 289
Committed: 2004-12-09T23:02:06-08:00 (20 years, 6 months ago) by douglas
File size: 1656 byte(s)
Log Message:
Die!

File Contents

# User Rev Content
1 Douglas Thrift 276 // Iffy
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "Tag.hpp"
8     #include "Matcher.hpp"
9    
10     #include <cctype>
11    
12 Douglas Thrift 280 Tag::Tag(const ext::String& segment) : type(OPEN)
13 Douglas Thrift 276 {
14     ext::Vector<ext::String> parts(segment.Split(' '));
15    
16 Douglas Thrift 280 _mforeach (ext::Vector<ext::String>, part, parts)
17 Douglas Thrift 276 {
18 douglas 289 if (part->IsEmpty()) continue;
19    
20 Douglas Thrift 280 if (part == parts.End() - 1 && part->Last() == '/')
21     {
22     type = STANDALONE;
23     *part = part->Substring(0, part->GetSize() - 1);
24     }
25    
26 Douglas Thrift 276 if (part == parts.Begin())
27     {
28     if (part->First() != '/')
29     {
30     name = lower(*part);
31     }
32     else
33     {
34     type = CLOSE;
35     name = lower(part->Substring(1));
36     }
37     }
38 Douglas Thrift 280
39     if (part != parts.Begin())
40 Douglas Thrift 276 {
41     Matcher matcher;
42     ext::String name;
43     ios::String value;
44    
45     if (*part == matcher("^(.*)=\"(.*)\"$"))
46     {
47     name = matcher[1];
48     value = matcher[2];
49     }
50     else if (*part == matcher("^(.*)=\"(.*)$"))
51     {
52     name = matcher[1];
53     value = matcher[2];
54    
55     while (++part != parts.End())
56     {
57 Douglas Thrift 280 if (part == parts.End() - 1 && *part == matcher("^(.*)\"/$"))
58 Douglas Thrift 276 {
59 Douglas Thrift 280 type = STANDALONE;
60    
61 Douglas Thrift 276 value << " " << matcher[1];
62    
63     break;
64     }
65 Douglas Thrift 280 else if (*part == matcher("^(.*)\"$"))
66     {
67     value << " " << matcher[1];
68    
69     break;
70     }
71 Douglas Thrift 276 else value << " " << *part;
72     }
73    
74     if (part == parts.End()) --part;
75     }
76     else if (*part == matcher("^(.*)=(.*)$"))
77     {
78     name = matcher[1];
79     value = matcher[2];
80     }
81    
82 Douglas Thrift 280 if (!name.IsEmpty()) attributes << " " << lower(name) << "=\"" << value << "\"";
83 Douglas Thrift 276 }
84     }
85     }
86    
87     ext::String Tag::lower(const ext::String& string)
88     {
89     ext::String lower;
90    
91     _foreach (ext::String, atom, string) lower.InsertLast(std::tolower(*atom));
92    
93     return lower;
94     }

Properties

Name Value
svn:eol-style native
svn:keywords Id