- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 23 Aug 2012 15:10:58 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css1 In directory hutz:/tmp/cvs-serv23761 Modified Files: CssFont.java CssFontSize.java CssFontWeight.java Log Message: case sensitivity of idents Index: CssFontSize.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssFontSize.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- CssFontSize.java 4 Aug 2012 21:17:05 -0000 1.5 +++ CssFontSize.java 23 Aug 2012 15:10:56 -0000 1.6 @@ -15,26 +15,37 @@ import org.w3c.css.values.CssTypes; import org.w3c.css.values.CssValue; -import java.util.HashMap; +import java.util.Arrays; /** * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#font-size */ public class CssFontSize extends org.w3c.css.properties.css.CssFontSize { - public static final HashMap<String,CssIdent> allowed_values; + public static final CssIdent[] allowed_values; static final String[] absolute_values = {"xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"}; static final String[] relative_values = {"smaller", "larger"}; static { - allowed_values = new HashMap<String, CssIdent>(); + allowed_values = new CssIdent[absolute_values.length + relative_values.length]; + int i = 0; for (String s : absolute_values) { - allowed_values.put(s, CssIdent.getIdent(s)); + allowed_values[i++] = CssIdent.getIdent(s); } for (String s : relative_values) { - allowed_values.put(s, CssIdent.getIdent(s)); + allowed_values[i++] = CssIdent.getIdent(s); } + Arrays.sort(allowed_values); } + + public static CssIdent getAllowedValue(CssIdent ident) { + int idx = Arrays.binarySearch(allowed_values, ident); + if (idx >= 0) { + return allowed_values[idx]; + } + return null; + } + /** * Create a new CssFontSize */ @@ -63,7 +74,7 @@ switch (val.getType()) { case CssTypes.CSS_NUMBER: - val = ((CssNumber)val).getLength(); + val = ((CssNumber) val).getLength(); case CssTypes.CSS_LENGTH: CssLength l = (CssLength) val; if (!l.isPositive()) { @@ -81,7 +92,7 @@ value = p; break; case CssTypes.CSS_IDENT: - value = allowed_values.get(val.toString()); + value = getAllowedValue((CssIdent) val); if (value == null) { throw new InvalidParamException("value", expression.getValue().toString(), Index: CssFontWeight.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssFontWeight.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CssFontWeight.java 4 Aug 2012 21:17:05 -0000 1.7 +++ CssFontWeight.java 23 Aug 2012 15:10:56 -0000 1.8 @@ -13,37 +13,45 @@ import org.w3c.css.values.CssTypes; import org.w3c.css.values.CssValue; -import java.util.HashMap; - /** * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#font-weight */ public class CssFontWeight extends org.w3c.css.properties.css.CssFontWeight { - public static final HashMap<String,CssIdent> allowed_values; + public static final CssIdent[] allowed_values; static final String[] _allowed_values = {"normal", "bold", "bolder", "lighter"}; static { - allowed_values = new HashMap<String, CssIdent>(_allowed_values.length); - for (String s : _allowed_values) { - allowed_values.put(s, CssIdent.getIdent(s)); + allowed_values = new CssIdent[_allowed_values.length]; + for (int i = 0; i < allowed_values.length; i++) { + allowed_values[i] = CssIdent.getIdent(_allowed_values[i]); } } - /** - * Create a new CssFontWeight - */ - public CssFontWeight() { - } - /** - * Creates a new CssFontWeight - * - * @param expression The expression for this property - * @throws org.w3c.css.util.InvalidParamException - * Expressions are incorrect - */ - public CssFontWeight(ApplContext ac, CssExpression expression, boolean check) - throws InvalidParamException { + public static final CssIdent getAllowedValue(CssIdent ident) { + for (CssIdent id : allowed_values) { + if (id.equals(ident)) { + return id; + } + } + return null; + } + + /** + * Create a new CssFontWeight + */ + public CssFontWeight() { + } + + /** + * Creates a new CssFontWeight + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * Expressions are incorrect + */ + public CssFontWeight(ApplContext ac, CssExpression expression, boolean check) + throws InvalidParamException { if (check && expression.getCount() > 1) { throw new InvalidParamException("unrecognize", ac); } @@ -58,7 +66,7 @@ switch (val.getType()) { case CssTypes.CSS_NUMBER: CssNumber num = (CssNumber) val; - switch(num.getInt()) { + switch (num.getInt()) { case 100: case 200: case 300: @@ -68,7 +76,7 @@ case 700: case 800: case 900: - value = num; + value = num; break; default: throw new InvalidParamException("value", @@ -77,7 +85,7 @@ } break; case CssTypes.CSS_IDENT: - value = allowed_values.get(val.toString()); + value = getAllowedValue((CssIdent) val); if (value == null) { throw new InvalidParamException("value", val.toString(), @@ -90,12 +98,12 @@ getPropertyName(), ac); } expression.next(); - } + } - public CssFontWeight(ApplContext ac, CssExpression expression) - throws InvalidParamException { - this(ac, expression, false); - } + public CssFontWeight(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } } Index: CssFont.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssFont.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- CssFont.java 5 Aug 2012 06:22:55 -0000 1.9 +++ CssFont.java 23 Aug 2012 15:10:56 -0000 1.10 @@ -12,7 +12,7 @@ import org.w3c.css.values.CssTypes; import org.w3c.css.values.CssValue; -import java.util.HashMap; +import java.util.Arrays; import static org.w3c.css.values.CssOperator.SPACE; @@ -22,16 +22,26 @@ public class CssFont extends org.w3c.css.properties.css.CssFont { public static final CssIdent normal; - public static final HashMap<String, CssIdent> systemFonts; + public static final CssIdent[] systemFonts; static final String[] _systemFonts = {"caption", "icon", "menu", "message-box", "small-caption", "status-bar"}; static { normal = CssIdent.getIdent("normal"); - systemFonts = new HashMap<String, CssIdent>(); + systemFonts = new CssIdent[_systemFonts.length]; + int i = 0; for (String s : _systemFonts) { - systemFonts.put(s, CssIdent.getIdent(s)); + systemFonts[i++] = CssIdent.getIdent(s); + } + Arrays.sort(systemFonts); + } + + public static final CssIdent getSystemFont(CssIdent ident) { + int idx = Arrays.binarySearch(systemFonts, ident); + if (idx >= 0) { + return systemFonts[idx]; } + return null; } /** @@ -73,7 +83,7 @@ break; } CssIdent ident; - ident = systemFonts.get(val.toString()); + ident = getSystemFont((CssIdent) val); if (ident != null) { if (expression.getCount() != 1) { throw new InvalidParamException("value", @@ -119,7 +129,7 @@ break; } // font-weight - v = CssFontWeight.allowed_values.get(ident.toString()); + v = CssFontWeight.getAllowedValue(ident); if (v != null) { if (fontWeight != null) { throw new InvalidParamException("value", @@ -135,7 +145,7 @@ // check if we moved past and we now got // a font-size if (state == 0) { - CssIdent v = CssFontSize.allowed_values.get(ident.toString()); + CssIdent v = CssFontSize.getAllowedValue(ident); if (v != null) { // we got a FontSize, so no more style/variant/weight state = 1;
Received on Thursday, 23 August 2012 15:11:11 UTC