X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdom%2Fio%2Fdomstream.cpp;h=c6234d462e652a7b46384af026d203777c098b03;hb=cfb5fa826062314dac912b3627f932aab8250988;hp=19ff3de7b1c784bd03f20ad23f5f7f18bde5292c;hpb=01e85e7889ed1e2f0bff3153bbe1ff0b38c31411;p=inkscape.git diff --git a/src/dom/io/domstream.cpp b/src/dom/io/domstream.cpp index 19ff3de7b..c6234d462 100644 --- a/src/dom/io/domstream.cpp +++ b/src/dom/io/domstream.cpp @@ -95,6 +95,13 @@ static int dprintInt(Writer &outs, buf.insert(buf.begin(), '0'); } + if (buf.size() == 0) + buf = "0"; + + int pad = width - (int)buf.size(); + for (int i=0 ; i') + outs.writeString(">"); + else if (ch == '"') + outs.writeString("""); + else if (ch == '\'') + outs.writeString("'"); + else + outs.put(ch); + } + } + else + { + outs.writeString(str); } return 1; @@ -218,151 +249,172 @@ static int dprintString(Writer &outs, -static char *getint(char *s, int *ret) +static int getint(const DOMString &buf, int pos, int *ret) { + int len = buf.size(); + if (!len) + { + *ret = 0; + return pos; + } + bool has_sign = false; int val = 0; - if (*s == '-') + if (buf[pos] == '-') { has_sign = true; - s++; + pos++; } - while (*s >= '0' && *s <= '9') + while (pos < len) { - val = val * 10 + (*s - '0'); - s++; + XMLCh ch = buf[pos]; + if (ch >= '0' && ch <= '9') + val = val * 10 + (ch - '0'); + else + break; + pos++; } if (has_sign) val = -val; *ret = val; - return s; + return pos; } -static int dprintf(Writer &outs, const char *fmt, va_list ap) +static int dprintf(Writer &outs, const DOMString &fmt, va_list ap) { - char *s = (char *) fmt; + int len = fmt.size(); - while (*s) + for (int pos=0 ; pos < len ; pos++) { - unsigned char ch = *s++; + XMLCh ch = fmt[pos]; + //## normal character if (ch != '%') { if (outs.put(ch)<0) { return -1; } + continue; } - else - //expecting %[flag][width][.precision][length][char] + + if (++pos >= len) { - if (!*s) + return -1; + } + + ch = fmt[pos]; + + //## is this %% ? + if (ch == '%') // escaped '%' + { + if (outs.put('%')<0) { return -1; } - if (*s == '%') // escaped '%' + continue; + } + + //## flag + char flag = '\0'; + if (ch == '-' || ch == '+' || ch == ' ' || + ch == '#' || ch == '0') + { + flag = ch; + if (++pos >= len) { - if (outs.put('%')<0) - { - return -1; - } - s++; - continue; + return -1; } - char flag = '\0'; - if (*s == '-' || *s == '+' || *s == ' ' || - *s == '#' || *s == '0') + ch = fmt[pos]; + } + + //## width.precision + int width = 0; + int precision = 0; + pos = getint(fmt, pos, &width); + if (pos >= len) + { + return -1; + } + ch = fmt[pos]; + if (ch == '.') + { + if (++pos >= len) + { + return -1; + } + pos = getint(fmt, pos, &precision); + if (pos >= len) { - flag = *s++; - if (!*s) - { - return -1; - } + return -1; } - int width = 0; - int precision = 0; - s = getint(s, &width); - if (!*s) + ch = fmt[pos]; + } + + //## length + char length = '\0'; + if (ch == 'l' || ch == 'h') + { + length = ch; + if (++pos >= len) { return -1; } - if (*s == '.') + ch = fmt[pos]; + } + + //## data type + switch (ch) + { + case 'f': + case 'g': { - s++; - if (!*s) - { - return -1; - } - s = getint(s, &precision); + double val = va_arg(ap, double); + dprintDouble(outs, val, flag, width, precision); + break; } - char length = '\0'; - if (*s == 'l' || *s == 'h') + case 'd': { - length = *s++; - if (!*s) - { - return -1; - } + long val = 0; + if (length == 'l') + val = va_arg(ap, long); + else if (length == 'h') + val = (long)va_arg(ap, int); + else + val = (long)va_arg(ap, int); + dprintInt(outs, val, 10, flag, width, precision); + break; } - ch = *s++; - if (!ch) + case 'x': { - return -1; + long val = 0; + if (length == 'l') + val = va_arg(ap, long); + else if (length == 'h') + val = (long)va_arg(ap, int); + else + val = (long)va_arg(ap, int); + dprintInt(outs, val, 16, flag, width, precision); + break; } - switch (ch) + case 's': { - case 'f': - case 'g': - { - double val = va_arg(ap, double); - dprintDouble(outs, val, flag, width, precision); - break; - } - case 'd': - { - long val = 0; - if (length == 'l') - val = va_arg(ap, long); - else if (length == 'h') - val = (long)va_arg(ap, int); - else - val = (long)va_arg(ap, int); - dprintInt(outs, val, 10, flag, width, precision); - break; - } - case 'x': - { - long val = 0; - if (length == 'l') - val = va_arg(ap, long); - else if (length == 'h') - val = (long)va_arg(ap, int); - else - val = (long)va_arg(ap, int); - dprintInt(outs, val, 16, flag, width, precision); - break; - } - case 's': - { - char *val = va_arg(ap, char *); - dprintString(outs, val, flag, width, precision); - break; - } - default: - { - break; - } + DOMString val = va_arg(ap, char *); + dprintString(outs, val, flag, width, precision); + break; + } + default: + { + break; } } - } - return 1; } @@ -856,12 +908,11 @@ Writer &BasicWriter::printf(char *fmt, ...) return *this; } */ -Writer &BasicWriter::printf(char *fmt, ...) +Writer &BasicWriter::printf(const DOMString &fmt, ...) { va_list args; va_start(args, fmt); dprintf(*this, fmt, args); - return *this; }