Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "strset.h"
6 #include <malloc.h>
7 #include <string.h>
9 StrSet::StrSet()
10 {
11 strings = 0;
12 numstrings = 0;
13 }
15 void StrSet::add(const char* s)
16 {
17 if (strings) {
18 strings = (char**) realloc(strings, (numstrings + 1) * sizeof(char*));
19 } else {
20 strings = (char**) malloc(sizeof(char*));
21 }
22 strings[numstrings] = strdup(s);
23 numstrings++;
24 }
26 int StrSet::contains(const char* s)
27 {
28 char** sp = strings;
29 int i = numstrings;
31 while (--i >= 0) {
32 char *ss = *sp++;
33 if (ss[0] == s[0]) {
34 if (strcmp(ss, s) == 0) {
35 return 1;
36 }
37 }
38 }
39 return 0;
40 }