@@ -604,14 +604,18 @@ function isHTTPWhiteSpace (char) {
604
604
* @param {boolean } [trailing=true]
605
605
*/
606
606
function removeHTTPWhitespace ( str , leading = true , trailing = true ) {
607
- let i = 0 ; let j = str . length
607
+ let lead = 0
608
+ let trail = str . length - 1
609
+
608
610
if ( leading ) {
609
- while ( j > i && isHTTPWhiteSpace ( str . charCodeAt ( i ) ) ) -- i
611
+ while ( lead < str . length && isHTTPWhiteSpace ( str . charCodeAt ( lead ) ) ) lead ++
610
612
}
613
+
611
614
if ( trailing ) {
612
- while ( j > i && isHTTPWhiteSpace ( str . charCodeAt ( j - 1 ) ) ) -- j
615
+ while ( trail > 0 && isHTTPWhiteSpace ( str . charCodeAt ( trail ) ) ) trail --
613
616
}
614
- return i === 0 && j === str . length ? str : str . substring ( i , j )
617
+
618
+ return lead === 0 && trail === str . length - 1 ? str : str . slice ( lead , trail + 1 )
615
619
}
616
620
617
621
/**
@@ -630,14 +634,18 @@ function isASCIIWhitespace (char) {
630
634
* @param {boolean } [trailing=true]
631
635
*/
632
636
function removeASCIIWhitespace ( str , leading = true , trailing = true ) {
633
- let i = 0 ; let j = str . length
637
+ let lead = 0
638
+ let trail = str . length - 1
639
+
634
640
if ( leading ) {
635
- while ( j > i && isASCIIWhitespace ( str . charCodeAt ( i ) ) ) -- i
641
+ while ( lead < str . length && isASCIIWhitespace ( str . charCodeAt ( lead ) ) ) lead ++
636
642
}
643
+
637
644
if ( trailing ) {
638
- while ( j > i && isASCIIWhitespace ( str . charCodeAt ( j - 1 ) ) ) -- j
645
+ while ( trail > 0 && isASCIIWhitespace ( str . charCodeAt ( trail ) ) ) trail --
639
646
}
640
- return i === 0 && j === str . length ? str : str . substring ( i , j )
647
+
648
+ return lead === 0 && trail === str . length - 1 ? str : str . slice ( lead , trail + 1 )
641
649
}
642
650
643
651
module . exports = {
0 commit comments