@@ -56,10 +56,11 @@ import org.w3c.css.util.ApplContext;
56
56
import org.w3c.css.util.CssProfile;
57
57
import org.w3c.css.util.CssVersion;
58
58
import org.w3c.css.util.InvalidParamException;
59
+ import org.w3c.css.util.StringUtils;
59
60
import org.w3c.css.util.Util;
60
61
import org.w3c.css.util.WarningParamException;
61
- import org.w3c.css.values.CssAngle;
62
62
import org.w3c.css.values.CssANPlusB;
63
+ import org.w3c.css.values.CssAngle;
63
64
import org.w3c.css.values.CssAttr;
64
65
import org.w3c.css.values.CssBracket;
65
66
import org.w3c.css.values.CssCalc;
@@ -93,6 +94,8 @@ import org.w3c.css.values.CssValue;
93
94
import org.w3c.css.values.CssVariable;
94
95
import org.w3c.css.values.CssVolume;
95
96
97
+ import static org.w3c.css.util.StringUtils.convertIdent;
98
+
96
99
import java.io.InputStream;
97
100
import java.io.InputStreamReader;
98
101
import java.io.UnsupportedEncodingException;
@@ -528,6 +531,9 @@ SPECIAL_TOKEN :
528
531
{
529
532
< #H : ["0"-"9", "a"-"f"] >
530
533
| < #NONASCII : ["\u0080"-"\uFFFF"] >
534
+ | < #__U : "u" | ( "\\" ( "0" )? ( "0" )? ( "0" )? ( "0" )? ( "55" | "75" ) ( "\r\n" | [ " ", "\t" , "\n" , "\r", "\f" ] )? ) >
535
+ | < #__R : "r" | ( "\\" ( "0" )? ( "0" )? ( "0" )? ( "0" )? ( "52" | "72" ) ( "\r\n" | [ " ", "\t" , "\n" , "\r", "\f" ] )? ) >
536
+ | < #__L : "l" | ( "\\" ( "0" )? ( "0" )? ( "0" )? ( "0" )? ( "4c" | "6c" ) ( "\r\n" | [ " ", "\t" , "\n" , "\r", "\f" ] )? ) >
531
537
| < #UNICODE : "\\" <H> ( <H> )? ( <H> )? ( <H> )? ( <H> )? ( <H> )?
532
538
( "\r\n" | [ " ", "\t" , "\n" , "\r", "\f" ] )? >
533
539
| < #ESCAPE : <UNICODE> | ( "\\" ~[ "\r", "\n", "\f", "0"-"9", "a"-"f" ] ) >
@@ -546,6 +552,7 @@ SPECIAL_TOKEN :
546
552
| < #_S : ( [ " ", "\t" , "\n" , "\r", "\f" ] ) ( <COMMENT> | [ " ", "\t" , "\n" , "\r", "\f" ] )* >
547
553
| < #_W : ( <_S> )? >
548
554
| < #NL : ( "\n" | "\r\n" | "\r" | "\f" ) >
555
+ | < URLPREFIX : <__U> <__R> <__L> "(" >
549
556
}
550
557
/*
551
558
* The _S definition is not ( [ " ", "\t" , "\n" , "\r", "\f" ] ) + as we need to add support
@@ -638,7 +645,7 @@ TOKEN :
638
645
<DEFAULT>
639
646
TOKEN [IGNORE_CASE] :
640
647
{
641
- < URL : "url(" ( <S> )* ( <STRING> | <_URL> ) ( <S> )* <RPAREN> >
648
+ < URL : <URLPREFIX> ( <S> )* ( <STRING> | <_URL> ) ( <S> )* <RPAREN> >
642
649
}
643
650
644
651
<DEFAULT>
@@ -3949,134 +3956,39 @@ void skipAfterExpression(Exception e) {
3949
3956
}
3950
3957
3951
3958
JAVACODE
3952
- String convertStringIndex(String s, int start, int len, boolean escapeFirst) {
3953
- int index = start;
3954
- int t;
3955
- int maxCount = 0;
3956
- boolean gotWhiteSpace = false;
3957
- int count = 0;
3958
- if ((start == 0) && (len == s.length()) && (s.indexOf('\\') == -1)) {
3959
- return s;
3960
- }
3961
- StringBuilder buf = new StringBuilder(len);
3962
- maxCount = ((ac.getCssVersion() == CssVersion.CSS1) ? 4 : 6);
3963
-
3964
- while (index < len) {
3965
- char c = s.charAt(index);
3966
- if (c == '\\') {
3967
- if (++index < len) {
3968
- c = s.charAt(index);
3969
- switch (c) {
3970
- case '0': case '1': case '2': case '3': case '4':
3971
- case '5': case '6': case '7': case '8': case '9':
3972
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
3973
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
3974
- int numValue = Character.digit(c, 16);
3975
- count = 1;
3976
- while (index + 1 < len) {
3977
- c = s.charAt(index+1);
3978
- t = Character.digit(c, 16);
3979
- if (t != -1 && count++ < maxCount) {
3980
- numValue = (numValue<<4) | t;
3981
- index++;
3982
- } else {
3983
- if (c == ' ' || c == '\t' ||
3984
- c == '\n' || c == '\f' ) {
3985
- // skip the latest white space
3986
- index++;
3987
- gotWhiteSpace = true;
3988
- } else if ( c == '\r' ) {
3989
- index++;
3990
- gotWhiteSpace = true;
3991
- // special case for \r\n
3992
- if (index+1 < len) {
3993
- if (s.charAt(index + 1) == '\n') {
3994
- index++;
3995
- }
3996
- }
3997
- }
3998
- break;
3999
- }
4000
- }
4001
- if (!escapeFirst && numValue < 255 && numValue>31) {
4002
- if (! ( (numValue>96 && numValue<123) // [a-z]
4003
- || (numValue>64 && numValue<91) // [A-Z]
4004
- || (numValue>47 && numValue<58) // [0-9]
4005
- || (numValue == 95) // _
4006
- || (numValue == 45) // -
4007
- )
4008
- ) {
4009
- buf.append('\\');
4010
- }
4011
- buf.append((char) numValue);
4012
- break;
4013
- }
4014
- char b[];
4015
- // we fully escape when we have a space
4016
- if (gotWhiteSpace) {
4017
- b = new char[maxCount];
4018
- t = maxCount;
4019
- } else {
4020
- b = new char[count];
4021
- t = count;
4022
- }
4023
- while (t > 0) {
4024
- b[--t] = hexdigits[numValue & 0xF];
4025
- numValue >>>= 4;
4026
- }
4027
- buf.append('\\').append(b);
4028
- break;
4029
- case '\n':
4030
- case '\f':
4031
- break;
4032
- case '\r':
4033
- if (index + 1 < len) {
4034
- if (s.charAt(index + 1) == '\n') {
4035
- index ++;
4036
- }
4037
- }
4038
- break;
4039
- case '-' : case '_' : case 'g' : case 'G' :
4040
- case 'h' : case 'H' : case 'i' : case 'I' :
4041
- case 'j' : case 'J' : case 'k' : case 'K' :
4042
- case 'l' : case 'L' : case 'm' : case 'M' :
4043
- case 'n' : case 'N' : case 'o' : case 'O' :
4044
- case 'p' : case 'P' : case 'q' : case 'Q' :
4045
- case 'r' : case 'R' : case 's' : case 'S' :
4046
- case 't' : case 'T' : case 'u' : case 'U' :
4047
- case 'v' : case 'V' : case 'w' : case 'W' :
4048
- case 'x' : case 'X' : case 'y' : case 'Y' :
4049
- case 'z' : case 'Z' :
4050
- buf.append(c);
4051
- break;
4052
- default:
4053
- buf.append('\\').append(c);
4054
- }
4055
- } else {
3959
+ public String convertStringIndex(String s, int start, int len, boolean escapeFirst) {
3960
+ try {
3961
+ return StringUtils.convertStringIndex(s, start, len, escapeFirst, ac);
3962
+ } catch (InvalidParamException nex) {
4056
3963
throw new ParseException("invalid string");
4057
- }
4058
- } else {
4059
- buf.append(c);
4060
3964
}
4061
- escapeFirst = false;
4062
- index++;
4063
- }
4064
- return buf.toString();
4065
3965
}
4066
3966
4067
3967
JAVACODE
4068
- String convertIdent(String s) {
4069
- return convertStringIndex(s, 0, s.length(), false);
3968
+ String convertIdent(String s) throws ParseException {
3969
+ try {
3970
+ return StringUtils.convertIdent(s, ac);
3971
+ } catch (InvalidParamException nex) {
3972
+ throw new ParseException("invalid string");
3973
+ }
4070
3974
}
4071
3975
4072
3976
JAVACODE
4073
3977
String convertClassIdent(String s) {
4074
- return convertStringIndex(s, 0, s.length(), true);
3978
+ try {
3979
+ return StringUtils.convertClassIdent(s, ac);
3980
+ } catch (InvalidParamException nex) {
3981
+ throw new ParseException("invalid string");
3982
+ }
4075
3983
}
4076
3984
4077
3985
JAVACODE
4078
3986
String convertString(String s) {
4079
- return convertStringIndex(s, 0, s.length(), false);
3987
+ try {
3988
+ return StringUtils.convertString(s, ac);
3989
+ } catch (InvalidParamException nex) {
3990
+ throw new ParseException("invalid string");
3991
+ }
4080
3992
}
4081
3993
4082
3994
JAVACODE
0 commit comments