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

Function jsws_trim

codegraph-kernel/src/cfnptr.rs:1017–1040  ·  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

1015}
1016
1017/// JS String.prototype.trim over bytes (the JS set == our jsws set).
1018fn jsws_trim(s: &[u8], mut a: usize, mut b: usize) -> (usize, usize) {
1019 loop {
1020 let l = jsws_len(s, a);
1021 if l == 0 || a + l > b {
1022 break;
1023 }
1024 a += l;
1025 }
1026 // Trailing: walk from the front to find the last non-ws position (ws
1027 // lengths vary, so scan forward tracking the end of the last non-ws char).
1028 let mut i = a;
1029 let mut last_end = a;
1030 while i < b {
1031 let l = jsws_len(s, i);
1032 if l == 0 {
1033 i += 1;
1034 last_end = i;
1035 } else {
1036 i += l;
1037 }
1038 }
1039 b = last_end;
1040 (a, b)
1041}
1042
1043/// /(\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