]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/goo/GString.cc
Enanche the find interface to be really able to do multi page find.
[evince.git] / pdf / goo / GString.cc
index e0890912d5b495a1ecb6a7c84d1f0023ddde094b..7653fd06e3e6b1dd2d1ed30f6321dba2e069a22b 100644 (file)
@@ -4,11 +4,13 @@
 //
 // Simple variable-length string type.
 //
 //
 // Simple variable-length string type.
 //
-// Copyright 1996 Derek B. Noonburg
+// Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
 //
 //========================================================================
 
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
 #pragma implementation
 #endif
 
 #pragma implementation
 #endif
 
@@ -16,6 +18,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <ctype.h>
 #include <stddef.h>
 #include <string.h>
 #include <ctype.h>
+#include "gtypes.h"
 #include "GString.h"
 
 static inline int size(int len) {
 #include "GString.h"
 
 static inline int size(int len) {
@@ -44,18 +47,25 @@ GString::GString() {
   s[0] = '\0';
 }
 
   s[0] = '\0';
 }
 
-GString::GString(char *s1) {
-  int n = strlen(s1);
+GString::GString(const char *sA) {
+  int n = strlen(sA);
 
   s = NULL;
   resize(length = n);
 
   s = NULL;
   resize(length = n);
-  memcpy(s, s1, n + 1);
+  memcpy(s, sA, n + 1);
+}
+
+GString::GString(const char *sA, int lengthA) {
+  s = NULL;
+  resize(length = lengthA);
+  memcpy(s, sA, length * sizeof(char));
+  s[length] = '\0';
 }
 
 }
 
-GString::GString(char *s1, int length1) {
+GString::GString(GString *str, int idx, int lengthA) {
   s = NULL;
   s = NULL;
-  resize(length = length1);
-  memcpy(s, s1, length * sizeof(char));
+  resize(length = lengthA);
+  memcpy(s, str->getCString() + idx, length);
   s[length] = '\0';
 }
 
   s[length] = '\0';
 }
 
@@ -75,6 +85,32 @@ GString::GString(GString *str1, GString *str2) {
   memcpy(s + n1, str2->getCString(), n2 + 1);
 }
 
   memcpy(s + n1, str2->getCString(), n2 + 1);
 }
 
+GString *GString::fromInt(int x) {
+  char buf[24]; // enough space for 64-bit ints plus a little extra
+  GBool neg;
+  Guint y;
+  int i;
+
+  i = 24;
+  if (x == 0) {
+    buf[--i] = '0';
+  } else {
+    if ((neg = x < 0)) {
+      y = (Guint)-x;
+    } else {
+      y = (Guint)x;
+    }
+    while (i > 0 && y > 0) {
+      buf[--i] = '0' + y % 10;
+      y /= 10;
+    }
+    if (neg && i > 0) {
+      buf[--i] = '-';
+    }
+  }
+  return new GString(buf + i, 24 - i);
+}
+
 GString::~GString() {
   delete[] s;
 }
 GString::~GString() {
   delete[] s;
 }
@@ -101,7 +137,7 @@ GString *GString::append(GString *str) {
   return this;
 }
 
   return this;
 }
 
-GString *GString::append(char *str) {
+GString *GString::append(const char *str) {
   int n = strlen(str);
 
   resize(length + n);
   int n = strlen(str);
 
   resize(length + n);
@@ -110,10 +146,10 @@ GString *GString::append(char *str) {
   return this;
 }
 
   return this;
 }
 
-GString *GString::append(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;
 }
   s[length] = '\0';
   return this;
 }
@@ -141,7 +177,7 @@ GString *GString::insert(int i, GString *str) {
   return this;
 }
 
   return this;
 }
 
-GString *GString::insert(int i, char *str) {
+GString *GString::insert(int i, const char *str) {
   int n = strlen(str);
   int j;
 
   int n = strlen(str);
   int j;
 
@@ -153,14 +189,14 @@ GString *GString::insert(int i, char *str) {
   return this;
 }
 
   return this;
 }
 
-GString *GString::insert(int i, char *str, int length1) {
+GString *GString::insert(int i, const char *str, int lengthA) {
   int j;
 
   int j;
 
-  resize(length + length1);
+  resize(length + lengthA);
   for (j = length; j >= i; --j)
   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;
 }
 
   return this;
 }
 
@@ -168,8 +204,12 @@ GString *GString::del(int i, int n) {
   int j;
 
   if (n > 0) {
   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];
       s[j] = s[j + n];
+    }
     resize(length -= n);
   }
   return this;
     resize(length -= n);
   }
   return this;