1
0
Fork 0
forked from fun/fun

Added lot more example code. (0.39.8).

This commit is contained in:
Johannes Findeisen 2026-03-25 23:38:04 +01:00
commit 564999709c
32 changed files with 1353 additions and 53 deletions

View file

@ -16,7 +16,7 @@ fun str_ltrim(s)
src = to_string(s)
number i = 0
ws = " \t\r\n"
while i < len(src)
while (i < len(src))
ch = substr(src, i, 1)
if (find(ws, ch) < 0)
break
@ -28,7 +28,7 @@ fun str_rtrim(s)
src = to_string(s)
number i = len(src) - 1
ws = " \t\r\n"
while i >= 0
while (i >= 0)
ch = substr(src, i, 1)
if (find(ws, ch) < 0)
break
@ -69,7 +69,7 @@ fun str_split(s, delim)
buf = []
number i = 0
number n = len(src)
while i < n
while (i < n)
ch = substr(src, i, 1)
if (ch == dd)
push(parts, join(buf, ""))
@ -92,7 +92,7 @@ fun str_replace_all(s, from, to)
return src
out = []
number i = 0
while i < n
while (i < n)
if ((i + lf <= n) && (substr(src, i, lf) == f))
push(out, t)
i = i + lf
@ -109,7 +109,7 @@ fun str_to_lower(s)
out = []
number i = 0
number n = len(src)
while i < n
while (i < n)
ch = substr(src, i, 1)
idx = find(U, ch)
if (idx >= 0)
@ -127,7 +127,7 @@ fun str_to_upper(s)
out = []
number i = 0
number n = len(src)
while i < n
while (i < n)
ch = substr(src, i, 1)
idx = find(L, ch)
if (idx >= 0)
@ -145,59 +145,19 @@ fun str_repeat(s, count)
return ""
parts = []
number i = 0
while i < c
while (i < c)
push(parts, src)
i = i + 1
return join(parts, "")
/*
// ASCII string to bytes (printable ASCII 0x20..0x7E)
// Temporarily disabled due to parser incompatibilities with certain string
// literals in this function on some environments. Re-enable after the
// language parser updates to support these cases.
fun string_to_bytes_ascii(s)
str = to_string(s)
out = []
number i = 0
// ASCII printable ranges
P1 = " !\"#$%&'()*+,-./" // 32..47
P2 = "0123456789" // 48..57
P3 = ":;<=>?@" // 58..64
P4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // 65..90
P5 = "[\\]^_`" // 91..96
P6 = "abcdefghijklmnopqrstuvwxyz" // 97..122
P7 = "{|}~" // 123..126
while true
ch = substr(str, i, 1)
if (typeof(ch) != "String" || ch == "")
break
number code = -1
idx = find(P1, ch)
if (idx >= 0)
code = 32 + idx
else
idx = find(P2, ch)
if (idx >= 0)
code = 48 + idx
else
idx = find(P3, ch)
if (idx >= 0)
code = 58 + idx
else
idx = find(P4, ch)
if (idx >= 0)
code = 65 + idx
else
idx = find(P5, ch)
if (idx >= 0)
code = 91 + idx
else
idx = find(P6, ch)
if (idx >= 0)
code = 97 + idx
else
idx = find(P7, ch)
if (idx >= 0)
code = 123 + idx
else
// non-printable -> 0
code = 0
push(out, code)
i = i + 1
return out
*/