Skip to content

Commit c2ce225

Browse files
committed
1 parent 9008dbc commit c2ce225

File tree

1 file changed

+32
-58
lines changed

1 file changed

+32
-58
lines changed

org/w3c/css/properties/css3/CssOverflowWrap.java

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Author: Yves Lafon <ylafon@w3.org>
33
//
4-
// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
4+
// (c) COPYRIGHT MIT, ERCIM and Keio University, Beihang, 2012.
55
// Please first read the full copyright statement in file COPYRIGHT.html
66
package org.w3c.css.properties.css3;
77

@@ -11,25 +11,32 @@
1111
import org.w3c.css.values.CssIdent;
1212
import org.w3c.css.values.CssTypes;
1313
import org.w3c.css.values.CssValue;
14-
import org.w3c.css.values.CssValueList;
15-
16-
import java.util.ArrayList;
17-
18-
import static org.w3c.css.values.CssOperator.SPACE;
1914

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

27-
public static final CssIdent normal, break_word, break_spaces;
22+
public static final CssIdent[] allowed_values;
2823

2924
static {
30-
normal = CssIdent.getIdent("normal");
31-
break_word = CssIdent.getIdent("break-word");
32-
break_spaces = CssIdent.getIdent("break-spaces");
25+
String[] _allowed_values = {"normal", "break-word", "anywhere"};
26+
allowed_values = new CssIdent[_allowed_values.length];
27+
int i = 0;
28+
for (String s : _allowed_values) {
29+
allowed_values[i++] = CssIdent.getIdent(s);
30+
}
31+
}
32+
33+
public static final CssIdent getAllowedValue(CssIdent ident) {
34+
for (CssIdent id : allowed_values) {
35+
if (id.equals(ident)) {
36+
return id;
37+
}
38+
}
39+
return null;
3340
}
3441

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

59-
ArrayList<CssValue> values = new ArrayList<>();
60-
boolean gotNormal = false;
61-
boolean gotBw = false;
62-
boolean gotBs = false;
63-
64-
while (!expression.end()) {
65-
val = expression.getValue();
66-
op = expression.getOperator();
66+
val = expression.getValue();
67+
op = expression.getOperator();
6768

68-
if (val.getType() == CssTypes.CSS_IDENT) {
69-
CssIdent ident = (CssIdent) val;
70-
if (inherit.equals(ident)) {
71-
if (expression.getCount() > 1) {
72-
throw new InvalidParamException("unrecognize", ac);
73-
}
74-
value = inherit;
75-
} else if (normal.equals(ident)) {
76-
if (gotNormal || gotBw || gotBs) {
77-
throw new InvalidParamException("unrecognize", ac);
78-
}
79-
value = normal;
80-
gotNormal = true;
81-
} else if (break_word.equals(ident)) {
82-
if (gotNormal || gotBw) {
83-
throw new InvalidParamException("unrecognize", ac);
84-
}
85-
values.add(break_word);
86-
gotBw = true;
87-
} else if (break_spaces.equals(ident)) {
88-
if (gotNormal || gotBs) {
89-
throw new InvalidParamException("unrecognize", ac);
90-
}
91-
values.add(break_spaces);
92-
gotBs = true;
93-
} else {
69+
if (val.getType() == CssTypes.CSS_IDENT) {
70+
CssIdent ident = (CssIdent) val;
71+
if (inherit.equals(ident)) {
72+
value = inherit;
73+
} else {
74+
value = getAllowedValue(ident);
75+
if (value == null) {
9476
throw new InvalidParamException("value",
9577
val.toString(),
9678
getPropertyName(), ac);
9779
}
98-
} else {
99-
throw new InvalidParamException("value",
100-
val.toString(),
101-
getPropertyName(), ac);
102-
}
103-
if (op != SPACE) {
104-
throw new InvalidParamException("operator",
105-
((new Character(op)).toString()),
106-
ac);
10780
}
108-
expression.next();
109-
}
110-
if (values.size() > 0) {
111-
value = values.size() == 1 ? values.get(0) : new CssValueList(values);
81+
} else {
82+
throw new InvalidParamException("value",
83+
val.toString(),
84+
getPropertyName(), ac);
11285
}
86+
expression.next();
11387
}
11488

11589
public CssOverflowWrap(ApplContext ac, CssExpression expression)

0 commit comments

Comments
 (0)