@@ -1129,17 +1129,6 @@ else if (ch1 == '/' && str.charAt(0) == '/') {
11291129 return str ;
11301130 }
11311131
1132- // Modifies the given name based on the specified mode.
1133- protected static String modifyName (final String name , final short mode ) {
1134- if (NAMES_UPPERCASE == mode ) {
1135- return name .toUpperCase (Locale .ROOT );
1136- }
1137- if (NAMES_LOWERCASE == mode ) {
1138- return name .toLowerCase (Locale .ROOT );
1139- }
1140- return name ;
1141- }
1142-
11431132 // Converts HTML names string value to constant value.
11441133 //
11451134 // @see #NAMES_NO_CHANGE
@@ -1202,15 +1191,12 @@ protected void scanDoctype() throws IOException {
12021191 String sysid = null ;
12031192
12041193 if (fCurrentEntity .skipSpaces ()) {
1205- root = scanName (true );
1194+ root = scanName (true , fNamesElems );
12061195 if (root == null ) {
12071196 if (fReportErrors_ ) {
12081197 fErrorReporter .reportError ("HTML1014" , null );
12091198 }
12101199 }
1211- else {
1212- root = modifyName (root , fNamesElems );
1213- }
12141200 if (fCurrentEntity .skipSpaces ()) {
12151201 if (fCurrentEntity .skip ("PUBLIC" )) {
12161202 fCurrentEntity .skipSpaces ();
@@ -1290,7 +1276,7 @@ else if (c == '<') {
12901276 }
12911277
12921278 // Scan a name.
1293- protected String scanName (final boolean strict ) throws IOException {
1279+ protected String scanName (final boolean strict , final short mode ) throws IOException {
12941280 if (DEBUG_BUFFER ) {
12951281 fCurrentEntity .debugBufferIfNeeded ("(scanName: " );
12961282 }
@@ -1306,6 +1292,7 @@ protected String scanName(final boolean strict) throws IOException {
13061292 while (true ) {
13071293 while (fCurrentEntity .hasNext ()) {
13081294 final char c = fCurrentEntity .getNextChar ();
1295+
13091296 // this has been split up to cater to the needs of branch prediction
13101297 if (strict && (!Character .isLetterOrDigit (c ) && c != '-' && c != '.' && c != ':' && c != '_' )) {
13111298 fCurrentEntity .rewind ();
@@ -1323,6 +1310,16 @@ else if (!strict
13231310 fCurrentEntity .rewind ();
13241311 break ;
13251312 }
1313+
1314+ if (NAMES_NO_CHANGE == mode ) {
1315+ // nothing to do
1316+ }
1317+ else if (NAMES_UPPERCASE == mode && !Character .isUpperCase (c )) {
1318+ fCurrentEntity .buffer_ [fCurrentEntity .offset_ - 1 ] = Character .toUpperCase (c );
1319+ }
1320+ else if (NAMES_LOWERCASE == mode && !Character .isLowerCase (c )) {
1321+ fCurrentEntity .buffer_ [fCurrentEntity .offset_ - 1 ] = Character .toLowerCase (c );
1322+ }
13261323 }
13271324 if (fCurrentEntity .offset_ == fCurrentEntity .length_ ) {
13281325 final int length = fCurrentEntity .length_ - offset ;
@@ -1381,7 +1378,18 @@ protected String scanTagName() throws IOException {
13811378 break ;
13821379 }
13831380 }
1381+
1382+ if (NAMES_NO_CHANGE == fNamesElems ) {
1383+ // nothing to do
1384+ }
1385+ else if (NAMES_UPPERCASE == fNamesElems && !Character .isUpperCase (c )) {
1386+ fCurrentEntity .buffer_ [fCurrentEntity .offset_ - 1 ] = Character .toUpperCase (c );
1387+ }
1388+ else if (NAMES_LOWERCASE == fNamesElems && !Character .isLowerCase (c )) {
1389+ fCurrentEntity .buffer_ [fCurrentEntity .offset_ - 1 ] = Character .toLowerCase (c );
1390+ }
13841391 }
1392+
13851393 if (fCurrentEntity .offset_ == fCurrentEntity .length_ ) {
13861394 final int length = fCurrentEntity .length_ - offset ;
13871395 System .arraycopy (fCurrentEntity .buffer_ , offset , fCurrentEntity .buffer_ , 0 , length );
@@ -2311,7 +2319,7 @@ else if (ename != null) {
23112319 }
23122320 if (fInsertDoctype_ ) {
23132321 fDocumentHandler .doctypeDecl (
2314- modifyName ( "HTML" , fNamesElems ) ,
2322+ NAMES_LOWERCASE == fNamesElems ? "html" : "HTML" ,
23152323 fDoctypePubid ,
23162324 fDoctypeSysid ,
23172325 synthesizedAugs ());
@@ -2690,7 +2698,7 @@ protected void scanPI() throws IOException {
26902698 }
26912699
26922700 // scan processing instruction
2693- final String target = scanName (true );
2701+ final String target = scanName (true , fNamesElems );
26942702 if (target != null && !"xml" .equalsIgnoreCase (target )) {
26952703 while (true ) {
26962704 int c = fCurrentEntity .read ();
@@ -2814,7 +2822,7 @@ else if (c == '>') {
28142822 * @throws IOException in case of io problems
28152823 */
28162824 protected String scanStartElement (final boolean [] empty ) throws IOException {
2817- String ename = scanTagName ();
2825+ final String ename = scanTagName ();
28182826 final int length = ename != null ? ename .length () : 0 ;
28192827 if (length == 0 ) {
28202828 if (fReportErrors_ ) {
@@ -2826,7 +2834,6 @@ protected String scanStartElement(final boolean[] empty) throws IOException {
28262834 }
28272835 return null ;
28282836 }
2829- ename = modifyName (ename , fNamesElems );
28302837 if (attributes_ .getLength () != 0 ) {
28312838 attributes_ .removeAllAttributes ();
28322839 }
@@ -3042,7 +3049,7 @@ protected boolean scanAttribute(final XMLAttributesImpl attributes, final boolea
30423049 }
30433050
30443051 fCurrentEntity .rewind ();
3045- String aname = scanName (false );
3052+ String aname = scanName (false , fNamesAttrs );
30463053 if (aname == null ) {
30473054 if (fReportErrors_ ) {
30483055 fErrorReporter .reportError ("HTML1011" , null );
@@ -3055,7 +3062,7 @@ protected boolean scanAttribute(final XMLAttributesImpl attributes, final boolea
30553062 empty [0 ] = fCurrentEntity .skipMarkup (false );
30563063 return false ;
30573064 }
3058- aname = '=' + scanName (false );
3065+ aname = '=' + scanName (false , fNamesElems );
30593066 }
30603067 if (fReportErrors_ && !skippedSpaces ) {
30613068 fErrorReporter .reportError ("HTML1013" , new Object [] {aname });
@@ -3068,7 +3075,6 @@ protected boolean scanAttribute(final XMLAttributesImpl attributes, final boolea
30683075 }
30693076 throw new EOFException ();
30703077 }
3071- aname = modifyName (aname , fNamesAttrs );
30723078 if (c == '/' ) {
30733079 qName_ .setValues (null , aname , aname , null );
30743080 attributes .addAttribute (qName_ , "CDATA" , "" , true );
@@ -3293,14 +3299,13 @@ else if (c != currentQuote) {
32933299
32943300 // Scans an end element.
32953301 protected void scanEndElement () throws IOException {
3296- String ename = scanTagName ();
3302+ final String ename = scanTagName ();
32973303 if (fReportErrors_ && ename == null ) {
32983304 fErrorReporter .reportError ("HTML1012" , null );
32993305 }
33003306 fCurrentEntity .skipMarkup (false );
33013307 if (ename != null ) {
33023308 if (fElementCount >= fElementDepth ) {
3303- ename = modifyName (ename , fNamesElems );
33043309 qName_ .setValues (null , ename , ename , null );
33053310 if (DEBUG_CALLBACKS ) {
33063311 System .out .println ("endElement(" + qName_ + ")" );
@@ -3385,14 +3390,13 @@ public boolean scan(final boolean complete) throws IOException {
33853390 case STATE_MARKUP_BRACKET : {
33863391 final int c = fCurrentEntity .read ();
33873392 if (c == '/' ) {
3388- String ename = scanName (true );
3393+ final String ename = scanName (true , fNamesElems );
33893394 if (ename != null ) {
33903395 fCurrentEntity .skipSpaces ();
33913396
33923397 if (ename .equalsIgnoreCase (fElementName )) {
33933398 if (fCurrentEntity .read () == '>' ) {
33943399 if (fElementCount >= fElementDepth ) {
3395- ename = modifyName (ename , fNamesElems );
33963400 fQName_ .setValues (null , ename , ename , null );
33973401 if (DEBUG_CALLBACKS ) {
33983402 System .out .println ("endElement(" + fQName_ + ")" );
0 commit comments