4 //TODO: Make this use a tree instead of a linear lookup
6 uint lookup(const char *str, bool create) {
15 array.Add(StrDup(str));
18 const char *name(uint index) {
19 if (index >= array.size)
28 Array<char*> array {};
31 //CharFlags is a collection of characters that are to be returned (or not returned) by the find* functions
33 property char *charsSet {
35 const byte *n = (const byte*)value;
38 flags[(uint)*n++] = ++val;
42 set { charsSet = value; }
45 byte flags[256]; //flags[c] indicates whether character c is selected
47 memset(flags, 0, sizeof(flags));
49 void Set(const char *needles, int val) {
50 const byte *n = (const byte*)needles;
53 flags[(uint)*n++] = v;
57 char *findfirst(const char *haystack, uint haystacklen, CharFlags cf) {
58 const byte *h = (const byte*)haystack;
59 while (haystacklen--) {
60 if (cf.flags[(uint)*h++])
65 char *findfirstnon(const char *haystack, uint haystacklen, CharFlags cf) {
66 const byte *h = (const byte*)haystack;
67 while (haystacklen--) {
68 if (!cf.flags[(uint)*h++])
73 char *findlast(const char *haystack, uint haystacklen, CharFlags cf) {
74 const byte *h = (const byte*)haystack + haystacklen;
75 while (haystacklen--) {
76 if (cf.flags[(uint)*--h])
81 char *findlastnon(const char *haystack, uint haystacklen, CharFlags cf) {
82 const byte *h = (const byte*)haystack + haystacklen;
83 while (haystacklen--) {
84 if (!cf.flags[(uint)*--h])
90 char *StrDup(const char *src) {
97 memcpy(ret, src, len);
101 define NB_ALLOWHIGHERDIGITS = 256;
102 define NB_ALLOWCAPLETTERS = 512;
103 define NB_ALLOWLCASELETTERS = 1024;
104 define NB_ALLOWLETTERS = (NB_ALLOWCAPLETTERS | NB_ALLOWLCASELETTERS);
106 define NB_Dec = ((uint16)(10));
107 define NB_Hex = ((uint16)(16 | NB_ALLOWLETTERS));
108 define NB_Bin = ((uint16)(2));
109 define NB_Oct = ((uint16)(8));
110 define NB_OctLoose = ((uint16)(8 | NB_ALLOWHIGHERDIGITS));
112 enum ReadULLError {noerror=0,empty=1,overflow=2};
114 //input must only contain valid digits for the given base
115 unsigned long long ReadULL_Valid(const char *ptr,const char *eptr, uint16 base, ReadULLError *errorout)
117 unsigned long long ret=0;
118 unsigned long long multiplier=1;
119 unsigned long long temp;
120 ReadULLError rerror = noerror;
126 //the range ptr-->eptr is all valid digits, and eptr is iterating backwards through the range.
130 //this series of if statements takes advantage of the fact that 'a'>'A'>'0'
139 if ((c&&!temp) || ret > ~temp) //if overflow occurred
142 multiplier *= (unsigned long long)base & 0xFF;