code wiki / (root) / nx_txtscan_lib.nx

nx_txtscan_lib.nx

buildroot/runtime/nx_txtscan_lib.nx

6612 B139 linesdepth 0pulls 0 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_txtscan_lib.nx -- BYTE-ORIENTED text search. The unit of a match is an OFFSET, never a line. u2605u2605u2605u2605u2605u2605WE DID NOT ONLY AVOID THE UNIX TOOLS, WE INHERITED THEIR UNIT OF MEANING. Every sovereign search organ in this estate -- nx_codegrep, nx_shelltool grep -- scans for a substring and then prints "the line that contains it". That is grep's worldview, reimplemented in NishiLang: it assumes text is a sequence of newline-delimited records. MEASURED 2026-08-05, and this is the bug that motivated the organ: the ruler corpus knowledge/library/write_nsfwbot_flowgpt_2601_14324.txt is 112,755 bytes on ONE line (scraped HTML, as most fetched text is). Asking the sovereign grep for "greeting" returned the ENTIRE FILE as a single match. A search that echoes 112KB for a 8-byte pattern has not searched, it has copied -- and it reports "1 match" while telling you nothing about WHERE. u2605A TOOL THAT DEGRADES TO THE IDENTITY FUNCTION ON ITS HARDEST INPUT STILL REPORTS SUCCESS. So the fix is not a faster grep, it is a different RECORD: the offset. Offsets exist in every byte stream -- minified JSON, scraped HTML, a firmware image, a file with no newline at all -- whereas lines are a property some text happens to have. This organ imposes its own record structure on the input instead of borrowing the input's. PURE: no syscalls, no allocation, caller owns every buffer -- so the gate can prove the search hermetically with in-memory fixtures and no filesystem at all. The CLI (nx_txtscan.nx) adds I/O. license_tier: ORIGINAL module: nishi-core.text.scan capability: TEXT_SCAN_BYTE_ORIENTED

dependencies 0 imports · 3 importers

nx_txtscan_lib.nx nx_slopmeter_lib.nx nx_txtscan.nx nx_txtscan_gate.nx

imports: none

imported by: nx_slopmeter_lib.nxnx_txtscan.nxnx_txtscan_gate.nx

structs

none

consts

26const TX_NOT_FOUND: i64 = 0 - 1
33const TX_STEP_OVERLAP: i64 = 1
34const TX_STEP_DISJOINT: i64 = 0
36const TX_CASE_SENSITIVE: i64 = 0
37const TX_CASE_INSENSITIVE: i64 = 1

functions

39func tx_lower(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
40func tx_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
43func tx_match_at(buf: *u8, i: i64, pat: *u8, m: i64, ci: i64) -> i64
called by 1: tx_next calls 1: tx_lower
61func tx_next(buf: *u8, n: i64, from: i64, pat: *u8, m: i64, ci: i64) -> i64
called by 3: ts_findmaintx_count calls 1: tx_match_at
74func tx_count(buf: *u8, n: i64, pat: *u8, m: i64, ci: i64, step: i64) -> i64
called by 2: ts_countmain calls 1: tx_next
99func tx_is_ctl(c: i64) -> i64
108func tx_next_ctl(buf: *u8, n: i64, from: i64) -> i64
called by 2: ts_ctlmain calls 1: tx_is_ctl
121func tx_run_len(buf: *u8, n: i64, at: i64) -> i64
called by 2: ts_ctlmain
134func tx_ctx_lo(hit: i64, ctx: i64) -> i64 { let a: i64 = hit - ctx; if a < 0 { return 0 } return a }
called by 2: ts_findmain
135func tx_ctx_hi(hit: i64, m: i64, ctx: i64, n: i64) -> i64
called by 2: ts_findmain