2013-07-03 02:52:38 +00:00
|
|
|
/* Copyright (c) 2008-2013, Avian Contributors
|
2010-09-20 23:31:23 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2013-02-21 23:18:20 +00:00
|
|
|
#ifndef AVIAN_UTIL_STRING_H
|
|
|
|
#define AVIAN_UTIL_STRING_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace avian {
|
|
|
|
namespace util {
|
|
|
|
|
|
|
|
class String {
|
|
|
|
public:
|
|
|
|
const char* text;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
String(const char* text):
|
|
|
|
text(text),
|
|
|
|
length(strlen(text)) {}
|
|
|
|
|
|
|
|
inline String(const char* text, size_t length):
|
|
|
|
text(text),
|
|
|
|
length(length) {}
|
|
|
|
};
|
2010-09-20 23:31:23 +00:00
|
|
|
|
|
|
|
class Tokenizer {
|
|
|
|
public:
|
|
|
|
|
2011-02-21 23:05:28 +00:00
|
|
|
Tokenizer(const char* s, char delimiter):
|
|
|
|
s(s), limit(0), delimiter(delimiter)
|
|
|
|
{ }
|
|
|
|
|
2013-02-21 23:18:20 +00:00
|
|
|
Tokenizer(String str, char delimiter):
|
|
|
|
s(str.text), limit(str.text + str.length), delimiter(delimiter)
|
2011-02-21 23:05:28 +00:00
|
|
|
{ }
|
2010-09-20 23:31:23 +00:00
|
|
|
|
|
|
|
bool hasMore() {
|
2012-09-12 21:25:17 +00:00
|
|
|
while (s != limit and *s == delimiter) ++s;
|
|
|
|
return s != limit and *s != 0;
|
2010-09-20 23:31:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 23:18:20 +00:00
|
|
|
String next() {
|
2010-09-20 23:31:23 +00:00
|
|
|
const char* p = s;
|
2012-09-12 21:25:17 +00:00
|
|
|
while (s != limit and *s and *s != delimiter) ++s;
|
2013-02-21 23:18:20 +00:00
|
|
|
return String(p, s - p);
|
2010-09-20 23:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* s;
|
2011-02-21 23:05:28 +00:00
|
|
|
const char* limit;
|
2010-09-20 23:31:23 +00:00
|
|
|
char delimiter;
|
|
|
|
};
|
|
|
|
|
2013-02-21 23:18:20 +00:00
|
|
|
} // namespace util
|
|
|
|
} // namespace avain
|
2010-09-20 23:31:23 +00:00
|
|
|
|
2013-02-21 23:18:20 +00:00
|
|
|
#endif//AVIAN_UTIL_STRING_H
|