1
1
//
2
2
// Author: Yves Lafon <ylafon@w3.org>
3
3
//
4
- // (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
4
+ // (c) COPYRIGHT MIT, ERCIM and Keio University, Beihang, 2012.
5
5
// Please first read the full copyright statement in file COPYRIGHT.html
6
6
package org .w3c .css .properties .css3 ;
7
7
11
11
import org .w3c .css .values .CssIdent ;
12
12
import org .w3c .css .values .CssTypes ;
13
13
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 ;
19
14
20
15
/**
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
22
17
* <p/>
23
18
* Note that word-wrap is also an alias for this.
24
19
*/
25
20
public class CssOverflowWrap extends org .w3c .css .properties .css .CssOverflowWrap {
26
21
27
- public static final CssIdent normal , break_word , break_spaces ;
22
+ public static final CssIdent [] allowed_values ;
28
23
29
24
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 ;
33
40
}
34
41
35
42
/**
@@ -56,60 +63,27 @@ public CssOverflowWrap(ApplContext ac, CssExpression expression, boolean check)
56
63
CssValue val ;
57
64
char op ;
58
65
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 ();
67
68
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 ) {
94
76
throw new InvalidParamException ("value" ,
95
77
val .toString (),
96
78
getPropertyName (), ac );
97
79
}
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 );
107
80
}
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 );
112
85
}
86
+ expression .next ();
113
87
}
114
88
115
89
public CssOverflowWrap (ApplContext ac , CssExpression expression )
0 commit comments