JS String.prototype.trim over bytes (the JS set == our jsws set).
(s: &[u8], mut a: usize, mut b: usize)
| 1015 | } |
| 1016 | |
| 1017 | /// JS String.prototype.trim over bytes (the JS set == our jsws set). |
| 1018 | fn 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. |
no test coverage detected