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