fixed end of string check in string parser added method to string parser to parse on character of a set of characters fixed end of string check in size, position and format
Stefan Schuermans

Stefan Schuermans commited on 2011-12-11 19:43:36
Showing 5 changed files, with 30 additions and 4 deletions.

... ...
@@ -36,7 +36,8 @@ bool Format::fromStr(const std::string &str)
36 36
       !parser.fixChr('-') ||
37 37
       !parser.uintMin(1, channels) ||
38 38
       !parser.fixChr('/') ||
39
-      !parser.uintMin(2, maxval1))
39
+      !parser.uintMin(2, maxval1) ||
40
+      !parser.isDone())
40 41
     return false;
41 42
   m_width = width;
42 43
   m_height = height;
... ...
@@ -30,7 +30,8 @@ bool Position::fromStr(const std::string &str)
30 30
 
31 31
   if (!parser.uintNo(x) ||
32 32
       !parser.fixChr(',') ||
33
-      !parser.uintNo(y))
33
+      !parser.uintNo(y) ||
34
+      !parser.isDone())
34 35
     return false;
35 36
   m_x = x;
36 37
   m_y = y;
... ...
@@ -30,7 +30,8 @@ bool Size::fromStr(const std::string &str)
30 30
 
31 31
   if (!parser.uintMin(1, width) ||
32 32
       !parser.fixChr('x') ||
33
-      !parser.uintMin(1, height))
33
+      !parser.uintMin(1, height) ||
34
+      !parser.isDone())
34 35
     return false;
35 36
   m_width = width;
36 37
   m_height = height;
... ...
@@ -15,7 +15,7 @@ namespace Blinker {
15 15
  */
16 16
 StringParser::StringParser(const std::string &str):
17 17
   m_str(str),
18
-  m_it(str.begin())
18
+  m_it(m_str.begin())
19 19
 {
20 20
 }
21 21
 
... ...
@@ -32,6 +32,21 @@ bool StringParser::fixChr(char chr)
32 32
   return true;
33 33
 }
34 34
 
35
+/**
36
+ * @brief parse one character ot of a set
37
+ * @param[in] set set of characters allowed
38
+ * @param[out] chr character parsed
39
+ * @return if a character from the set was found and processed
40
+ */
41
+bool StringParser::oneChrOf(const std::string &set, char &chr)
42
+{
43
+  if (m_it == m_str.end() || set.find(*m_it) == std::string::npos)
44
+    return false;
45
+  chr = *m_it;
46
+  ++m_it;
47
+  return true;
48
+}
49
+
35 50
 /**
36 51
  * @brief parse unsigned number
37 52
  * @param[out] uint number parsed from string
... ...
@@ -28,6 +28,14 @@ public:
28 28
    */
29 29
   bool fixChr(char chr);
30 30
 
31
+  /**
32
+   * @brief parse one character ot of a set
33
+   * @param[in] set set of characters allowed
34
+   * @param[out] chr character parsed
35
+   * @return if a character from the set was found and processed
36
+   */
37
+  bool oneChrOf(const std::string &set, char &chr);
38
+
31 39
   /**
32 40
    * @brief parse unsigned number
33 41
    * @param[out] uint number parsed from string
34 42