Differences From
Artifact [f2457b558f]:
1 1 -- vim: ft=terra
2 2 -- string.t: string classes
3 3 local util = lib.util
4 4 local pstr = lib.mem.ptr(int8)
5 5 local pref = lib.mem.ref(int8)
6 6
7 7 local m = {
8 + t = pstr, ref = pref;
8 9 sz = terralib.externfunction('strlen', rawstring -> intptr);
9 10 cmp = terralib.externfunction('strcmp', {rawstring, rawstring} -> int);
10 11 ncmp = terralib.externfunction('strncmp', {rawstring, rawstring, intptr} -> int);
11 12 cpy = terralib.externfunction('stpcpy',{rawstring, rawstring} -> rawstring);
12 13 ncpy = terralib.externfunction('stpncpy',{rawstring, rawstring, intptr} -> rawstring);
13 14 cat = terralib.externfunction('strcat',{rawstring, rawstring} -> rawstring);
14 15 ncat = terralib.externfunction('strncat',{rawstring, rawstring, intptr} -> rawstring);
................................................................................
92 93
93 94 struct m.acc {
94 95 buf: rawstring
95 96 sz: intptr
96 97 run: intptr
97 98 space: intptr
98 99 }
100 +
101 +terra m.cdowncase(c: int8)
102 + if c >= @'A' and c <= @'Z' then
103 + return c + (@'a' - @'A')
104 + else return c end
105 +end
106 +
107 +terra m.cupcase(c: int8)
108 + if c >= @'a' and c <= @'z' then
109 + return c - (@'a' - @'A')
110 + else return c end
111 +end
99 112
100 113 local terra biggest(a: intptr, b: intptr)
101 114 if a > b then return a else return b end
102 115 end
103 116
104 117 terra m.acc:init(run: intptr)
105 118 --lib.dbg('initializing string accumulator')