MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / parseStrings

Method parseStrings

src/org/opensourcephysics/tools/DataTool.java:1015–1053  ·  view source on GitHub ↗

Parses a String into tokens separated by a specified delimiter. A token may be "". @param text the text to parse @param delimiter the delimiter @return an array of String tokens

(String text, String delimiter)

Source from the content-addressed store, hash-verified

1013 * @return an array of String tokens
1014 */
1015 protected static String[] parseStrings(String text, String delimiter) {
1016 Collection<String> tokens = new ArrayList<String>();
1017 if (text != null) {
1018 // get the first token
1019 String next = text;
1020 int i = text.indexOf(delimiter);
1021 if (i == -1) { // no delimiter
1022 tokens.add(stripQuotes(next));
1023 text = null;
1024 } else {
1025 next = text.substring(0, i);
1026 text = text.substring(i + 1);
1027 while (" ".equals(delimiter) //$NON-NLS-1$
1028 && (text.startsWith(" ") || text.startsWith("\t"))) { //$NON-NLS-1$ //$NON-NLS-2$
1029 // treat multiple spaces/tabs as a single delimiter
1030 text = text.substring(1);
1031 }
1032 }
1033 // iterate thru the tokens and add to token list
1034 while (text != null) {
1035 tokens.add(stripQuotes(next));
1036 i = text.indexOf(delimiter);
1037 if (i == -1) { // no delimiter
1038 next = text;
1039 tokens.add(stripQuotes(next));
1040 text = null;
1041 } else {
1042 next = text.substring(0, i).trim();
1043 text = text.substring(i + 1);
1044 while (" ".equals(delimiter) //$NON-NLS-1$
1045 && (text.startsWith(" ") || text.startsWith("\t"))) { //$NON-NLS-1$ //$NON-NLS-2$
1046 // treat multiple spaces/tabs as a single delimiter
1047 text = text.substring(1);
1048 }
1049 }
1050 }
1051 }
1052 return tokens.toArray(new String[0]);
1053 }
1054
1055 /**
1056 * Strips quotation marks around a string.

Callers 2

parseDoublesMethod · 0.95
parseDataMethod · 0.95

Calls 5

stripQuotesMethod · 0.95
toArrayMethod · 0.80
equalsMethod · 0.65
addMethod · 0.45
trimMethod · 0.45

Tested by

no test coverage detected