| 3 | import utils from '../utils.js'; |
| 4 | |
| 5 | function trimSPorHTAB(str) { |
| 6 | let start = 0; |
| 7 | let end = str.length; |
| 8 | |
| 9 | while (start < end) { |
| 10 | const code = str.charCodeAt(start); |
| 11 | |
| 12 | if (code !== 0x09 && code !== 0x20) { |
| 13 | break; |
| 14 | } |
| 15 | |
| 16 | start += 1; |
| 17 | } |
| 18 | |
| 19 | while (end > start) { |
| 20 | const code = str.charCodeAt(end - 1); |
| 21 | |
| 22 | if (code !== 0x09 && code !== 0x20) { |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | end -= 1; |
| 27 | } |
| 28 | |
| 29 | return start === 0 && end === str.length ? str : str.slice(start, end); |
| 30 | } |
| 31 | |
| 32 | // The control-code ranges are intentional: header sanitization strips C0/DEL bytes. |
| 33 | // eslint-disable-next-line no-control-regex |