-
Notifications
You must be signed in to change notification settings - Fork 7
PK-173 #23
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
PK-173 #23
Conversation
vaambival
commented
Sep 23, 2018
- added DynamicCellStyle for parse style params of cell
- added test for check regex validation
| private static final String DELIMITER_FOR_ALL_PARAMS = "||"; | ||
| private static final String DELIMITER_FOR_EACH_PARAM = ";"; | ||
| private static final String KEY_VALUE_DELIMITER = ":"; | ||
| private static final Pattern p = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*\\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.
suggested regexp
(\|\|\s*([a-zA-Z][a-zA-Z0-9_\-]*\s*:\s*"([^"]|"")*"\s*;?\s*)+)$
| } | ||
|
|
||
| String paramsString = record.substring(indexOfParams + DELIMITER_FOR_ALL_PARAMS.length()); | ||
| String[] parameters = paramsString.split(DELIMITER_FOR_EACH_PARAM); |
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.
What if semicolon is in the parameter value? what if '||' is somewhere in the text, but they don't mean it as a delimeter?
OK. When dealing with string parsing,
- you never need to use
split() - you never ever need to use
indexOf()-- please just forget about it!!
The outline is as following:
- You just need to match the whole string by regexp.
2.1. If it doesn't match -- we don't have the properties. And it doen't matter if semicolons or || are in the string or not -- semicolons won't fool us, if the string as a whole doesn't match the pattern.
2.2. If it matches -- group(1) will return you the part that starts from ||. Knowing its length, you can split the original string in two parts. NB: in the left part '||' might occur, but we handle it!
- Now process the part that starts from '||'. You may use
([a-zA-Z][a-zA-Z0-9_\-]*)\s*:\s*"(([^"]|"")*)"regexp to find the key-value pairs in cycle.group(1)will return you the key,group(2)will return you the value: already stripped from whitespaces, semicolons and outer quotes! You will need to change""for"in the values, though.
|
|
||
| assertTrue(actual.equals(expected)); | ||
| } | ||
| } |
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.
OK, here are more sofisticated examples to check:
aaa || aa; bb
should return the string as is.
aaa abbb || color: "#AABBCC"; value: "a b"; quotedvalue: "aa""bb""" background-color: "blue"
should parse and yield the left part and the map (testing for semicolons in property values, dashes in property name)
aaa || bbb ||key: "value || "
should also parse, the left part should be aaa || bbb, the map should contain key: "value || " mapping
0bbb228 to
111a2dc
Compare
e70a0d1 to
9df0906
Compare
…73-add-property-of-cell