OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 template<typename CharType> | 158 template<typename CharType> |
159 static SVGAngle::SVGAngleType stringToAngleType(const CharType*& ptr, const Char
Type* end) | 159 static SVGAngle::SVGAngleType stringToAngleType(const CharType*& ptr, const Char
Type* end) |
160 { | 160 { |
161 // If there's no unit given, the angle type is unspecified. | 161 // If there's no unit given, the angle type is unspecified. |
162 if (ptr == end) | 162 if (ptr == end) |
163 return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; | 163 return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; |
164 | 164 |
165 SVGAngle::SVGAngleType type = SVGAngle::SVG_ANGLETYPE_UNKNOWN; | 165 SVGAngle::SVGAngleType type = SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
166 const CharType firstChar = *ptr++; | 166 if (isHTMLSpace<CharType>(ptr[0])) { |
167 | |
168 if (isHTMLSpace<CharType>(firstChar)) { | |
169 type = SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; | 167 type = SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; |
170 } else if (end - ptr >= 2) { | 168 ptr++; |
171 const CharType secondChar = *ptr++; | 169 } else if (end - ptr >= 3) { |
172 const CharType thirdChar = *ptr++; | 170 if (ptr[0] == 'd' && ptr[1] == 'e' && ptr[2] == 'g') { |
173 if (firstChar == 'd' && secondChar == 'e' && thirdChar == 'g') { | |
174 type = SVGAngle::SVG_ANGLETYPE_DEG; | 171 type = SVGAngle::SVG_ANGLETYPE_DEG; |
175 } else if (firstChar == 'r' && secondChar == 'a' && thirdChar == 'd') { | 172 ptr += 3; |
| 173 } else if (ptr[0] == 'r' && ptr[1] == 'a' && ptr[2] == 'd') { |
176 type = SVGAngle::SVG_ANGLETYPE_RAD; | 174 type = SVGAngle::SVG_ANGLETYPE_RAD; |
177 } else if (ptr != end) { | 175 ptr += 3; |
178 const CharType fourthChar = *ptr++; | 176 } else if (end - ptr >= 4) { |
179 if (firstChar == 'g' && secondChar == 'r' && thirdChar == 'a' && fou
rthChar == 'd') | 177 if (ptr[0] == 'g' && ptr[1] == 'r' && ptr[2] == 'a' && ptr[3] == 'd'
) { |
180 type = SVGAngle::SVG_ANGLETYPE_GRAD; | 178 type = SVGAngle::SVG_ANGLETYPE_GRAD; |
181 else if (firstChar == 't' && secondChar == 'u' && thirdChar == 'r' &
& fourthChar == 'n') | 179 ptr += 4; |
| 180 } else if (ptr[0] == 't' && ptr[1] == 'u' && ptr[2] == 'r' && ptr[3]
== 'n') { |
182 type = SVGAngle::SVG_ANGLETYPE_TURN; | 181 type = SVGAngle::SVG_ANGLETYPE_TURN; |
| 182 ptr += 4; |
| 183 } |
183 } | 184 } |
184 } | 185 } |
185 | 186 |
186 if (!skipOptionalSVGSpaces(ptr, end)) | 187 if (!skipOptionalSVGSpaces(ptr, end)) |
187 return type; | 188 return type; |
188 | 189 |
189 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; | 190 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
190 } | 191 } |
191 | 192 |
192 String SVGAngle::valueAsString() const | 193 String SVGAngle::valueAsString() const |
(...skipping 18 matching lines...) Expand all Loading... |
211 case SVG_ANGLETYPE_UNSPECIFIED: | 212 case SVG_ANGLETYPE_UNSPECIFIED: |
212 case SVG_ANGLETYPE_UNKNOWN: | 213 case SVG_ANGLETYPE_UNKNOWN: |
213 return String::number(m_valueInSpecifiedUnits); | 214 return String::number(m_valueInSpecifiedUnits); |
214 } | 215 } |
215 | 216 |
216 ASSERT_NOT_REACHED(); | 217 ASSERT_NOT_REACHED(); |
217 return String(); | 218 return String(); |
218 } | 219 } |
219 | 220 |
220 template<typename CharType> | 221 template<typename CharType> |
221 static bool parseValue(const String& value, float& valueInSpecifiedUnits, SVGAng
le::SVGAngleType& unitType) | 222 static SVGParsingError parseValue(const String& value, float& valueInSpecifiedUn
its, SVGAngle::SVGAngleType& unitType) |
222 { | 223 { |
223 const CharType* ptr = value.getCharacters<CharType>(); | 224 const CharType* ptr = value.getCharacters<CharType>(); |
224 const CharType* end = ptr + value.length(); | 225 const CharType* end = ptr + value.length(); |
225 | 226 |
226 if (!parseNumber(ptr, end, valueInSpecifiedUnits, AllowLeadingWhitespace)) | 227 if (!parseNumber(ptr, end, valueInSpecifiedUnits, AllowLeadingWhitespace)) |
227 return false; | 228 return SVGParsingError(SVGParseStatus::ExpectedAngle, ptr - value.getCha
racters<CharType>()); |
228 | 229 |
229 unitType = stringToAngleType(ptr, end); | 230 unitType = stringToAngleType(ptr, end); |
230 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN) | 231 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN) |
231 return false; | 232 return SVGParsingError(SVGParseStatus::ExpectedAngle, ptr - value.getCha
racters<CharType>()); |
232 | 233 |
233 return true; | 234 return SVGParseStatus::NoError; |
234 } | 235 } |
235 | 236 |
236 SVGParsingError SVGAngle::setValueAsString(const String& value) | 237 SVGParsingError SVGAngle::setValueAsString(const String& value) |
237 { | 238 { |
238 if (value.isEmpty()) { | 239 if (value.isEmpty()) { |
239 newValueSpecifiedUnits(SVG_ANGLETYPE_UNSPECIFIED, 0); | 240 newValueSpecifiedUnits(SVG_ANGLETYPE_UNSPECIFIED, 0); |
240 return SVGParseStatus::NoError; | 241 return SVGParseStatus::NoError; |
241 } | 242 } |
242 | 243 |
243 if (value == "auto") { | 244 if (value == "auto") { |
244 newValueSpecifiedUnits(SVG_ANGLETYPE_UNSPECIFIED, 0); | 245 newValueSpecifiedUnits(SVG_ANGLETYPE_UNSPECIFIED, 0); |
245 m_orientType->setEnumValue(SVGMarkerOrientAuto); | 246 m_orientType->setEnumValue(SVGMarkerOrientAuto); |
246 return SVGParseStatus::NoError; | 247 return SVGParseStatus::NoError; |
247 } | 248 } |
248 if (value == "auto-start-reverse") { | 249 if (value == "auto-start-reverse") { |
249 newValueSpecifiedUnits(SVG_ANGLETYPE_UNSPECIFIED, 0); | 250 newValueSpecifiedUnits(SVG_ANGLETYPE_UNSPECIFIED, 0); |
250 m_orientType->setEnumValue(SVGMarkerOrientAutoStartReverse); | 251 m_orientType->setEnumValue(SVGMarkerOrientAutoStartReverse); |
251 return SVGParseStatus::NoError; | 252 return SVGParseStatus::NoError; |
252 } | 253 } |
253 | 254 |
254 float valueInSpecifiedUnits = 0; | 255 float valueInSpecifiedUnits = 0; |
255 SVGAngleType unitType = SVG_ANGLETYPE_UNKNOWN; | 256 SVGAngleType unitType = SVG_ANGLETYPE_UNKNOWN; |
256 | 257 |
257 bool success = value.is8Bit() ? parseValue<LChar>(value, valueInSpecifiedUni
ts, unitType) | 258 SVGParsingError error; |
258 : parseValue<UChar>(value, valueInSpecifiedUni
ts, unitType); | 259 if (value.is8Bit()) |
259 if (!success) | 260 error = parseValue<LChar>(value, valueInSpecifiedUnits, unitType); |
260 return SVGParseStatus::ParsingFailed; | 261 else |
| 262 error = parseValue<UChar>(value, valueInSpecifiedUnits, unitType); |
| 263 if (error != SVGParseStatus::NoError) |
| 264 return error; |
261 | 265 |
262 m_orientType->setEnumValue(SVGMarkerOrientAngle); | 266 m_orientType->setEnumValue(SVGMarkerOrientAngle); |
263 m_unitType = unitType; | 267 m_unitType = unitType; |
264 m_valueInSpecifiedUnits = valueInSpecifiedUnits; | 268 m_valueInSpecifiedUnits = valueInSpecifiedUnits; |
265 return SVGParseStatus::NoError; | 269 return SVGParseStatus::NoError; |
266 } | 270 } |
267 | 271 |
268 void SVGAngle::newValueSpecifiedUnits(SVGAngleType unitType, float valueInSpecif
iedUnits) | 272 void SVGAngle::newValueSpecifiedUnits(SVGAngleType unitType, float valueInSpecif
iedUnits) |
269 { | 273 { |
270 m_orientType->setEnumValue(SVGMarkerOrientAngle); | 274 m_orientType->setEnumValue(SVGMarkerOrientAngle); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 436 |
433 void SVGAngle::orientTypeChanged() | 437 void SVGAngle::orientTypeChanged() |
434 { | 438 { |
435 if (orientType()->enumValue() == SVGMarkerOrientAuto || orientType()->enumVa
lue() == SVGMarkerOrientAutoStartReverse) { | 439 if (orientType()->enumValue() == SVGMarkerOrientAuto || orientType()->enumVa
lue() == SVGMarkerOrientAutoStartReverse) { |
436 m_unitType = SVG_ANGLETYPE_UNSPECIFIED; | 440 m_unitType = SVG_ANGLETYPE_UNSPECIFIED; |
437 m_valueInSpecifiedUnits = 0; | 441 m_valueInSpecifiedUnits = 0; |
438 } | 442 } |
439 } | 443 } |
440 | 444 |
441 } // namespace blink | 445 } // namespace blink |
OLD | NEW |