| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 m_orientType->setEnumValue(SVGMarkerOrientAngle); | 145 m_orientType->setEnumValue(SVGMarkerOrientAngle); |
| 146 } | 146 } |
| 147 | 147 |
| 148 template<typename CharType> | 148 template<typename CharType> |
| 149 static SVGAngle::SVGAngleType stringToAngleType(const CharType*& ptr, const Char
Type* end) | 149 static SVGAngle::SVGAngleType stringToAngleType(const CharType*& ptr, const Char
Type* end) |
| 150 { | 150 { |
| 151 // If there's no unit given, the angle type is unspecified. | 151 // If there's no unit given, the angle type is unspecified. |
| 152 if (ptr == end) | 152 if (ptr == end) |
| 153 return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; | 153 return SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; |
| 154 | 154 |
| 155 const CharType firstChar = *ptr; | 155 SVGAngle::SVGAngleType type = SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
| 156 const CharType firstChar = *ptr++; |
| 156 | 157 |
| 157 // If the unit contains only one character, the angle type is unknown. | 158 if (isHTMLSpace<CharType>(firstChar)) { |
| 158 ++ptr; | 159 type = SVGAngle::SVG_ANGLETYPE_UNSPECIFIED; |
| 159 if (ptr == end) | 160 } else if (end - ptr >= 2) { |
| 160 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; | 161 const CharType secondChar = *ptr++; |
| 162 const CharType thirdChar = *ptr++; |
| 163 if (firstChar == 'd' && secondChar == 'e' && thirdChar == 'g') { |
| 164 type = SVGAngle::SVG_ANGLETYPE_DEG; |
| 165 } else if (firstChar == 'r' && secondChar == 'a' && thirdChar == 'd') { |
| 166 type = SVGAngle::SVG_ANGLETYPE_RAD; |
| 167 } else if (ptr != end) { |
| 168 const CharType fourthChar = *ptr++; |
| 169 if (firstChar == 'g' && secondChar == 'r' && thirdChar == 'a' && fou
rthChar == 'd') |
| 170 type = SVGAngle::SVG_ANGLETYPE_GRAD; |
| 171 } |
| 172 } |
| 161 | 173 |
| 162 const CharType secondChar = *ptr; | 174 if (!skipOptionalSVGSpaces(ptr, end)) |
| 163 | 175 return type; |
| 164 // If the unit contains only two characters, the angle type is unknown. | |
| 165 ++ptr; | |
| 166 if (ptr == end) | |
| 167 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; | |
| 168 | |
| 169 const CharType thirdChar = *ptr; | |
| 170 if (firstChar == 'd' && secondChar == 'e' && thirdChar == 'g') | |
| 171 return SVGAngle::SVG_ANGLETYPE_DEG; | |
| 172 if (firstChar == 'r' && secondChar == 'a' && thirdChar == 'd') | |
| 173 return SVGAngle::SVG_ANGLETYPE_RAD; | |
| 174 | |
| 175 // If the unit contains three characters, but is not deg or rad, then it's u
nknown. | |
| 176 ++ptr; | |
| 177 if (ptr == end) | |
| 178 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; | |
| 179 | |
| 180 const CharType fourthChar = *ptr; | |
| 181 | |
| 182 if (firstChar == 'g' && secondChar == 'r' && thirdChar == 'a' && fourthChar
== 'd') | |
| 183 return SVGAngle::SVG_ANGLETYPE_GRAD; | |
| 184 | 176 |
| 185 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; | 177 return SVGAngle::SVG_ANGLETYPE_UNKNOWN; |
| 186 } | 178 } |
| 187 | 179 |
| 188 String SVGAngle::valueAsString() const | 180 String SVGAngle::valueAsString() const |
| 189 { | 181 { |
| 190 switch (m_unitType) { | 182 switch (m_unitType) { |
| 191 case SVG_ANGLETYPE_DEG: { | 183 case SVG_ANGLETYPE_DEG: { |
| 192 DEFINE_STATIC_LOCAL(String, degString, ("deg")); | 184 DEFINE_STATIC_LOCAL(String, degString, ("deg")); |
| 193 return String::number(m_valueInSpecifiedUnits) + degString; | 185 return String::number(m_valueInSpecifiedUnits) + degString; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 208 ASSERT_NOT_REACHED(); | 200 ASSERT_NOT_REACHED(); |
| 209 return String(); | 201 return String(); |
| 210 } | 202 } |
| 211 | 203 |
| 212 template<typename CharType> | 204 template<typename CharType> |
| 213 static bool parseValue(const String& value, float& valueInSpecifiedUnits, SVGAng
le::SVGAngleType& unitType) | 205 static bool parseValue(const String& value, float& valueInSpecifiedUnits, SVGAng
le::SVGAngleType& unitType) |
| 214 { | 206 { |
| 215 const CharType* ptr = value.getCharacters<CharType>(); | 207 const CharType* ptr = value.getCharacters<CharType>(); |
| 216 const CharType* end = ptr + value.length(); | 208 const CharType* end = ptr + value.length(); |
| 217 | 209 |
| 218 if (!parseNumber(ptr, end, valueInSpecifiedUnits, false)) | 210 if (!parseNumber(ptr, end, valueInSpecifiedUnits, AllowLeadingWhitespace)) |
| 219 return false; | 211 return false; |
| 220 | 212 |
| 221 unitType = stringToAngleType(ptr, end); | 213 unitType = stringToAngleType(ptr, end); |
| 222 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN) | 214 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN) |
| 223 return false; | 215 return false; |
| 224 | 216 |
| 225 return true; | 217 return true; |
| 226 } | 218 } |
| 227 | 219 |
| 228 void SVGAngle::setValueAsString(const String& value, ExceptionState& exceptionSt
ate) | 220 void SVGAngle::setValueAsString(const String& value, ExceptionState& exceptionSt
ate) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 389 |
| 398 void SVGAngle::orientTypeChanged() | 390 void SVGAngle::orientTypeChanged() |
| 399 { | 391 { |
| 400 if (orientType()->enumValue() == SVGMarkerOrientAuto) { | 392 if (orientType()->enumValue() == SVGMarkerOrientAuto) { |
| 401 m_unitType = SVG_ANGLETYPE_UNSPECIFIED; | 393 m_unitType = SVG_ANGLETYPE_UNSPECIFIED; |
| 402 m_valueInSpecifiedUnits = 0; | 394 m_valueInSpecifiedUnits = 0; |
| 403 } | 395 } |
| 404 } | 396 } |
| 405 | 397 |
| 406 } | 398 } |
| OLD | NEW |