More updates to keyvalOptions, and add GetBrackets() option to match brackets. #1037
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes more issues with
keyvalOptions()
, and provides an option toGetBrackets()
to allow matching of brackets within the argument, as is done in LaTeX packages like siunitx.One problem was that
keyvalOptions()
was removing trailing spaces when when it shouldn't. For example,keyvalOptiouns('x = { }')
should produce{x: ' '}
with a space, not an empty string ortrue
. Also,keyvalOptions('x = \\ ')
should return{x: '\\ '}
with a trailing space, not{x: '\\'}
. Finally,keyvalOptions('x = {}')
should produce{x: ''}
not{x: true}
.The changes to
removeBraces()
are to handle the issue with trimming the result inappropriately. The changes toreadValue()
fix the handling of empty braces and braces containing just spaces. It turns out the thestopCount
variable is not needed (everything is handled by the check forstart > braces
in thedefault
branch of theswitch()
statement.The change in new line 178 is to handle
\
at the end of the string, so as not to get\undefined
as a result.I changed
startCount
tocountBraces
becausestartCount
sounds like it should be a number, whilecountBraces
is a boolean.I added a check for extra close braces, since
x = a}
would not throw an error before.The logic for the
}
case is simplified, as we don't needstopCount
, and thestart
is decremented in thedefault
branch when a non-space character follows a brace. In this case,braces
will be smaller thanstart
, and `start will be reset to the current unclosed brace count.The other changes to readValue()
are to remove the
stopCount` variable that is no longer needed.Since LaTeX3 packages match brackets within optional arguments (e.g.,
\sample[a[b]c]{...}
would geta[b]c
as the optional argument), theGetBracket()
function now has a third argument that determines whether to match internal brackets in the optional argument.