-
Notifications
You must be signed in to change notification settings - Fork 8
Update dotstrings parser to handle entries with multi-line values #12
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
base: master
Are you sure you want to change the base?
Conversation
The dotstrings parser has been updated to handle multi-line entries in the format "key = value;". This allows for more flexibility in writing and parsing dotstrings files.
| comment = re.compile(r"(\'(?:[^\'\\]|\\[\s\S])*\')|//.*|/\*(?:[^*]|\*(?!/))*\*/", re.MULTILINE) | ||
| whitespace = re.compile(r"\s*", re.MULTILINE) | ||
| entry = re.compile(r'"(.*)"\s*=\s*"(.*)";') | ||
| entry = re.compile(r'"([^"]*?)"\s*=\s*"((?:[^";]|"(?!\s*;))*?)";', re.DOTALL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this will break on strings that contain quotes. e.g. NSLocalizedString("Hello \"World\"", "Some Comment") gets turned into "Hello \"World\"" = "Hello \"World\"";.
I think the second change on this line will also stop the string containing ;.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first change is there so that the first match group doesn't end up matching the whole string (even matching the "value" part).
But yeah it wouldn't work when there are more than two quotes, in the "key" part of the string (the two quotes around the key itself). This was intentional because I didn't thought there would be any "key" that would have more quotes than two.
If we really want to cater keys that have quotes inside of them, we can replicate the regex that we have for value part, but without the semicolon
entry = re.compile(r'"((?:[^";]|"(?!\s*;))*?)"\s*=\s*"((?:[^";]|"(?!\s*;))*?)";')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second change is finding a ";" to match the value part of the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the test file I have here to contain edge cases?
|
Also there is a line that I hate everytime I take a look at it. comment = comment[::-1].replace("/*", "", 1)[::-1] Or maybe I am missing something? :) |
The dotstrings parser has been updated to handle multi-line entries in the format
This allows for more flexibility in writing and parsing dotstrings files