summaryrefslogtreecommitdiff
path: root/parser.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-27 10:08:42 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:31 -0400
commit0eb597a681115d6d5dd2ea4511fa3b8c7b3d9c9f (patch)
tree750d64f6817282a6f4744058f73164a2996f6b03 /parser.h
parentd01629148383261d7944e91fd2ac67b334a6834d (diff)
downloadfork-ledger-0eb597a681115d6d5dd2ea4511fa3b8c7b3d9c9f.tar.gz
fork-ledger-0eb597a681115d6d5dd2ea4511fa3b8c7b3d9c9f.tar.bz2
fork-ledger-0eb597a681115d6d5dd2ea4511fa3b8c7b3d9c9f.zip
Restructured the code to use the new utility code in utils.h.
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h60
1 files changed, 59 insertions, 1 deletions
diff --git a/parser.h b/parser.h
index 689846da..2bdc4622 100644
--- a/parser.h
+++ b/parser.h
@@ -21,7 +21,65 @@ class parser_t
const string * original_file = NULL) = 0;
};
-DEFINE_EXCEPTION(parse_exception)
+DECLARE_EXCEPTION(parse_exception);
+
+/************************************************************************
+ *
+ * General utility parsing functions
+ */
+
+inline char * skip_ws(char * ptr) {
+ while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n')
+ ptr++;
+ return ptr;
+}
+
+inline char peek_next_nonws(std::istream& in) {
+ char c = in.peek();
+ while (! in.eof() && std::isspace(c)) {
+ in.get(c);
+ c = in.peek();
+ }
+ return c;
+}
+
+#define READ_INTO(str, targ, size, var, cond) { \
+ char * _p = targ; \
+ var = str.peek(); \
+ while (! str.eof() && var != '\n' && (cond) && _p - targ < size) { \
+ str.get(var); \
+ if (str.eof()) \
+ break; \
+ if (var == '\\') { \
+ str.get(var); \
+ if (in.eof()) \
+ break; \
+ } \
+ *_p++ = var; \
+ var = str.peek(); \
+ } \
+ *_p = '\0'; \
+}
+
+#define READ_INTO_(str, targ, size, var, idx, cond) { \
+ char * _p = targ; \
+ var = str.peek(); \
+ while (! str.eof() && var != '\n' && (cond) && _p - targ < size) { \
+ str.get(var); \
+ if (str.eof()) \
+ break; \
+ idx++; \
+ if (var == '\\') { \
+ str.get(var); \
+ if (in.eof()) \
+ break; \
+ idx++; \
+ } \
+ *_p++ = var; \
+ var = str.peek(); \
+ } \
+ *_p = '\0'; \
+}
} // namespace ledger