@@ -26,7 +26,7 @@ impl FStringParser {
26
26
mut chars : iter:: Peekable < str:: Chars < ' a > > ,
27
27
nested : u8 ,
28
28
) -> Result < ( Vec < Expr > , iter:: Peekable < str:: Chars < ' a > > ) , FStringErrorType > {
29
- let mut expression = String :: from ( "{" ) ;
29
+ let mut expression = String :: new ( ) ;
30
30
let mut spec = None ;
31
31
let mut delims = Vec :: new ( ) ;
32
32
let mut conversion = ConversionFlag :: None ;
@@ -67,14 +67,14 @@ impl FStringParser {
67
67
Some ( 'a' ) => ConversionFlag :: Ascii ,
68
68
Some ( 'r' ) => ConversionFlag :: Repr ,
69
69
Some ( _) => {
70
- return Err ( if expression[ 1 .. ] . trim ( ) . is_empty ( ) {
70
+ return Err ( if expression. trim ( ) . is_empty ( ) {
71
71
EmptyExpression
72
72
} else {
73
73
InvalidConversionFlag
74
74
} ) ;
75
75
}
76
76
None => {
77
- return Err ( if expression[ 1 .. ] . trim ( ) . is_empty ( ) {
77
+ return Err ( if expression. trim ( ) . is_empty ( ) {
78
78
EmptyExpression
79
79
} else {
80
80
UnclosedLbrace
@@ -84,14 +84,14 @@ impl FStringParser {
84
84
85
85
if let Some ( & peek) = chars. peek ( ) {
86
86
if peek != '}' && peek != ':' {
87
- return Err ( if expression[ 1 .. ] . trim ( ) . is_empty ( ) {
87
+ return Err ( if expression. trim ( ) . is_empty ( ) {
88
88
EmptyExpression
89
89
} else {
90
90
UnclosedLbrace
91
91
} ) ;
92
92
}
93
93
} else {
94
- return Err ( if expression[ 1 .. ] . trim ( ) . is_empty ( ) {
94
+ return Err ( if expression. trim ( ) . is_empty ( ) {
95
95
EmptyExpression
96
96
} else {
97
97
UnclosedLbrace
@@ -156,15 +156,14 @@ impl FStringParser {
156
156
}
157
157
}
158
158
'}' => {
159
- if expression[ 1 .. ] . trim ( ) . is_empty ( ) {
159
+ if expression. trim ( ) . is_empty ( ) {
160
160
return Err ( EmptyExpression ) ;
161
161
}
162
- expression. push ( ch) ;
163
162
164
163
let ret = if !self_documenting {
165
164
vec ! [ self . expr( ExprKind :: FormattedValue {
166
165
value: Box :: new(
167
- parse_fstring_expr( & expression[ 1 ..expression . len ( ) - 1 ] )
166
+ parse_fstring_expr( & expression)
168
167
. map_err( |e| InvalidExpression ( Box :: new( e. error) ) ) ?,
169
168
) ,
170
169
conversion: conversion as _,
@@ -173,9 +172,7 @@ impl FStringParser {
173
172
} else {
174
173
vec ! [
175
174
self . expr( ExprKind :: Constant {
176
- value: Constant :: Str (
177
- expression[ 1 ..expression. len( ) - 1 ] . to_owned( ) + "=" ,
178
- ) ,
175
+ value: Constant :: Str ( expression. to_owned( ) + "=" ) ,
179
176
kind: None ,
180
177
} ) ,
181
178
self . expr( ExprKind :: Constant {
@@ -184,7 +181,7 @@ impl FStringParser {
184
181
} ) ,
185
182
self . expr( ExprKind :: FormattedValue {
186
183
value: Box :: new(
187
- parse_fstring_expr( & expression[ 1 ..expression . len ( ) - 1 ] )
184
+ parse_fstring_expr( & expression)
188
185
. map_err( |e| InvalidExpression ( Box :: new( e. error) ) ) ?,
189
186
) ,
190
187
conversion: ( if conversion == ConversionFlag :: None && spec. is_none( )
@@ -226,7 +223,7 @@ impl FStringParser {
226
223
}
227
224
}
228
225
}
229
- Err ( if expression[ 1 .. ] . trim ( ) . is_empty ( ) {
226
+ Err ( if expression. trim ( ) . is_empty ( ) {
230
227
EmptyExpression
231
228
} else {
232
229
UnclosedLbrace
0 commit comments