PSCF v1.1
XmlEndTag.cpp
1/*
2* Util Package - C++ Utilities for Scientific Computation
3*
4* Copyright 2010 - 2017, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "XmlEndTag.h"
9#include <util/misc/ioUtil.h>
10
11namespace Util
12{
13
15 {}
16
18 {}
19
20 bool XmlEndTag::match(const std::string& line, int begin)
21 {
22 label_ = "";
23 setString(line, begin);
24
25 // Skip leading white space
26 if (isEnd()) return false;
27 skip();
28 if (isEnd()) return false;
29
30 // Read opening bracket
31 if (c() != '<') {
32 //std::cout << "Missing opening bracket" << std::endl;
33 return false;
34 }
35 next();
36 if (isEnd()) return false;
37 if (c() != '/') {
38 //std::cout << "Missing slash" << std::endl;
39 return false;
40 }
41
42 // Read label
43 int beginLabel, endLabel;
44 next();
45 skip();
46 if (isEnd()) return false;
47 beginLabel = cursor();
48 while (c() != '>' && c() != ' ') {
49 next();
50 if (isEnd()) return false;
51 }
52 endLabel = cursor();
53 label_ = string().substr(beginLabel, endLabel - beginLabel);
54
55 skip();
56 if (isEnd()) return false;
57 if (c() == '>') {
58 return true;
59 } else {
60 return false;
61 }
62
63 }
64
65 void XmlEndTag::match(const std::string expected,
66 const std::string& line, int begin)
67 {
68 if (!match(line, begin)) {
69 Log::file() << "line = " << line << std::endl;
70 UTIL_THROW("No end tag");
71 }
72 if (label() != expected) {
73 Log::file() << "line = " << line << std::endl;
74 Log::file() << "expected = " << expected << std::endl;
75 Log::file() << "label = " << label() << std::endl;
76 UTIL_THROW("Incorrect end tag label");
77 }
78 }
79
80}
static std::ostream & file()
Get log ostream by reference.
Definition: Log.cpp:57
void skip()
Skip leading white space, if any.
Definition: XmlBase.h:88
const std::string & string() const
Return the associated string.
Definition: XmlBase.h:118
void next()
Advance to the next character.
Definition: XmlBase.h:104
int cursor() const
Return the index of the current character.
Definition: XmlBase.h:124
void setString(const std::string &string, int cursor=0)
Initialize string and cursor.
Definition: XmlBase.cpp:32
int c() const
Return the current character.
Definition: XmlBase.h:130
bool isEnd() const
Has the cursor reached the end of the string?
Definition: XmlBase.h:136
~XmlEndTag()
Destructor.
Definition: XmlEndTag.cpp:17
const std::string label()
Label string.
Definition: XmlEndTag.h:64
XmlEndTag()
Constructor.
Definition: XmlEndTag.cpp:14
bool match(const std::string &string, int begin)
Attempt to match any end tag.
Definition: XmlEndTag.cpp:20
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1