michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "strset.h" michael@0: #include michael@0: #include michael@0: michael@0: StrSet::StrSet() michael@0: { michael@0: strings = 0; michael@0: numstrings = 0; michael@0: } michael@0: michael@0: void StrSet::add(const char* s) michael@0: { michael@0: if (strings) { michael@0: strings = (char**) realloc(strings, (numstrings + 1) * sizeof(char*)); michael@0: } else { michael@0: strings = (char**) malloc(sizeof(char*)); michael@0: } michael@0: strings[numstrings] = strdup(s); michael@0: numstrings++; michael@0: } michael@0: michael@0: int StrSet::contains(const char* s) michael@0: { michael@0: char** sp = strings; michael@0: int i = numstrings; michael@0: michael@0: while (--i >= 0) { michael@0: char *ss = *sp++; michael@0: if (ss[0] == s[0]) { michael@0: if (strcmp(ss, s) == 0) { michael@0: return 1; michael@0: } michael@0: } michael@0: } michael@0: return 0; michael@0: }