[poppler] Branch 'xpdf303merge' - goo/GooString.cc goo/GooString.h
Carlos Garcia Campos
carlosgc at kemper.freedesktop.org
Fri Sep 2 09:44:42 PDT 2011
goo/GooString.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
goo/GooString.h | 21 +++++++++--
2 files changed, 111 insertions(+), 12 deletions(-)
New commits:
commit 419ee8c30ba0df02e9f0281b321fbe38387e5a21
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Fri Sep 2 18:44:04 2011 +0200
xpdf303: Add more formats to GooString
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 1842565..5c8a14d 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -49,6 +49,12 @@ union GooStringFormatArg {
Guint ui;
long l;
Gulong ul;
+#ifdef LLONG_MAX
+ long long ll;
+#endif
+#ifdef ULLONG_MAX
+ unsigned long long ull;
+#endif
double f;
char c;
char *s;
@@ -72,6 +78,18 @@ enum GooStringFormatType {
fmtULongHex,
fmtULongOctal,
fmtULongBinary,
+#ifdef LLONG_MAX
+ fmtLongLongDecimal,
+ fmtLongLongHex,
+ fmtLongLongOctal,
+ fmtLongLongBinary,
+#endif
+#ifdef ULLONG_MAX
+ fmtULongLongDecimal,
+ fmtULongLongHex,
+ fmtULongLongOctal,
+ fmtULongLongBinary,
+#endif
fmtDouble,
fmtDoubleTrimSmallAware,
fmtDoubleTrim,
@@ -84,6 +102,12 @@ enum GooStringFormatType {
static const char *formatStrings[] = {
"d", "x", "o", "b", "ud", "ux", "uo", "ub",
"ld", "lx", "lo", "lb", "uld", "ulx", "ulo", "ulb",
+#ifdef LLONG_MAX
+ "lld", "llx", "llo", "llb",
+#endif
+#ifdef ULLONG_MAX
+ "ulld", "ullx", "ullo", "ullb",
+#endif
"f", "gs", "g",
"c",
"s",
@@ -211,7 +235,7 @@ GooString::GooString(GooString *str1, GooString *str2) {
GooString *GooString::fromInt(int x) {
char buf[24]; // enough space for 64-bit ints plus a little extra
- const char *p;
+ char *p;
int len;
formatInt(x, buf, sizeof(buf), gFalse, 0, 10, &p, &len);
return new GooString(p, len);
@@ -281,7 +305,8 @@ GooString *GooString::appendfv(const char *fmt, va_list argList) {
GooStringFormatType ft;
char buf[65];
int len, i;
- const char *p0, *p1, *str;
+ const char *p0, *p1;
+ char *str;
argsLen = 0;
argsSize = 8;
@@ -380,6 +405,22 @@ GooString *GooString::appendfv(const char *fmt, va_list argList) {
case fmtULongBinary:
args[argsLen].ul = va_arg(argList, Gulong);
break;
+#ifdef LLONG_MAX
+ case fmtLongLongDecimal:
+ case fmtLongLongHex:
+ case fmtLongLongOctal:
+ case fmtLongLongBinary:
+ args[argsLen].ll = va_arg(argList, long long);
+ break;
+#endif
+#ifdef ULLONG_MAX
+ case fmtULongLongDecimal:
+ case fmtULongLongHex:
+ case fmtULongLongOctal:
+ case fmtULongLongBinary:
+ args[argsLen].ull = va_arg(argList, unsigned long long);
+ break;
+#endif
case fmtDouble:
case fmtDoubleTrim:
case fmtDoubleTrimSmallAware:
@@ -453,6 +494,38 @@ GooString *GooString::appendfv(const char *fmt, va_list argList) {
case fmtULongBinary:
formatUInt(arg.ul, buf, sizeof(buf), zeroFill, width, 2, &str, &len);
break;
+#ifdef LLONG_MAX
+ case fmtLongLongDecimal:
+ formatInt(arg.ll, buf, sizeof(buf), zeroFill, width, 10, &str, &len);
+ break;
+ case fmtLongLongHex:
+ formatInt(arg.ll, buf, sizeof(buf), zeroFill, width, 16, &str, &len);
+ break;
+ case fmtLongLongOctal:
+ formatInt(arg.ll, buf, sizeof(buf), zeroFill, width, 8, &str, &len);
+ break;
+ case fmtLongLongBinary:
+ formatInt(arg.ll, buf, sizeof(buf), zeroFill, width, 2, &str, &len);
+ break;
+#endif
+#ifdef ULLONG_MAX
+ case fmtULongLongDecimal:
+ formatUInt(arg.ull, buf, sizeof(buf), zeroFill, width, 10,
+ &str, &len);
+ break;
+ case fmtULongLongHex:
+ formatUInt(arg.ull, buf, sizeof(buf), zeroFill, width, 16,
+ &str, &len);
+ break;
+ case fmtULongLongOctal:
+ formatUInt(arg.ull, buf, sizeof(buf), zeroFill, width, 8,
+ &str, &len);
+ break;
+ case fmtULongLongBinary:
+ formatUInt(arg.ull, buf, sizeof(buf), zeroFill, width, 2,
+ &str, &len);
+ break;
+#endif
case fmtDouble:
formatDouble(arg.f, buf, sizeof(buf), prec, gFalse, &str, &len);
break;
@@ -516,10 +589,15 @@ GooString *GooString::appendfv(const char *fmt, va_list argList) {
gfree(args);
return this;
}
-
+#ifdef LLONG_MAX
+void GooString::formatInt(long long x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len) {
+#else
void GooString::formatInt(long x, char *buf, int bufSize,
- GBool zeroFill, int width, int base,
- const char **p, int *len) {
+ GBool zeroFill, int width, int base,
+ char **p, int *len) {
+#endif
static char vals[17] = "0123456789abcdef";
GBool neg;
int start, i, j;
@@ -549,9 +627,15 @@ void GooString::formatInt(long x, char *buf, int bufSize,
*len = bufSize - i;
}
+#ifdef ULLONG_MAX
+void GooString::formatUInt(unsigned long long x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len) {
+#else
void GooString::formatUInt(Gulong x, char *buf, int bufSize,
- GBool zeroFill, int width, int base,
- const char **p, int *len) {
+ GBool zeroFill, int width, int base,
+ char **p, int *len) {
+#endif
static char vals[17] = "0123456789abcdef";
int i, j;
@@ -574,7 +658,7 @@ void GooString::formatUInt(Gulong x, char *buf, int bufSize,
}
void GooString::formatDouble(double x, char *buf, int bufSize, int prec,
- GBool trim, const char **p, int *len) {
+ GBool trim, char **p, int *len) {
GBool neg, started;
double x2;
int d, i, j;
@@ -613,7 +697,7 @@ void GooString::formatDouble(double x, char *buf, int bufSize, int prec,
}
void GooString::formatDoubleSmallAware(double x, char *buf, int bufSize, int prec,
- GBool trim, const char **p, int *len)
+ GBool trim, char **p, int *len)
{
double absX = fabs(x);
if (absX >= 0.1) {
diff --git a/goo/GooString.h b/goo/GooString.h
index aac7872..ee9fb2c 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -31,6 +31,7 @@
#pragma interface
#endif
+#include <limits.h> // for LLONG_MAX and ULLONG_MAX
#include <stdarg.h>
#include <stdlib.h> // for NULL
#include "gtypes.h"
@@ -82,10 +83,12 @@ public:
// d, x, o, b -- int in decimal, hex, octal, binary
// ud, ux, uo, ub -- unsigned int
// ld, lx, lo, lb, uld, ulx, ulo, ulb -- long, unsigned long
+ // lld, llx, llo, llb, ulld, ullx, ullo, ullb
+ // -- long long, unsigned long long
// f, g -- double
// c -- char
// s -- string (char *)
- // t -- GooString *
+ // t -- GString *
// w -- blank space; arg determines width
// To get literal curly braces, use {{ or }}.
static GooString *format(const char *fmt, ...);
@@ -164,16 +167,28 @@ private:
char *s;
void resize(int newLength);
+#ifdef LLONG_MAX
+ static void formatInt(long long x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len);
+#else
static void formatInt(long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
const char **p, int *len);
+#endif
+#ifdef ULLONG_MAX
+ static void formatUInt(unsigned long long x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len);
+#else
static void formatUInt(Gulong x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
const char **p, int *len);
+#endif
static void formatDouble(double x, char *buf, int bufSize, int prec,
- GBool trim, const char **p, int *len);
+ GBool trim, char **p, int *len);
static void formatDoubleSmallAware(double x, char *buf, int bufSize, int prec,
- GBool trim, const char **p, int *len);
+ GBool trim, char **p, int *len);
};
#endif
More information about the poppler
mailing list