MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / ArrayFromWordList

Function ArrayFromWordList

scintilla/lexlib/WordList.cxx:26–65  ·  view source on GitHub ↗

* Creates an array that points into each word in the string and puts \0 terminators * after each word. */

Source from the content-addressed store, hash-verified

24 * after each word.
25 */
26static char **ArrayFromWordList(char *wordlist, int *len, bool onlyLineEnds = false) {
27 int prev = '\n';
28 int words = 0;
29 // For rapid determination of whether a character is a separator, build
30 // a look up table.
31 bool wordSeparator[256];
32 for (int i=0; i<256; i++) {
33 wordSeparator[i] = false;
34 }
35 wordSeparator['\r'] = true;
36 wordSeparator['\n'] = true;
37 if (!onlyLineEnds) {
38 wordSeparator[' '] = true;
39 wordSeparator['\t'] = true;
40 }
41 for (int j = 0; wordlist[j]; j++) {
42 int curr = static_cast<unsigned char>(wordlist[j]);
43 if (!wordSeparator[curr] && wordSeparator[prev])
44 words++;
45 prev = curr;
46 }
47 char **keywords = new char *[words + 1];
48 words = 0;
49 prev = '\0';
50 size_t slen = strlen(wordlist);
51 for (size_t k = 0; k < slen; k++) {
52 if (!wordSeparator[static_cast<unsigned char>(wordlist[k])]) {
53 if (!prev) {
54 keywords[words] = &wordlist[k];
55 words++;
56 }
57 } else {
58 wordlist[k] = '\0';
59 }
60 prev = wordlist[k];
61 }
62 keywords[words] = &wordlist[slen];
63 *len = words;
64 return keywords;
65}
66
67WordList::WordList(bool onlyLineEnds_) :
68 words(0), list(0), len(0), onlyLineEnds(onlyLineEnds_) {

Callers 1

SetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected