@@ -153,7 +153,7 @@ fn parse_array(mut s: &str) -> Result<usize, Cow<'static, str>> {
153153}
154154
155155// example input: "0=Type:hint" (note: no braces)
156- fn parse_param ( mut s : & str ) -> Result < Param , Cow < ' static , str > > {
156+ fn parse_param ( mut s : & str , strict : bool ) -> Result < Param , Cow < ' static , str > > {
157157 const TYPE_PREFIX : & str = "=" ;
158158 const HINT_PREFIX : & str = ":" ;
159159
@@ -249,7 +249,13 @@ fn parse_param(mut s: &str) -> Result<Param, Cow<'static, str>> {
249249 } ,
250250 "X" => DisplayHint :: Hexadecimal { is_uppercase : true } ,
251251 "?" => DisplayHint :: Debug ,
252- _ => DisplayHint :: Unknown ( s. to_owned ( ) ) ,
252+ _ => {
253+ if strict {
254+ return Err ( format ! ( "unknown display hint: {:?}" , s) . into ( ) ) ;
255+ } else {
256+ DisplayHint :: Unknown ( s. to_owned ( ) )
257+ }
258+ }
253259 } ) ;
254260 } else if !s. is_empty ( ) {
255261 return Err ( format ! ( "unexpected content {:?} in format string" , s) . into ( ) ) ;
@@ -325,7 +331,10 @@ where
325331 }
326332}
327333
328- pub fn parse < ' f > ( format_string : & ' f str ) -> Result < Vec < Fragment < ' f > > , Cow < ' static , str > > {
334+ pub fn parse < ' f > (
335+ format_string : & ' f str ,
336+ strict : bool ,
337+ ) -> Result < Vec < Fragment < ' f > > , Cow < ' static , str > > {
329338 let mut fragments = Vec :: new ( ) ;
330339
331340 // Index after the `}` of the last format specifier.
@@ -363,7 +372,7 @@ pub fn parse<'f>(format_string: &'f str) -> Result<Vec<Fragment<'f>>, Cow<'stati
363372
364373 // Parse the contents inside the braces.
365374 let param_str = & format_string[ brace_pos + 1 ..] [ ..len] ;
366- let param = parse_param ( param_str) ?;
375+ let param = parse_param ( param_str, strict ) ?;
367376 fragments. push ( Fragment :: Parameter ( Parameter {
368377 index : param. index . unwrap_or_else ( || {
369378 // If there is no explicit index, assign the next one.
0 commit comments