392 |
|
|
393 |
StringBuffer buf = new StringBuffer(); |
StringBuffer buf = new StringBuffer(); |
394 |
char[] textAsChars = text.toCharArray(); |
char[] textAsChars = text.toCharArray(); |
395 |
|
|
396 |
|
outer_loop: |
397 |
for (int i=0, ilim=textAsChars.length+1; i<ilim; ++i) { |
for (int i=0, ilim=textAsChars.length+1; i<ilim; ++i) { |
398 |
int c; |
int c; |
399 |
|
|
460 |
state = STATE_INITIAL; |
state = STATE_INITIAL; |
461 |
continue; |
continue; |
462 |
} |
} |
463 |
|
else { |
464 |
|
// peek forward and see whether this is a valid entity. |
465 |
|
if ('#'==c) { |
466 |
|
buf.append("&"); |
467 |
|
buf.append((char)c); |
468 |
|
state = STATE_INITIAL; |
469 |
|
continue outer_loop; |
470 |
|
} |
471 |
|
else if (Character.isLetter((char)c)) { |
472 |
|
for (int i2=i+1; i2<ilim-1; i2++) { |
473 |
|
if (';' == textAsChars[i2]) { |
474 |
|
buf.append("&"); |
475 |
|
buf.append((char)c); |
476 |
|
state = STATE_INITIAL; |
477 |
|
continue outer_loop; |
478 |
|
} |
479 |
|
else if (!Character.isLetter((char)c) |
480 |
|
&& !Character.isDigit((char)c) |
481 |
|
&& ".-_:".indexOf((char)c) < 0 |
482 |
|
//&& !isCombiningChar(c) // FIXME |
483 |
|
//&& !isExtender(c) // FIXME |
484 |
|
) { |
485 |
|
break; |
486 |
|
} |
487 |
|
} |
488 |
|
// not a valid entity declaration; assume & |
489 |
|
} |
490 |
|
buf.append("&"); |
491 |
|
buf.append((char)c); |
492 |
|
state = STATE_INITIAL; |
493 |
|
} |
494 |
|
|
495 |
|
/* |
496 |
else if ('#'==c || Character.isLetter((char)c)) { |
else if ('#'==c || Character.isLetter((char)c)) { |
497 |
buf.append("&"); |
buf.append("&"); |
498 |
buf.append((char)c); |
buf.append((char)c); |
503 |
buf.append((char)c); |
buf.append((char)c); |
504 |
state = STATE_INITIAL; |
state = STATE_INITIAL; |
505 |
} |
} |
506 |
|
*/ |
507 |
break; |
break; |
508 |
|
|
509 |
case STATE_TAG_START: |
case STATE_TAG_START: |