aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PropSet.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/PropSet.cxx')
-rw-r--r--src/PropSet.cxx31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/PropSet.cxx b/src/PropSet.cxx
index 296799691..b527c385c 100644
--- a/src/PropSet.cxx
+++ b/src/PropSet.cxx
@@ -411,33 +411,38 @@ bool PropSet::GetNext(char ** key, char ** val) {
return false;
}
-static bool iswordsep(char ch, bool onlyLineEnds) {
- if (!isspace(ch))
- return false;
- if (!onlyLineEnds)
- return true;
- return ch == '\r' || ch == '\n';
-}
-
/**
* Creates an array that points into each word in the string and puts \0 terminators
* after each word.
*/
static char **ArrayFromWordList(char *wordlist, int *len, bool onlyLineEnds = false) {
- char prev = '\n';
+ int prev = '\n';
int words = 0;
+ // For rapid determination of whether a character is a separator, build
+ // a look up table.
+ bool wordSeparator[256];
+ for (int i=0;i<256; i++) {
+ wordSeparator[i] = false;
+ }
+ wordSeparator['\r'] = true;
+ wordSeparator['\n'] = true;
+ if (!onlyLineEnds) {
+ wordSeparator[' '] = true;
+ wordSeparator['\t'] = true;
+ }
for (int j = 0; wordlist[j]; j++) {
- if (!iswordsep(wordlist[j], onlyLineEnds) && iswordsep(prev, onlyLineEnds))
+ int curr = static_cast<unsigned char>(wordlist[j]);
+ if (!wordSeparator[curr] && wordSeparator[prev])
words++;
- prev = wordlist[j];
+ prev = curr;
}
- char **keywords = new char * [words + 1];
+ char **keywords = new char *[words + 1];
if (keywords) {
words = 0;
prev = '\0';
size_t slen = strlen(wordlist);
for (size_t k = 0; k < slen; k++) {
- if (!iswordsep(wordlist[k], onlyLineEnds)) {
+ if (!wordSeparator[static_cast<unsigned char>(wordlist[k])]) {
if (!prev) {
keywords[words] = &wordlist[k];
words++;