Lines 209-215
Link Here
|
209 |
public static final char TAG_POSTFIX= '$'; |
209 |
public static final char TAG_POSTFIX= '$'; |
210 |
public static final int TAG_POSTFIX_LENGTH= 1; |
210 |
public static final int TAG_POSTFIX_LENGTH= 1; |
211 |
public Set nonNLSStrings = null; |
211 |
public Set nonNLSStrings = null; |
212 |
public Set unnecessaryNONNLSTags = null; |
212 |
public Set unnecessaryNLSTags = null; |
213 |
|
213 |
|
214 |
// generic support |
214 |
// generic support |
215 |
public boolean returnOnlyGreater = false; |
215 |
public boolean returnOnlyGreater = false; |
Lines 904-910
Link Here
|
904 |
if (this.currentPosition > this.eofPosition) |
904 |
if (this.currentPosition > this.eofPosition) |
905 |
return TokenNameEOF; |
905 |
return TokenNameEOF; |
906 |
} |
906 |
} |
907 |
//little trick to get out in the middle of a source compuation |
|
|
908 |
if (this.currentPosition > this.eofPosition) |
907 |
if (this.currentPosition > this.eofPosition) |
909 |
return TokenNameEOF; |
908 |
return TokenNameEOF; |
910 |
if (checkIfUnicode) { |
909 |
if (checkIfUnicode) { |
Lines 913-925
Link Here
|
913 |
} else { |
912 |
} else { |
914 |
offset = this.currentPosition - offset; |
913 |
offset = this.currentPosition - offset; |
915 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
914 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
916 |
if (this.currentLine != null) { |
915 |
if (this.currentLine != null && this.currentLine.size() != 0) { |
917 |
parseTags(false); |
916 |
parseTags(false); |
918 |
} |
917 |
} |
919 |
if (this.recordLineSeparator) { |
918 |
if (this.recordLineSeparator) { |
920 |
pushLineSeparator(); |
919 |
pushLineSeparator(); |
921 |
} else if (this.currentLine != null) { |
|
|
922 |
this.currentLine.clear(); |
923 |
} |
920 |
} |
924 |
} |
921 |
} |
925 |
// inline version of: |
922 |
// inline version of: |
Lines 1355-1362
Link Here
|
1355 |
} else { |
1352 |
} else { |
1356 |
pushLineSeparator(); |
1353 |
pushLineSeparator(); |
1357 |
} |
1354 |
} |
1358 |
} else if (this.currentLine != null) { |
|
|
1359 |
this.currentLine.clear(); |
1360 |
} |
1355 |
} |
1361 |
} |
1356 |
} |
1362 |
if (this.tokenizeComments) { |
1357 |
if (this.tokenizeComments) { |
Lines 1400-1406
Link Here
|
1400 |
star = true; |
1395 |
star = true; |
1401 |
} |
1396 |
} |
1402 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1397 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1403 |
if (this.currentLine != null) { |
1398 |
if (this.currentLine != null && this.currentLine.size() != 0) { |
1404 |
parseTags(false); |
1399 |
parseTags(false); |
1405 |
} |
1400 |
} |
1406 |
if (this.recordLineSeparator) { |
1401 |
if (this.recordLineSeparator) { |
Lines 1409-1416
Link Here
|
1409 |
} else { |
1404 |
} else { |
1410 |
pushLineSeparator(); |
1405 |
pushLineSeparator(); |
1411 |
} |
1406 |
} |
1412 |
} else if (currentLine != null){ |
|
|
1413 |
this.currentLine.clear(); |
1414 |
} |
1407 |
} |
1415 |
} |
1408 |
} |
1416 |
isUnicode = false; |
1409 |
isUnicode = false; |
Lines 1436-1442
Link Here
|
1436 |
int firstTag = 0; |
1429 |
int firstTag = 0; |
1437 |
while ((this.currentCharacter != '/') || (!star)) { |
1430 |
while ((this.currentCharacter != '/') || (!star)) { |
1438 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1431 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1439 |
if (this.currentLine != null) { |
1432 |
if (this.currentLine != null && this.currentLine.size() != 0) { |
1440 |
parseTags(false); |
1433 |
parseTags(false); |
1441 |
} |
1434 |
} |
1442 |
if (this.recordLineSeparator) { |
1435 |
if (this.recordLineSeparator) { |
Lines 1445-1452
Link Here
|
1445 |
} else { |
1438 |
} else { |
1446 |
pushLineSeparator(); |
1439 |
pushLineSeparator(); |
1447 |
} |
1440 |
} |
1448 |
} else if (this.currentLine != null) { |
|
|
1449 |
this.currentLine.clear(); |
1450 |
} |
1441 |
} |
1451 |
} |
1442 |
} |
1452 |
switch (this.currentCharacter) { |
1443 |
switch (this.currentCharacter) { |
Lines 1638-1644
Link Here
|
1638 |
} else { |
1629 |
} else { |
1639 |
if (this.recordLineSeparator |
1630 |
if (this.recordLineSeparator |
1640 |
&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) { |
1631 |
&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) { |
1641 |
if (this.currentLine != null) { |
1632 |
if (this.currentLine != null && this.currentLine.size() != 0) { |
1642 |
parseTags(false); |
1633 |
parseTags(false); |
1643 |
} |
1634 |
} |
1644 |
pushLineSeparator(); |
1635 |
pushLineSeparator(); |
Lines 1863-1869
Link Here
|
1863 |
star = true; |
1854 |
star = true; |
1864 |
} |
1855 |
} |
1865 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1856 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1866 |
if (this.currentLine != null) { |
1857 |
if (this.currentLine != null && this.currentLine.size() != 0) { |
1867 |
parseTags(false); |
1858 |
parseTags(false); |
1868 |
} |
1859 |
} |
1869 |
if (this.recordLineSeparator) { |
1860 |
if (this.recordLineSeparator) { |
Lines 1872-1879
Link Here
|
1872 |
} else { |
1863 |
} else { |
1873 |
pushLineSeparator(); |
1864 |
pushLineSeparator(); |
1874 |
} |
1865 |
} |
1875 |
} else if (this.currentLine != null) { |
|
|
1876 |
this.currentLine.clear(); |
1877 |
} |
1866 |
} |
1878 |
} |
1867 |
} |
1879 |
isUnicode = false; |
1868 |
isUnicode = false; |
Lines 1898-1904
Link Here
|
1898 |
int firstTag = 0; |
1887 |
int firstTag = 0; |
1899 |
while ((this.currentCharacter != '/') || (!star)) { |
1888 |
while ((this.currentCharacter != '/') || (!star)) { |
1900 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1889 |
if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) { |
1901 |
if (this.currentLine != null) { |
1890 |
if (this.currentLine != null && this.currentLine.size() != 0) { |
1902 |
parseTags(false); |
1891 |
parseTags(false); |
1903 |
} |
1892 |
} |
1904 |
if (this.recordLineSeparator) { |
1893 |
if (this.recordLineSeparator) { |
Lines 1907-1914
Link Here
|
1907 |
} else { |
1896 |
} else { |
1908 |
pushLineSeparator(); |
1897 |
pushLineSeparator(); |
1909 |
} |
1898 |
} |
1910 |
} else if (this.currentLine != null) { |
|
|
1911 |
this.currentLine.clear(); |
1912 |
} |
1899 |
} |
1913 |
} |
1900 |
} |
1914 |
switch (this.currentCharacter) { |
1901 |
switch (this.currentCharacter) { |
Lines 2257-2302
Link Here
|
2257 |
} |
2244 |
} |
2258 |
|
2245 |
|
2259 |
protected void parseTags(boolean hasLineComment) { |
2246 |
protected void parseTags(boolean hasLineComment) { |
2260 |
final NLSLine line = this.currentLine; |
|
|
2261 |
if (!hasLineComment) { |
2247 |
if (!hasLineComment) { |
2262 |
if (line.size() == 0) return; // nothing to do |
|
|
2263 |
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet(); |
2248 |
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet(); |
2264 |
this.nonNLSStrings.addAll(line.elements); |
2249 |
this.nonNLSStrings.addAll(this.currentLine.elements); |
2265 |
} else { |
2250 |
} else { |
2266 |
char[] s = getCurrentTokenSource(); |
2251 |
int position = 0; |
2267 |
int pos = CharOperation.indexOf(TAG_PREFIX, s, true); |
2252 |
if (this.linePtr >= 0) { |
|
|
2253 |
position = this.lineEnds[this.linePtr] + 1; |
2254 |
} |
2255 |
while (Character.isWhitespace(this.source[position])) { |
2256 |
position++; |
2257 |
} |
2258 |
if (getCurrentTokenStartPosition() == position) { |
2259 |
// the whole line is commented out |
2260 |
return; |
2261 |
} |
2262 |
final NLSLine line = this.currentLine; |
2263 |
char[] s = null; |
2264 |
int sourceEnd = this.currentPosition; |
2265 |
int sourceStart = this.startPosition; |
2266 |
int sourceDelta = 0; |
2267 |
if (this.withoutUnicodePtr != 0) { |
2268 |
// 0 is used as a fast test flag so the real first char is in position 1 |
2269 |
System.arraycopy( |
2270 |
this.withoutUnicodeBuffer, |
2271 |
1, |
2272 |
s = new char[this.withoutUnicodePtr], |
2273 |
0, |
2274 |
this.withoutUnicodePtr); |
2275 |
sourceEnd = this.withoutUnicodePtr; |
2276 |
sourceStart = 1; |
2277 |
sourceDelta = this.getCurrentTokenStartPosition(); |
2278 |
} else { |
2279 |
s = this.source; |
2280 |
} |
2281 |
int pos = CharOperation.indexOf(TAG_PREFIX, s, true, sourceStart, sourceEnd); |
2282 |
final int lineSize = line.size(); |
2268 |
if (pos != -1) { |
2283 |
if (pos != -1) { |
2269 |
if (this.unnecessaryNONNLSTags == null) this.unnecessaryNONNLSTags = new HashSet(); |
2284 |
if (this.unnecessaryNLSTags == null) this.unnecessaryNLSTags = new HashSet(); |
2270 |
while (pos != -1) { |
2285 |
while (pos != -1) { |
2271 |
int start = pos + TAG_PREFIX_LENGTH; |
2286 |
int start = pos + TAG_PREFIX_LENGTH; |
2272 |
int end = CharOperation.indexOf(TAG_POSTFIX, s, start); |
2287 |
int end = CharOperation.indexOf(TAG_POSTFIX, s, start, sourceEnd); |
2273 |
if (end != -1) { |
2288 |
if (end != -1) { |
2274 |
String index = new String(CharOperation.subarray(s, start, end)); |
2289 |
String index = new String(CharOperation.subarray(s, start, end)); |
2275 |
int i = 0; |
|
|
2276 |
try { |
2290 |
try { |
2277 |
i = Integer.parseInt(index) - 1; // Tags are one based not zero based. |
2291 |
final int i = Integer.parseInt(index) - 1; // Tags are one based not zero based. |
2278 |
} catch (NumberFormatException e) { |
2292 |
if (i >= 0 && i < lineSize) { |
2279 |
i = -1; // we don't want to consider this as a valid NLS tag |
2293 |
if (line.get(i) == null) { |
2280 |
} |
2294 |
this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta)); |
2281 |
if (line != null && line.exists(i)) { |
2295 |
} else { |
2282 |
line.set(i, null); |
2296 |
line.set(i, null); |
2283 |
final NLSTag tag = new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end, NLSTag.USED); |
2297 |
final NLSTag tag = new NLSTag(pos + sourceDelta , end + sourceDelta, NLSTag.USED); |
2284 |
if (!this.unnecessaryNONNLSTags.add(tag)) { |
2298 |
if (!this.unnecessaryNLSTags.add(tag)) { |
2285 |
this.unnecessaryNONNLSTags.remove(tag); |
2299 |
this.unnecessaryNLSTags.remove(tag); |
2286 |
this.unnecessaryNONNLSTags.add(tag); |
2300 |
this.unnecessaryNLSTags.add(tag); |
|
|
2301 |
} |
2302 |
} |
2303 |
} else { |
2304 |
this.unnecessaryNLSTags.add(new NLSTag(pos + sourceDelta, end + sourceDelta)); |
2287 |
} |
2305 |
} |
2288 |
} else { |
2306 |
} catch (NumberFormatException e) { |
2289 |
this.unnecessaryNONNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end)); |
2307 |
this.unnecessaryNLSTags.add(new NLSTag(pos + this.getCurrentTokenStartPosition(), this.getCurrentTokenStartPosition() + end)); |
2290 |
} |
2308 |
} |
2291 |
} |
2309 |
} |
2292 |
pos = CharOperation.indexOf(TAG_PREFIX, s, true, start); |
2310 |
pos = CharOperation.indexOf(TAG_PREFIX, s, true, start); |
2293 |
} |
2311 |
} |
2294 |
} |
2312 |
} |
2295 |
|
2313 |
|
2296 |
if (line.size() != 0) { |
2314 |
if (line.remainingElementsSize != 0) { |
2297 |
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet(); |
2315 |
if (this.nonNLSStrings == null) this.nonNLSStrings = new HashSet(); |
2298 |
for (Iterator iterator = line.iterator(); iterator.hasNext(); ) { |
2316 |
for (Iterator iterator = line.iterator(); iterator.hasNext(); ) { |
2299 |
StringLiteral literal = (StringLiteral) iterator.next(); |
2317 |
final StringLiteral literal = (StringLiteral) iterator.next(); |
2300 |
if (literal != null) { |
2318 |
if (literal != null) { |
2301 |
this.nonNLSStrings.add(literal); |
2319 |
this.nonNLSStrings.add(literal); |
2302 |
} |
2320 |
} |
Lines 2309-2321
Link Here
|
2309 |
public final void pushLineSeparator() { |
2327 |
public final void pushLineSeparator() { |
2310 |
//see comment on isLineDelimiter(char) for the use of '\n' and '\r' |
2328 |
//see comment on isLineDelimiter(char) for the use of '\n' and '\r' |
2311 |
final int INCREMENT = 250; |
2329 |
final int INCREMENT = 250; |
2312 |
|
|
|
2313 |
if (this.currentLine != null) { |
2314 |
// reinitialize the current line for non externalize strings purpose |
2315 |
this.currentLine.clear(); |
2316 |
} |
2317 |
//currentCharacter is at position currentPosition-1 |
2330 |
//currentCharacter is at position currentPosition-1 |
2318 |
|
|
|
2319 |
// cr 000D |
2331 |
// cr 000D |
2320 |
if (this.currentCharacter == '\r') { |
2332 |
if (this.currentCharacter == '\r') { |
2321 |
int separatorPos = this.currentPosition - 1; |
2333 |
int separatorPos = this.currentPosition - 1; |
Lines 2356-2366
Link Here
|
2356 |
} |
2368 |
} |
2357 |
} |
2369 |
} |
2358 |
public final void pushUnicodeLineSeparator() { |
2370 |
public final void pushUnicodeLineSeparator() { |
2359 |
if (this.currentLine != null) { |
|
|
2360 |
// reinitialize the current line for non externalize strings purpose |
2361 |
this.currentLine.clear(); |
2362 |
} |
2363 |
|
2364 |
// cr 000D |
2371 |
// cr 000D |
2365 |
if (this.currentCharacter == '\r') { |
2372 |
if (this.currentCharacter == '\r') { |
2366 |
if (this.source[this.currentPosition] == '\n') { |
2373 |
if (this.source[this.currentPosition] == '\n') { |