X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fxpdf%2FGString.cc;h=049dcf38dc93b88a99e82a4dc9c092ab818c8391;hb=c26ca847941ca0acfc9f3b4bdc519d904ba09a39;hp=7b8f271840752d8252cfcd355faccc7028881b25;hpb=fc554a43712b76d16b41ec77dd311b4a78b1ef6b;p=swftools.git diff --git a/pdf2swf/xpdf/GString.cc b/pdf2swf/xpdf/GString.cc index 7b8f271..049dcf3 100644 --- a/pdf2swf/xpdf/GString.cc +++ b/pdf2swf/xpdf/GString.cc @@ -4,11 +4,13 @@ // // Simple variable-length string type. // -// Copyright 1996 Derek B. Noonburg +// Copyright 1996-2003 Glyph & Cog, LLC // //======================================================================== -#ifdef __GNUC__ +#include + +#ifdef USE_GCC_PRAGMAS #pragma implementation #endif @@ -33,7 +35,12 @@ inline void GString::resize(int length1) { s = new char[size(length1)]; } else if (size(length1) != size(length)) { s1 = new char[size(length1)]; - memcpy(s1, s, length + 1); + if (length1 < length) { + memcpy(s1, s, length1); + s1[length1] = '\0'; + } else { + memcpy(s1, s, length + 1); + } delete[] s; s = s1; } @@ -45,18 +52,25 @@ GString::GString() { s[0] = '\0'; } -GString::GString(const char *s1) { - int n = strlen(s1); +GString::GString(const char *sA) { + int n = strlen(sA); s = NULL; resize(length = n); - memcpy(s, s1, n + 1); + memcpy(s, sA, n + 1); } -GString::GString(const char *s1, int length1) { +GString::GString(const char *sA, int lengthA) { s = NULL; - resize(length = length1); - memcpy(s, s1, length * sizeof(char)); + resize(length = lengthA); + memcpy(s, sA, length * sizeof(char)); + s[length] = '\0'; +} + +GString::GString(GString *str, int idx, int lengthA) { + s = NULL; + resize(length = lengthA); + memcpy(s, str->getCString() + idx, length); s[length] = '\0'; } @@ -137,10 +151,10 @@ GString *GString::append(const char *str) { return this; } -GString *GString::append(const char *str, int length1) { - resize(length + length1); - memcpy(s + length, str, length1); - length += length1; +GString *GString::append(const char *str, int lengthA) { + resize(length + lengthA); + memcpy(s + length, str, lengthA); + length += lengthA; s[length] = '\0'; return this; } @@ -180,14 +194,14 @@ GString *GString::insert(int i, const char *str) { return this; } -GString *GString::insert(int i, const char *str, int length1) { +GString *GString::insert(int i, const char *str, int lengthA) { int j; - resize(length + length1); + resize(length + lengthA); for (j = length; j >= i; --j) - s[j+length1] = s[j]; - memcpy(s+i, str, length1); - length += length1; + s[j+lengthA] = s[j]; + memcpy(s+i, str, lengthA); + length += lengthA; return this; } @@ -195,8 +209,12 @@ GString *GString::del(int i, int n) { int j; if (n > 0) { - for (j = i; j <= length - n; ++j) + if (i + n > length) { + n = length - i; + } + for (j = i; j <= length - n; ++j) { s[j] = s[j + n]; + } resize(length -= n); } return this; @@ -221,3 +239,81 @@ GString *GString::lowerCase() { } return this; } + +int GString::cmp(GString *str) { + int n1, n2, i, x; + char *p1, *p2; + + n1 = length; + n2 = str->length; + for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) { + x = *p1 - *p2; + if (x != 0) { + return x; + } + } + return n1 - n2; +} + +int GString::cmpN(GString *str, int n) { + int n1, n2, i, x; + char *p1, *p2; + + n1 = length; + n2 = str->length; + for (i = 0, p1 = s, p2 = str->s; + i < n1 && i < n2 && i < n; + ++i, ++p1, ++p2) { + x = *p1 - *p2; + if (x != 0) { + return x; + } + } + if (i == n) { + return 0; + } + return n1 - n2; +} + +int GString::cmp(const char *sA) { + int n1, i, x; + const char *p1, *p2; + + n1 = length; + for (i = 0, p1 = s, p2 = sA; i < n1 && *p2; ++i, ++p1, ++p2) { + x = *p1 - *p2; + if (x != 0) { + return x; + } + } + if (i < n1) { + return 1; + } + if (*p2) { + return -1; + } + return 0; +} + +int GString::cmpN(const char *sA, int n) { + int n1, i, x; + const char *p1, *p2; + + n1 = length; + for (i = 0, p1 = s, p2 = sA; i < n1 && *p2 && i < n; ++i, ++p1, ++p2) { + x = *p1 - *p2; + if (x != 0) { + return x; + } + } + if (i == n) { + return 0; + } + if (i < n1) { + return 1; + } + if (*p2) { + return -1; + } + return 0; +}