File indexing completed on 2024-04-21 11:31:04
0001 /* 0002 Copyright (C) 2002, 2003 The Karbon Developers 0003 2006, 2007 Rob Buis <buis@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef SVGParserUtilities_h 0022 #define SVGParserUtilities_h 0023 #if ENABLE(SVG) 0024 0025 #include "ParserUtilities.h" 0026 0027 namespace khtml 0028 { 0029 class Path; 0030 } 0031 0032 namespace WebCore 0033 { 0034 0035 typedef khtml::Path Path; 0036 class SVGPointList; 0037 class SVGPathSegList; 0038 0039 bool parseNumber(const UChar *&ptr, const UChar *end, float &number, bool skip = true); 0040 bool parseNumberOptionalNumber(const String &s, float &h, float &v); 0041 0042 // SVG allows several different whitespace characters: 0043 // https://www.w3.org/TR/SVG/paths.html#PathDataBNF 0044 inline bool isWhitespace(const UChar &c) 0045 { 0046 return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); 0047 } 0048 0049 inline bool skipOptionalSpaces(const UChar *&ptr, const UChar *end) 0050 { 0051 while (ptr < end && isWhitespace(*ptr)) { 0052 ptr++; 0053 } 0054 return ptr < end; 0055 } 0056 0057 inline bool skipOptionalSpacesOrDelimiter(const UChar *&ptr, const UChar *end, UChar delimiter = UChar(',')) 0058 { 0059 if (ptr < end && !isWhitespace(*ptr) && *ptr != delimiter) { 0060 return false; 0061 } 0062 if (skipOptionalSpaces(ptr, end)) { 0063 if (ptr < end && *ptr == delimiter) { 0064 ptr++; 0065 skipOptionalSpaces(ptr, end); 0066 } 0067 } 0068 return ptr < end; 0069 } 0070 0071 bool pointsListFromSVGData(SVGPointList *pointsList, const String &points); 0072 bool pathFromSVGData(Path &path, const String &d); 0073 bool pathSegListFromSVGData(SVGPathSegList *pathSegList, const String &d, bool process = false); 0074 Vector<String> parseDelimitedString(const String &input, const char separator); 0075 0076 } // namespace WebCore 0077 0078 #endif // ENABLE(SVG) 0079 #endif // SVGParserUtilities_h