Differences From
Artifact [01c1839f00]:
- File
mods/vtlib/str.lua
— part of check-in
[953151446f]
at
2024-05-05 19:31:39
on branch trunk
— better alarm LEDs, continue work on matter compiler UI, hack around gravitational horrorscape (i.e. stop shitting all over the server's `minetest.conf`), better stat interface, tweak some compute stats, be more generous with starting battery loadout, mercilessly squash numberless bugs beneath my jackbooted heel
(user:
lexi,
size: 5957)
[annotate]
[blame]
[check-ins using]
161 161 else
162 162 tbl[#tbl+1] = string.sub(ss,1,d-1)
163 163 end
164 164 until i > string.len(str)
165 165 return tbl
166 166 end;
167 167
168 - rand = function(min,max)
168 + rand = function(rng, min,max)
169 169 if not min then min = 16 end
170 170 if not max then max = min end
171 171 local str = ''
172 172 local r_int = 0x39 - 0x30
173 173 local r_upper = r_int + (0x5a - 0x41)
174 174 local r_lower = r_upper + (0x7a - 0x61)
175 - for i = 1,math.random(max - min) + min do
175 + for i = 1,rng:int(min,max) do
176 176 -- 0x30 -- 0x39
177 177 -- 0x41 -- 0x5A
178 178 -- 0x61 -- 0x71
179 - local codepoint = math.random(r_lower)
179 + local codepoint = rng:int(r_lower)
180 180 if codepoint > r_upper then
181 181 codepoint = (codepoint - r_upper) + 0x61
182 182 elseif codepoint > r_int then
183 183 codepoint = (codepoint - r_int) + 0x41
184 184 else
185 185 codepoint = codepoint + 0x30
186 186 end
187 187 str = str .. string.char(codepoint)
188 188 end
189 189 return str
190 190 end;
191 +
192 + htsan = function(str)
193 + return str:gsub('([<\\])', '\\%1')
194 + end;
191 195
192 196 chop = function(str)
193 197 if string.sub(str, 1,1) == ' ' then
194 198 str = string.sub(str, 2)
195 199 end
196 200 if string.sub(str, #str,#str) == ' ' then
197 201 str = string.sub(str, 1, #str - 1)