1 /* 2 * Copyright (C) 2002, 2003 The Karbon Developers 3 * Copyright (C) 2006, 2007 Rob Buis <buis (at) kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef SVGParserUtilities_h 22 #define SVGParserUtilities_h 23 #if ENABLE(SVG) 24 25 #include "ParserUtilities.h" 26 #include <wtf/HashSet.h> 27 28 typedef pair<unsigned, unsigned> UnicodeRange; 29 typedef Vector<UnicodeRange> UnicodeRanges; 30 31 namespace WebCore { 32 33 class SVGPointList; 34 35 bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip = true); 36 bool parseNumberOptionalNumber(const String& s, float& h, float& v); 37 bool parseArcFlag(const UChar*& ptr, const UChar* end, bool& flag); 38 39 // SVG allows several different whitespace characters: 40 // http://www.w3.org/TR/SVG/paths.html#PathDataBNF 41 inline bool isWhitespace(const UChar& c) 42 { 43 return c == ' ' || c == '\t' || c == '\n' || c == '\r'; 44 } 45 46 inline bool skipOptionalSpaces(const UChar*& ptr, const UChar* end) 47 { 48 while (ptr < end && isWhitespace(*ptr)) 49 ptr++; 50 return ptr < end; 51 } 52 53 inline bool skipOptionalSpacesOrDelimiter(const UChar*& ptr, const UChar* end, UChar delimiter = ',') 54 { 55 if (ptr < end && !isWhitespace(*ptr) && *ptr != delimiter) 56 return false; 57 if (skipOptionalSpaces(ptr, end)) { 58 if (ptr < end && *ptr == delimiter) { 59 ptr++; 60 skipOptionalSpaces(ptr, end); 61 } 62 } 63 return ptr < end; 64 } 65 66 bool pointsListFromSVGData(SVGPointList& pointsList, const String& points); 67 Vector<String> parseDelimitedString(const String& input, const char seperator); 68 bool parseKerningUnicodeString(const String& input, UnicodeRanges&, HashSet<String>& stringList); 69 bool parseGlyphName(const String& input, HashSet<String>& values); 70 71 } // namespace WebCore 72 73 #endif // ENABLE(SVG) 74 #endif // SVGParserUtilities_h 75