From 64e594860a92fdd912d08398baf1ad4b013068a8 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: 2012年7月30日 15:05:50 +0200 Subject: Implement a local function to parse printf templates The header file seems to be absent on MinGW and broken on Linux so it is better to not rely on this header file. --- agg-plot/printf_check.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 agg-plot/printf_check.cpp (limited to 'agg-plot/printf_check.cpp') diff --git a/agg-plot/printf_check.cpp b/agg-plot/printf_check.cpp new file mode 100644 index 00000000..3e8e50b2 --- /dev/null +++ b/agg-plot/printf_check.cpp @@ -0,0 +1,78 @@ + +#include "printf_check.h" + +static const char* match_plain_chars(const char *p) +{ + for (/* */; *p; p++) { + for (/* */; *p != '%'; p++) { + if (*p == 0) + return 0; + } + p ++; + if (*p != '%') + return p; + } + return 0; +} + +static const char* match_integer(const char* p) +{ + if (int(*p)>= int('1') && int(*p) <= int('9')) + p++; + while (int(*p)>= int('0') && int(*p) <= int('9')) + p++; + + return p; +} + +int check_printf_argument(const char *label, const char*& tail, arg_type_e& arg_type) +{ + const char* p = match_plain_chars(label); + + if (!p) return 0; + + if (*p) + { + const char c = *p; + if (c == '0' || c == '-' || c == '+' || c == ' ' || c == '#' || c == '\'') + { + p ++; + if (*p == 0) goto error_exit; + } + } + else + goto error_exit; + + p = match_integer(p); + if (*p == 0) goto error_exit; + + if (*p == '.') + { + p++; + if (*p == 0) goto error_exit; + p = match_integer(p); + if (*p == 0) goto error_exit; + } + + if (*p == 'l') { + p++; + if (*p == 0) goto error_exit; + } + + if (*p) + { + const char s = *p; + if (s == 'd' || s == 'i' || s == 'd' || s == 'u' || s == 'x' || s == 'X' || s == 'o') { + tail = p + 1; + arg_type = argument_int; + return 1; + } else if (s == 'f' || s == 'g' || s == 'e' || s == 'E' || s == 'G') { + tail = p + 1; + arg_type = argument_double; + return 1; + } + } + + error_exit: + return (-1); +} -- cgit v1.2.3

AltStyle によって変換されたページ (->オリジナル) /