Author: j16sdiz
Date: 2008-12-30 03:27:48 +0000 (Tue, 30 Dec 2008)
New Revision: 24838

Modified:
   trunk/freenet/src/freenet/support/HTMLNode.java
Log:
faster namePattern check by short-cutting

Modified: trunk/freenet/src/freenet/support/HTMLNode.java
===================================================================
--- trunk/freenet/src/freenet/support/HTMLNode.java     2008-12-30 02:49:33 UTC 
(rev 24837)
+++ trunk/freenet/src/freenet/support/HTMLNode.java     2008-12-30 03:27:48 UTC 
(rev 24838)
@@ -12,6 +12,7 @@
 public class HTMLNode implements XMLCharacterClasses {
        
        private static final Pattern namePattern = Pattern.compile("^[" + NAME 
+ "]*$");
+       private static final Pattern simpleNamePattern = 
Pattern.compile("^[A-Za-z][A-Za-z0-9]*$");
 
        protected final String name;
 
@@ -41,8 +42,12 @@
                this(name, attributeNames, attributeValues, null);
        }
 
+       protected boolean checkNamePattern(String str) {                
+               return simpleNamePattern.matcher(str).matches() || 
namePattern.matcher(str).matches();
+       }
+       
        public HTMLNode(String name, String[] attributeNames, String[] 
attributeValues, String content) {
-               if ((name == null) || (!"#".equals(name) && !"%".equals(name) 
&& !namePattern.matcher(name).matches())) {
+               if ((name == null) || (!"#".equals(name) && !"%".equals(name) 
&& !checkNamePattern(name))) {
                        throw new IllegalArgumentException("element name is not 
legal");
                }
                if ((attributeNames != null) && (attributeValues != null)) {
@@ -50,7 +55,7 @@
                                throw new IllegalArgumentException("attribute 
names and values differ in length");
                        }
                        for (int attributeIndex = 0, attributeCount = 
attributeNames.length; attributeIndex < attributeCount; attributeIndex++) {
-                               if ((attributeNames[attributeIndex] == null) || 
!namePattern.matcher(attributeNames[attributeIndex]).matches()) {
+                               if ((attributeNames[attributeIndex] == null) || 
!checkNamePattern(attributeNames[attributeIndex])) {
                                        throw new 
IllegalArgumentException("attributeName is not legal");
                                }
                                addAttribute(attributeNames[attributeIndex], 
attributeValues[attributeIndex]);

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to