mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
AK: Update OptionParser::m_arg_index by substracting skipped args
On argument swapping to put positional ones toward the end, m_arg_index was pointing at "last arg index" + "skipped args" + "consumed args" and thus was pointing ahead of the skipped ones. m_arg_index now points after the current parsed option arguments.
This commit is contained in:
parent
8320faf052
commit
a9df60ff1c
5 changed files with 382 additions and 2 deletions
|
@ -239,7 +239,7 @@ void OptionParser::shift_argv()
|
|||
{
|
||||
// We've just parsed an option (which perhaps has a value).
|
||||
// Put the option (along with its value, if any) in front of other arguments.
|
||||
if (m_consumed_args == 0 || m_skipped_arguments == 0) {
|
||||
if (m_consumed_args == 0 && m_skipped_arguments == 0) {
|
||||
// Nothing to do!
|
||||
return;
|
||||
}
|
||||
|
@ -253,6 +253,12 @@ void OptionParser::shift_argv()
|
|||
m_args.slice(m_arg_index, m_consumed_args).copy_to(buffer_bytes);
|
||||
m_args.slice(m_arg_index - m_skipped_arguments, m_skipped_arguments).copy_to(m_args.slice(m_arg_index + m_consumed_args - m_skipped_arguments));
|
||||
buffer_bytes.slice(0, m_consumed_args).copy_to(m_args.slice(m_arg_index - m_skipped_arguments, m_consumed_args));
|
||||
|
||||
// m_arg_index took into account m_skipped_arguments (both are inc in find_next_option)
|
||||
// so now we have to make m_arg_index point to the beginning of skipped arguments
|
||||
m_arg_index -= m_skipped_arguments;
|
||||
// and let's forget about skipped arguments
|
||||
m_skipped_arguments = 0;
|
||||
}
|
||||
|
||||
bool OptionParser::find_next_option()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue