JS String.prototype.trim over bytes (the JS set == our jsws set).
(s: &[u8], mut a: usize, mut b: usize)
| 987 | } |
| 988 | |
| 989 | /// JS String.prototype.trim over bytes (the JS set == our jsws set). |
| 990 | fn jsws_trim(s: &[u8], mut a: usize, mut b: usize) -> (usize, usize) { |
| 991 | loop { |
| 992 | let l = jsws_len(s, a); |
| 993 | if l == 0 || a + l > b { |
| 994 | break; |
| 995 | } |
| 996 | a += l; |
| 997 | } |
| 998 | // Trailing: walk from the front to find the last non-ws position (ws |
| 999 | // lengths vary, so scan forward tracking the end of the last non-ws char). |
| 1000 | let mut i = a; |
| 1001 | let mut last_end = a; |
| 1002 | while i < b { |
| 1003 | let l = jsws_len(s, i); |
| 1004 | if l == 0 { |
| 1005 | i += 1; |
| 1006 | last_end = i; |
| 1007 | } else { |
| 1008 | i += l; |
| 1009 | } |
| 1010 | } |
| 1011 | b = last_end; |
| 1012 | (a, b) |
| 1013 | } |
| 1014 | |
| 1015 | /// /(\w+)\s+\**\s*(\w+)\s*$/ — leftmost match whose tail reaches the end. |
no test coverage detected