[libgxps] Fix parsing of real numbers containing e[+-]number



commit 9ae0299eb47412d50a249b3d53730571b4a8e22f
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Fri Jan 11 15:58:26 2013 +0100

    Fix parsing of real numbers containing e[+-]number

 libgxps/gxps-glyphs.c      |    4 +---
 libgxps/gxps-parse-utils.c |   39 +++++++++++++++++++++++++++++++++++++++
 libgxps/gxps-parse-utils.h |    2 ++
 libgxps/gxps-path.c        |    4 +---
 4 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/libgxps/gxps-glyphs.c b/libgxps/gxps-glyphs.c
index 3b89526..ed52898 100644
--- a/libgxps/gxps-glyphs.c
+++ b/libgxps/gxps-glyphs.c
@@ -127,9 +127,7 @@ glyphs_indices_iter_next (GlyphsIndicesToken *token,
                 gchar *str;
 
                 start = token->iter;
-                token->iter++;
-                while (token->iter != token->end && (g_ascii_isdigit (*token->iter) || *token->iter == '.'))
-                        token->iter++;
+                gxps_parse_skip_number (&token->iter, token->end);
                 str = g_strndup (start, token->iter - start);
                 if (!gxps_value_get_double (str, &token->number)) {
                         g_set_error (error,
diff --git a/libgxps/gxps-parse-utils.c b/libgxps/gxps-parse-utils.c
index b6614bf..18127d0 100644
--- a/libgxps/gxps-parse-utils.c
+++ b/libgxps/gxps-parse-utils.c
@@ -351,6 +351,45 @@ gxps_point_parse (const gchar *point,
         return TRUE;
 }
 
+void
+gxps_parse_skip_number (gchar      **iter,
+                        const gchar *end)
+{
+        gchar *p = *iter;
+
+        p++;
+        while (p != end && g_ascii_isdigit (*p))
+                p++;
+        if (p == end) {
+                *iter = p;
+                return;
+        }
+
+        if (*p == '.')
+                p++;
+
+        while (p != end && g_ascii_isdigit (*p))
+                p++;
+        if (p == end) {
+                *iter = p;
+                return;
+        }
+
+        if (*p == 'e' || *p == 'E')
+                p++;
+        if (p == end) {
+                *iter = p;
+                return;
+        }
+
+        if (*p == '+' || *p == '-')
+                p++;
+
+        while (p != end && g_ascii_isdigit (*p))
+                p++;
+        *iter = p;
+}
+
 gchar *
 gxps_resolve_relative_path (const gchar *source,
 			    const gchar *target)
diff --git a/libgxps/gxps-parse-utils.h b/libgxps/gxps-parse-utils.h
index 0255bba..9dbdefa 100644
--- a/libgxps/gxps-parse-utils.h
+++ b/libgxps/gxps-parse-utils.h
@@ -45,6 +45,8 @@ gboolean gxps_value_get_boolean         (const gchar          *value,
 gboolean gxps_point_parse               (const gchar          *point,
                                          gdouble              *x,
                                          gdouble              *y);
+void     gxps_parse_skip_number         (gchar               **iter,
+                                         const gchar          *end);
 gchar   *gxps_resolve_relative_path     (const gchar          *source,
                                          const gchar          *target);
 
diff --git a/libgxps/gxps-path.c b/libgxps/gxps-path.c
index 90a9103..4f5c2f6 100644
--- a/libgxps/gxps-path.c
+++ b/libgxps/gxps-path.c
@@ -173,9 +173,7 @@ path_data_iter_next (PathDataToken *token,
                 gchar *str;
 
                 start = token->iter;
-                token->iter++;
-                while (token->iter != token->end && (g_ascii_isdigit (*token->iter) || *token->iter == '.'))
-                        token->iter++;
+                gxps_parse_skip_number (&token->iter, token->end);
                 str = g_strndup (start, token->iter - start);
                 if (!gxps_value_get_double (str, &token->number)) {
                         g_set_error (error,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]