From 6148d681f460a33a9649b8c4059986e91f214a55 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 14 Apr 2022 16:08:50 -0500 Subject: [PATCH] refactor(lex): Clarify side effects --- src/parse/lexer.rs | 6 +++--- src/parse/parser.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parse/lexer.rs b/src/parse/lexer.rs index eb84ac34..9c1104c4 100644 --- a/src/parse/lexer.rs +++ b/src/parse/lexer.rs @@ -212,7 +212,7 @@ impl<'s> ShortFlags<'s> { self.invalid_suffix.is_none() && self.utf8_prefix.as_str().parse::().is_ok() } - pub fn next(&mut self) -> Option> { + pub fn next_flag(&mut self) -> Option> { if let Some((_, flag)) = self.utf8_prefix.next() { return Some(Ok(flag)); } @@ -225,7 +225,7 @@ impl<'s> ShortFlags<'s> { None } - pub fn value_os(&mut self) -> Option<&'s RawOsStr> { + pub fn next_value_os(&mut self) -> Option<&'s RawOsStr> { if let Some((index, _)) = self.utf8_prefix.next() { self.utf8_prefix = "".char_indices(); self.invalid_suffix = None; @@ -245,7 +245,7 @@ impl<'s> Iterator for ShortFlags<'s> { type Item = Result; fn next(&mut self) -> Option { - self.next() + self.next_flag() } } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index f37e39ff..be16b272 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -969,7 +969,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { "tracking of `flag_subcmd_skip` is off for `{:?}`", short_arg ); - while let Some(c) = short_arg.next() { + while let Some(c) = short_arg.next_flag() { let c = match c { Ok(c) => c, Err(rest) => { @@ -1010,7 +1010,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { // Check for trailing concatenated value // // Cloning the iterator, so we rollback if it isn't there. - let val = short_arg.clone().value_os().unwrap_or_default(); + let val = short_arg.clone().next_value_os().unwrap_or_default(); debug!( "Parser::parse_short_arg:iter:{}: val={:?} (bytes), val={:?} (ascii), short_arg={:?}", c, val, val.as_raw_bytes(), short_arg