MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / jsws_trim

Function jsws_trim

codegraph-kernel/src/cfnptr.rs:1007–1030  ·  view source on GitHub ↗

JS String.prototype.trim over bytes (the JS set == our jsws set).

(s: &[u8], mut a: usize, mut b: usize)

Source from the content-addressed store, hash-verified

1005}
1006
1007/// JS String.prototype.trim over bytes (the JS set == our jsws set).
1008fn jsws_trim(s: &[u8], mut a: usize, mut b: usize) -> (usize, usize) {
1009 loop {
1010 let l = jsws_len(s, a);
1011 if l == 0 || a + l > b {
1012 break;
1013 }
1014 a += l;
1015 }
1016 // Trailing: walk from the front to find the last non-ws position (ws
1017 // lengths vary, so scan forward tracking the end of the last non-ws char).
1018 let mut i = a;
1019 let mut last_end = a;
1020 while i < b {
1021 let l = jsws_len(s, i);
1022 if l == 0 {
1023 i += 1;
1024 last_end = i;
1025 } else {
1026 i += l;
1027 }
1028 }
1029 b = last_end;
1030 (a, b)
1031}
1032
1033/// /(\w+)\s+\**\s*(\w+)\s*$/ — leftmost match whose tail reaches the end.

Callers 1

parse_struct_fields_rawFunction · 0.85

Calls 1

jsws_lenFunction · 0.85

Tested by

no test coverage detected