Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The primary delimiter used in CSV files
- static final String DELIM = "~";
- //The secondary delimiter, used to separate multi-valued attributes
- static final String DELIM_TWO = "`";
- public static final String ESCAPE = "^";
- public static final String ESCAPE_ENCODING = ESCAPE + "car;";
- public static final String DELIM_ONE_ENCODING = ESCAPE + "til;";
- public static final String DELIM_TWO_ENCODING = ESCAPE + "baq;";
- /**
- * Encodes strings so that data does not contain any delimiter characters
- *
- * @param s
- * @return
- */
- public static String encodeString(String s) {
- s = val(s);
- if (!findDelimCharacters(s)) {
- return s;
- }
- /*
- * The order that the characters are encoded is important. If you have the string:
- * "a~^b" and you encoded DELIM first, then you would have "a^til;^b" and then the two
- * carets in that string would get encoded which would be incorrect
- */
- return s.replace(ESCAPE, ESCAPE_ENCODING).
- replace(DELIM_TWO, DELIM_TWO_ENCODING).
- replace(DELIM, DELIM_ONE_ENCODING);
- }
Add Comment
Please, Sign In to add comment