@@ -686,27 +686,26 @@ where
686686}
687687
688688fn trim_end_unescaped ( s : & str ) -> & str {
689- use unicode_width:: UnicodeWidthChar ;
690689 let mut cbuf = [ 0 ; 4 ] ;
691- let mut initial_space_bytes = 0 ;
692- let mut last_char_width = 0 ;
690+ let mut total_ws_bytes = 0 ;
691+ let mut last_ws_char_len = 0 ;
693692 // First loop over spaces
694693 for ch in s. chars ( ) . rev ( ) . into_iter ( ) {
695694 if RE_SPACE_SEP . is_match ( ch. encode_utf8 ( & mut cbuf) ) {
696- last_char_width = ch. width ( ) . unwrap_or ( 0 ) ;
697- initial_space_bytes += last_char_width ;
695+ last_ws_char_len = ch. len_utf8 ( ) ;
696+ total_ws_bytes += last_ws_char_len ;
698697 } else {
699698 break ;
700699 }
701700 }
702- if initial_space_bytes == 0 {
701+ if total_ws_bytes == 0 {
703702 return s;
704703 }
705704 let mut preceeding_backslashes = 0 ;
706705 // Next loop over escaped slashes or spaces,
707706 // an even number of backslashes are all escaping slashes,
708707 // and an odd number of backslashes must have a trailing escaped space.
709- for c in s[ ..s. len ( ) - initial_space_bytes ] . chars ( ) . rev ( ) {
708+ for c in s[ ..s. len ( ) - total_ws_bytes ] . chars ( ) . rev ( ) {
710709 if c == '\\' {
711710 preceeding_backslashes += 1
712711 } else {
@@ -716,10 +715,10 @@ fn trim_end_unescaped(s: &str) -> &str {
716715 // The backslash count was odd, the last must escape a space.
717716 // Drop one of the intial spaces from the trim.
718717 if preceeding_backslashes % 2 == 1 {
719- initial_space_bytes -= last_char_width ;
718+ total_ws_bytes -= last_ws_char_len ;
720719 }
721720
722- & s[ ..s. len ( ) - initial_space_bytes ]
721+ & s[ ..s. len ( ) - total_ws_bytes ]
723722}
724723
725724#[ cfg( test) ]
0 commit comments