W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2012

2002/css-validator/org/w3c/css/properties/css3 CssLetterSpacing.java,1.1,1.2

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 04 Sep 2012 08:40:05 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1T8og1-0005Wh-0N@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css3
In directory hutz:/tmp/cvs-serv21157/css3

Modified Files:
	CssLetterSpacing.java 
Log Message:
use CssValueList (so, a real CssValue), bumped to latest draft http://www.w3.org/TR/2012/WD-css3-text-20120814/#letter-spacing0, discovered that the same grammar does not accept the same vales as word-spacing :/

Index: CssLetterSpacing.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css3/CssLetterSpacing.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssLetterSpacing.java	9 Feb 2012 17:36:32 -0000	1.1
+++ CssLetterSpacing.java	4 Sep 2012 08:40:02 -0000	1.2
@@ -4,7 +4,6 @@
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.properties.css3;
 
-import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
@@ -13,21 +12,22 @@
 import org.w3c.css.values.CssOperator;
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
+import org.w3c.css.values.CssValueList;
+
+import java.util.ArrayList;
 
 /**
  * @spec http://www.w3.org/TR/2011/WD-css3-text-20110901/#letter-spacing0
  */
 public class CssLetterSpacing extends org.w3c.css.properties.css.CssLetterSpacing {
 
-    private CssValue value[] = new CssValue[3];
-    int nb_values;
     private static CssIdent normal = CssIdent.getIdent("normal");
 
     /**
      * Create a new CssLetterSpacing.
      */
     public CssLetterSpacing() {
-        value[0] = normal;
+        value = initial;
     }
 
     /**
@@ -39,48 +39,51 @@
      */
     public CssLetterSpacing(ApplContext ac, CssExpression expression,
                             boolean check) throws InvalidParamException {
-        nb_values = expression.getCount();
-
-        if (check && nb_values > 3) {
-            throw new InvalidParamException("unrecognize", ac);
-        }
+		if (check && expression.getCount() > 3) {
+			throw new InvalidParamException("unrecognize", ac);
+		}
+		setByUser();
 
-        for (int i = 0; i < nb_values; i++) {
-            CssValue val = expression.getValue();
+		ArrayList<CssValue> v = new ArrayList<CssValue>(4);
+		CssValue val;
+		char op;
 
-            setByUser();
+		while (!expression.end()) {
+			val = expression.getValue();
+			op = expression.getOperator();
 
-            switch (val.getType()) {
-                case CssTypes.CSS_NUMBER:
-                    val = ((CssNumber) val).getLength();
-                case CssTypes.CSS_LENGTH:
-                    value[i] = val;
-                    break;
-                case CssTypes.CSS_PERCENTAGE:
-                    value[i] = val;
-                    break;
-                case CssTypes.CSS_IDENT:
-                    if (inherit.equals(val)) {
-                        // inherit can only be alone
-                        if (nb_values > 1) {
-                            throw new InvalidParamException("value", expression.getValue(),
-                                    getPropertyName(), ac);
-                        }
-                        value[i] = inherit;
-                        break;
-                    } else if (normal.equals(val)) {
-                        value[i] = normal;
-                        break;
-                    }
-                default:
-                    throw new InvalidParamException("value", expression.getValue(),
-                            getPropertyName(), ac);
-            }
-            if (i+1 < nb_values && expression.getOperator() != CssOperator.SPACE) {
-               throw new InvalidParamException("operator", CssOperator.SPACE, ac);
-            }
-            expression.next();
-        }
+			switch (val.getType()) {
+				case CssTypes.CSS_NUMBER:
+					val = ((CssNumber) val).getLength();
+				case CssTypes.CSS_LENGTH:
+					v.add(val);
+					break;
+				case CssTypes.CSS_IDENT:
+					if (inherit.equals(val)) {
+						// inherit can only be alone
+						if (expression.getCount() > 1) {
+							throw new InvalidParamException("value", expression.getValue(),
+									getPropertyName(), ac);
+						}
+						value = inherit;
+						break;
+					} else if (normal.equals(val)) {
+						v.add(normal);
+						break;
+					}
+				default:
+					throw new InvalidParamException("value", expression.getValue(),
+							getPropertyName(), ac);
+			}
+			if (op != CssOperator.SPACE) {
+				throw new InvalidParamException("operator",
+						((new Character(op)).toString()), ac);
+			}
+			expression.next();
+		}
+		if (value != inherit) {
+			value = (v.size() == 1) ? v.get(0) : new CssValueList(v);
+		}
     }
 
     public CssLetterSpacing(ApplContext ac, CssExpression expression)
@@ -88,45 +91,4 @@
         this(ac, expression, false);
     }
 
-    /**
-     * Returns the value of this property
-     */
-    public Object get() {
-        return value;
-    }
-
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-        return value[0] == inherit;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-        if (nb_values == 1) {
-            return value[0].toString();
-        }
-        StringBuilder sb = new StringBuilder();
-        for (int i=0; i < nb_values; i++) {
-            if (i > 0) {
-                sb.append(' ');
-            }
-            sb.append(value[i]);
-        }
-        return sb.toString();
-    }
-
-    /**
-     * Compares two properties for equality.
-     *
-     * @param property The other property.
-     */
-    public boolean equals(CssProperty property) {
-        return (property instanceof CssLetterSpacing &&
-                value.equals(((CssLetterSpacing) property).value));
-    }
 }
Received on Tuesday, 4 September 2012 08:40:15 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:51 UTC