summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-17 16:41:07 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-17 16:41:07 -0400
commitbbcb49fed27ea7d2052724fbee79f42c9bc744bc (patch)
tree094e1b10bcac1ba2d2c5ac7103b9b9ffe150ff79 /util.h
parent019a42f199494c86b0aeea59caf9421d96a2c009 (diff)
downloadfork-ledger-bbcb49fed27ea7d2052724fbee79f42c9bc744bc.tar.gz
fork-ledger-bbcb49fed27ea7d2052724fbee79f42c9bc744bc.tar.bz2
fork-ledger-bbcb49fed27ea7d2052724fbee79f42c9bc744bc.zip
fixes
Diffstat (limited to 'util.h')
-rw-r--r--util.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/util.h b/util.h
new file mode 100644
index 00000000..f021e437
--- /dev/null
+++ b/util.h
@@ -0,0 +1,38 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
+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() && (cond)) { \
+ str.get(var); \
+ if (str.eof()) \
+ break; \
+ if (var == '\\') { \
+ str.get(var); \
+ if (in.eof()) \
+ break; \
+ } \
+ *_p++ = var; \
+ var = str.peek(); \
+ } \
+ assert(_p < targ + ((size) - 1)); \
+ *_p = '\0'; \
+}
+
+#endif // _UTIL_H