Skip to content

Conversation

@vaambival
Copy link
Contributor

  • 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*;?$");
Copy link
Member

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);
Copy link
Member

@inponomarev inponomarev Sep 23, 2018

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:

  1. 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!

  1. 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));
}
}
Copy link
Member

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

@vaambival vaambival force-pushed the feature/pk-173-add-property-of-cell branch from 0bbb228 to 111a2dc Compare September 23, 2018 14:58
- added DynamicCellStyle for parse style params of cell
- added test for check regex validation
@vaambival vaambival force-pushed the feature/pk-173-add-property-of-cell branch from e70a0d1 to 9df0906 Compare September 23, 2018 15:24
@inponomarev inponomarev merged commit c83e11d into CourseOrchestra:dev Sep 24, 2018
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