Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ylafon committed Feb 11, 2019
1 parent 9008dbc commit c2ce225
Showing 1 changed file with 32 additions and 58 deletions.
90 changes: 32 additions & 58 deletions org/w3c/css/properties/css3/CssOverflowWrap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Author: Yves Lafon <ylafon@w3.org>
//
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
// (c) COPYRIGHT MIT, ERCIM and Keio University, Beihang, 2012.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css3;

Expand All @@ -11,25 +11,32 @@
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;
import org.w3c.css.values.CssValueList;

import java.util.ArrayList;

import static org.w3c.css.values.CssOperator.SPACE;

/**
* @spec hhttps://www.w3.org/TR/2017/WD-css-text-3-20170822/#overflow-wrap-property
* @spec https://www.w3.org/TR/2018/WD-css-text-3-20181212/#propdef-overflow-wrap
* <p/>
* Note that word-wrap is also an alias for this.
*/
public class CssOverflowWrap extends org.w3c.css.properties.css.CssOverflowWrap {

public static final CssIdent normal, break_word, break_spaces;
public static final CssIdent[] allowed_values;

static {
normal = CssIdent.getIdent("normal");
break_word = CssIdent.getIdent("break-word");
break_spaces = CssIdent.getIdent("break-spaces");
String[] _allowed_values = {"normal", "break-word", "anywhere"};
allowed_values = new CssIdent[_allowed_values.length];
int i = 0;
for (String s : _allowed_values) {
allowed_values[i++] = CssIdent.getIdent(s);
}
}

public static final CssIdent getAllowedValue(CssIdent ident) {
for (CssIdent id : allowed_values) {
if (id.equals(ident)) {
return id;
}
}
return null;
}

/**
Expand All @@ -56,60 +63,27 @@ public CssOverflowWrap(ApplContext ac, CssExpression expression, boolean check)
CssValue val;
char op;

ArrayList<CssValue> values = new ArrayList<>();
boolean gotNormal = false;
boolean gotBw = false;
boolean gotBs = false;

while (!expression.end()) {
val = expression.getValue();
op = expression.getOperator();
val = expression.getValue();
op = expression.getOperator();

if (val.getType() == CssTypes.CSS_IDENT) {
CssIdent ident = (CssIdent) val;
if (inherit.equals(ident)) {
if (expression.getCount() > 1) {
throw new InvalidParamException("unrecognize", ac);
}
value = inherit;
} else if (normal.equals(ident)) {
if (gotNormal || gotBw || gotBs) {
throw new InvalidParamException("unrecognize", ac);
}
value = normal;
gotNormal = true;
} else if (break_word.equals(ident)) {
if (gotNormal || gotBw) {
throw new InvalidParamException("unrecognize", ac);
}
values.add(break_word);
gotBw = true;
} else if (break_spaces.equals(ident)) {
if (gotNormal || gotBs) {
throw new InvalidParamException("unrecognize", ac);
}
values.add(break_spaces);
gotBs = true;
} else {
if (val.getType() == CssTypes.CSS_IDENT) {
CssIdent ident = (CssIdent) val;
if (inherit.equals(ident)) {
value = inherit;
} else {
value = getAllowedValue(ident);
if (value == null) {
throw new InvalidParamException("value",
val.toString(),
getPropertyName(), ac);
}
} else {
throw new InvalidParamException("value",
val.toString(),
getPropertyName(), ac);
}
if (op != SPACE) {
throw new InvalidParamException("operator",
((new Character(op)).toString()),
ac);
}
expression.next();
}
if (values.size() > 0) {
value = values.size() == 1 ? values.get(0) : new CssValueList(values);
} else {
throw new InvalidParamException("value",
val.toString(),
getPropertyName(), ac);
}
expression.next();
}

public CssOverflowWrap(ApplContext ac, CssExpression expression)
Expand Down

0 comments on commit c2ce225

Please sign in to comment.