Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More updates to keyvalOptions, and add GetBrackets() option to match brackets. #1037

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Jan 5, 2024

This PR fixes more issues with keyvalOptions(), and provides an option to GetBrackets() 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 or true. 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 to readValue() fix the handling of empty braces and braces containing just spaces. It turns out the the stopCount variable is not needed (everything is handled by the check for start > braces in the default branch of the switch() 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 to countBraces because startCount sounds like it should be a number, while countBraces 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 need stopCount, and the start is decremented in the default branch when a non-space character follows a brace. In this case, braces will be smaller than start, and `start will be reset to the current unclosed brace count.

The other changes to readValue()are to remove thestopCount` variable that is no longer needed.

Since LaTeX3 packages match brackets within optional arguments (e.g., \sample[a[b]c]{...} would get a[b]c as the optional argument), the GetBracket() function now has a third argument that determines whether to match internal brackets in the optional argument.

@dpvc dpvc requested a review from zorkow January 5, 2024 18:59
@dpvc dpvc added this to the v4.0 milestone Jan 5, 2024
Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@dpvc dpvc merged commit 9f19cc1 into develop Jan 18, 2024
@dpvc dpvc deleted the key-val-update branch January 18, 2024 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants