code wiki / _hdl_build / nx_gen_util.nx
nx_gen_util.nx source
↩ module page · 25 lines · 1288 B
1// nx_gen_util.nx -- shared string/scan primitives = the BASE MODULE of the companion/gen OO decomposition.
2// Pure functions extracted VERBATIM from nx_gen_orchestrator (behaviour-preserving). Imported by the orchestrator
3// + every companion object. Object model: companion_arch.md. license_tier: ORIGINAL
4
5func go_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
6func go_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i]; o=o+1; i=i+1} return o }
7func go_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var o: i64=off; var i: i64=0; while i<n {dst[o]=src[i]; o=o+1; i=i+1} return o }
8// case-insensitive: 1 if NUL-term `needle` occurs in hay[0..hlen)
9func go_contains_ci(hay: *u8, hlen: i64, needle: *u8) -> i64 {
10 var nl: i64 = 0; while needle[nl]!=(0 as u8) { nl=nl+1 }
11 if nl==0 { return 0 }
12 var i: i64 = 0
13 while i + nl <= hlen {
14 var j: i64 = 0; var ok: i64 = 1
15 while j < nl {
16 var a: i64 = hay[i+j]&0xff; var b2: i64 = needle[j]&0xff
17 if a>=65 { if a<=90 { a=a+32 } }
18 if b2>=65 { if b2<=90 { b2=b2+32 } }
19 if a!=b2 { ok=0; j=nl } else { j=j+1 }
20 }
21 if ok==1 { return 1 }
22 i=i+1
23 }
24 return 0
25}