Changeset 23094 in osm for applications/editors
- Timestamp:
- 2010-09-10T17:23:39+02:00 (14 years ago)
- Location:
- applications/editors/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSImporterAction.java
r22148 r23094 219 219 220 220 System.out.println("Public Transport: StopInserter: No data found"); 221 222 return; 221 223 } 222 224 else … … 241 243 JOptionPane.ERROR_MESSAGE); 242 244 243 System.out.println("Public Transport: GTFSImporter: No data found"); 245 System.out.println("Public Transport: GTFSImporter: No data found"); 246 247 return; 244 248 } 245 249 -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSStopTableModel.java
r22148 r23094 26 26 private int latCol = -1; 27 27 private int lonCol = -1; 28 private char separator = ','; 28 29 29 30 public GTFSStopTableModel(GTFSImporterAction controller, 30 31 String columnConfig) 31 32 { 32 int pos = columnConfig.indexOf(','); 33 int pos = columnConfig.indexOf(separator); 34 if (pos == -1) 35 { 36 separator = ';'; 37 pos = columnConfig.indexOf(separator); 38 } 39 if (pos == -1) 40 { 41 separator = '\t'; 42 pos = columnConfig.indexOf(separator); 43 } 33 44 int oldPos = 0; 34 45 int i = 0; … … 46 57 ++i; 47 58 oldPos = pos + 1; 48 pos = columnConfig.indexOf( ',', oldPos);59 pos = columnConfig.indexOf(separator, oldPos); 49 60 } 50 61 String title = columnConfig.substring(oldPos); … … 89 100 insertRow(-1, s, existingStops); 90 101 } 102 103 /* tokenizes a line as follows: 104 any comma outside a pair of double quotation marks is taken as field separator. 105 In particular, neither \" nor \, have a special meaning. 106 Returns the position of the next field separator, if any. Otherwise it returns -1. 107 s - the string to tokenize. 108 startPos - the position of the last field separator plus 1 or the value 0. */ 109 private int tokenize(String s, int startPos) 110 { 111 int pos = startPos; 112 boolean insideDoubleQuoted = false; 113 while (pos < s.length()) 114 { 115 if ('"' == s.charAt(pos)) 116 insideDoubleQuoted = !insideDoubleQuoted; 117 else if ((separator == s.charAt(pos)) && (!insideDoubleQuoted)) 118 break; 119 ++pos; 120 } 121 if (pos < s.length()) 122 return pos; 123 else 124 return -1; 125 } 126 127 private String stripQuot(String s) 128 { 129 int pos = s.indexOf('"'); 130 while (pos > -1) 131 { 132 s = s.substring(0, pos) + s.substring(pos + 1); 133 pos = s.indexOf('"'); 134 } 135 return s; 136 } 91 137 92 138 public void insertRow(int insPos, String s, Vector< Node > existingStops) 93 139 { 140 System.out.println("insertRow(" + insPos + ", [" + s + "], ..)"); 141 94 142 String[] buf = { "", "", "pending" }; 95 int pos = s.indexOf(',');143 int pos = tokenize(s, 0); 96 144 int oldPos = 0; 97 145 int i = 0; … … 100 148 while (pos > -1) 101 149 { 150 System.out.println("[" + stripQuot(s.substring(oldPos, pos)) + "]"); 151 102 152 if (i == idCol) 103 buf[0] = s .substring(oldPos, pos);153 buf[0] = stripQuot(s.substring(oldPos, pos)); 104 154 else if (i == nameCol) 105 buf[1] = s .substring(oldPos, pos);155 buf[1] = stripQuot(s.substring(oldPos, pos)); 106 156 else if (i == latCol) 107 lat = Double.parseDouble(s .substring(oldPos, pos));157 lat = Double.parseDouble(stripQuot(s.substring(oldPos, pos))); 108 158 else if (i == lonCol) 109 lon = Double.parseDouble(s .substring(oldPos, pos));159 lon = Double.parseDouble(stripQuot(s.substring(oldPos, pos))); 110 160 ++i; 111 161 oldPos = pos + 1; 112 pos = s.indexOf(',', oldPos);162 pos = tokenize(s, oldPos); 113 163 } 114 164 if (i == idCol) 115 buf[0] = s .substring(oldPos);165 buf[0] = stripQuot(s.substring(oldPos)); 116 166 else if (i == nameCol) 117 buf[1] = s .substring(oldPos);167 buf[1] = stripQuot(s.substring(oldPos)); 118 168 else if (i == latCol) 119 lat = Double.parseDouble(s .substring(oldPos));169 lat = Double.parseDouble(stripQuot(s.substring(oldPos))); 120 170 else if (i == lonCol) 121 lon = Double.parseDouble(s .substring(oldPos));171 lon = Double.parseDouble(stripQuot(s.substring(oldPos))); 122 172 123 173 LatLon coor = new LatLon(lat, lon);
Note:
See TracChangeset
for help on using the changeset viewer.