Home | History | Annotate | Download | only in svg
      1 /*
      2    Copyright (C) 2002, 2003 The Karbon Developers
      3                  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 
     27 namespace WebCore {
     28 
     29     class Path;
     30     class SVGPointList;
     31     class SVGPathSegList;
     32 
     33     bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip = true);
     34     bool parseNumberOptionalNumber(const String& s, float& h, float& v);
     35 
     36     // SVG allows several different whitespace characters:
     37     // http://www.w3.org/TR/SVG/paths.html#PathDataBNF
     38     inline bool isWhitespace(const UChar& c)
     39     {
     40         return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
     41     }
     42 
     43     inline bool skipOptionalSpaces(const UChar*& ptr, const UChar* end)
     44     {
     45         while (ptr < end && isWhitespace(*ptr))
     46             ptr++;
     47         return ptr < end;
     48     }
     49 
     50     inline bool skipOptionalSpacesOrDelimiter(const UChar*& ptr, const UChar* end, UChar delimiter = ',')
     51     {
     52         if (ptr < end && !isWhitespace(*ptr) && *ptr != delimiter)
     53             return false;
     54         if (skipOptionalSpaces(ptr, end)) {
     55             if (ptr < end && *ptr == delimiter) {
     56                 ptr++;
     57                 skipOptionalSpaces(ptr, end);
     58             }
     59         }
     60         return ptr < end;
     61     }
     62 
     63     bool pointsListFromSVGData(SVGPointList* pointsList, const String& points);
     64     bool pathFromSVGData(Path& path, const String& d);
     65     bool pathSegListFromSVGData(SVGPathSegList* pathSegList, const String& d, bool process = false);
     66     Vector<String> parseDelimitedString(const String& input, const char seperator);
     67 
     68 } // namespace WebCore
     69 
     70 #endif // ENABLE(SVG)
     71 #endif // SVGParserUtilities_h
     72