- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 21 Oct 2011 01:49:15 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/values In directory hutz:/tmp/cvs-serv28700/org/w3c/css/values Modified Files: CssExpression.java CssResolution.java Log Message: redone the Media Features of media queries, up to date per http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/, todo, parsing of media in HTML form Index: CssResolution.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssResolution.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CssResolution.java 14 Sep 2011 16:31:50 -0000 1.7 +++ CssResolution.java 21 Oct 2011 01:49:13 -0000 1.8 @@ -32,11 +32,25 @@ return type; } + private Float value; + private String unit; + boolean isInt; + /** * Create a new CssResolution */ public CssResolution() { - value = defaultValue; + } + + private void setValue(String s) { + try { + new Integer(s); + isInt = true; + } catch (NumberFormatException e) { + isInt = false; + } finally { + value = new Float(s); + } } /** @@ -47,19 +61,20 @@ * @throws InvalidParamException The unit is incorrect */ public void set(String s, ApplContext ac) throws InvalidParamException { + s = s.toLowerCase(); int length = s.length(); String unit = ""; if (s.contains("dpi")) { unit = s.substring(length - 3, length); - this.value = new Float(s.substring(0, length - 3)); + setValue(s.substring(0, length - 3)); if (unit.equals("dpi")) { this.unit = unit; } return; } else if (s.contains("dpcm")) { unit = s.substring(length - 4, length); - this.value = new Float(s.substring(0, length - 4)); + setValue(s.substring(0, length - 4)); if (unit.equals("dpcm")) { this.unit = unit; } @@ -77,10 +92,21 @@ * Returns the current value */ public Object get() { + if (isInt) { + return new Integer(value.intValue()); + } return value; } /** + * @return a float + * + */ + public float getFloatValue() { + return value.floatValue(); + } + + /** * @return the current value */ public String getUnit() { @@ -91,11 +117,14 @@ * Returns a string representation of the object. */ public String toString() { - if (value.floatValue() != 0.0) { - return Util.displayFloat(value) + unit; + StringBuilder sb = new StringBuilder(); + if (isInt) { + sb.append(Integer.toString(value.intValue())); } else { - return Util.displayFloat(value); + sb.append(Util.displayFloat(value)); } + sb.append(unit); + return sb.toString(); } /** @@ -108,10 +137,5 @@ this.value.equals(((CssResolution) value).value) && unit.equals(((CssResolution) value).unit)); } - - private Float value; - private String unit; - private static Float defaultValue = new Float(0); - } Index: CssExpression.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/CssExpression.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- CssExpression.java 9 Jan 2010 10:36:47 -0000 1.10 +++ CssExpression.java 21 Oct 2011 01:49:13 -0000 1.11 @@ -195,7 +195,8 @@ } // remove the last one if (sb.length() > 0) { - return sb.deleteCharAt(sb.length() - 1).toString(); +// sb.setLength(sb.length() - 1); + return sb.toString(); } else { return "**invalid state**"; }
Received on Friday, 21 October 2011 01:49:17 UTC