]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Converted the String implementation itself
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 29 Jan 2009 16:14:07 +0000 (17:14 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 29 Jan 2009 16:14:07 +0000 (17:14 +0100)
src/String.cc
src/String.cci

index b423424b139e4f0655cee943fc33e6af60f5e419..4f6bcba94930a7e02ad0e0aeff5a3f83332fa2e3 100644 (file)
@@ -42,7 +42,7 @@ void
 String::allocBuffer(size_t sz)
 {
     PROF_start(StringInitBuf);
-    assert (buf_ == NULL);
+    assert (undefined());
     char *newBuffer = (char*)memAllocString(sz, &sz);
     setBuffer(newBuffer, sz);
     PROF_stop(StringInitBuf);
@@ -53,7 +53,7 @@ String::allocBuffer(size_t sz)
 void
 String::setBuffer(char *aBuf, size_t aSize)
 {
-    assert(!buf_);
+    assert(undefined());
     assert(aSize < 65536);
     buf_ = aBuf;
     size_ = aSize;
@@ -81,7 +81,7 @@ String::operator = (String const &old)
 {
     clean(); // TODO: optimize to avoid cleaning the buffer we can use
     if (old.size() > 0)
-        allocAndFill(old.unsafeBuf(), old.size());
+        allocAndFill(old.rawBuf(), old.size());
     return *this;
 }
 
@@ -128,7 +128,7 @@ String::allocAndFill(const char *str, int len)
 String::String (String const &old) : size_(0), len_(0), buf_(NULL)
 {
     if (old.size() > 0)
-        allocAndFill(old.unsafeBuf(), old.size());
+        allocAndFill(old.rawBuf(), old.size());
 #if DEBUGSTRINGS
 
     StringRegistry::Instance().add(this);
@@ -141,7 +141,7 @@ String::clean()
     PROF_start(StringClean);
     assert(this);
 
-    if (unsafeBuf())
+    if (defined())
         memFreeString(size_, buf_);
 
     len_ = 0;
@@ -219,7 +219,7 @@ String::append (char chr)
 void
 String::append(String const &old)
 {
-    append (old.unsafeBuf(), old.len_);
+    append (old.rawBuf(), old.len_);
 }
 
 void
@@ -237,7 +237,7 @@ String::absorb(String &old)
 void
 String::stat(StoreEntry *entry) const
 {
-    storeAppendPrintf(entry, "%p : %d/%d \"%s\"\n",this,len_, size_, unsafeBuf());
+    storeAppendPrintf(entry, "%p : %d/%d \"%.*s\"\n",this,len_, size_, size(), rawBuf());
 }
 
 StringRegistry &
index e0f3a90eb867183fbac0b1c6f8000fc5c66d551d..6c75dc628d92e9c308771a7232474dd4b70df414 100644 (file)
@@ -87,19 +87,19 @@ String::operator [](unsigned int pos)
 const char *
 String::pos(char const *aString) const
 {
-    return strstr(unsafeBuf(), aString);
+    return strstr(termedBuf(), aString);
 }
 
 const char *
 String::pos(char const ch) const
 {
-    return strchr(unsafeBuf(), ch);
+    return strchr(termedBuf(), ch);
 }
 
 const char *
 String::rpos(char const ch) const
 {
-    return strrchr(unsafeBuf(), (ch));
+    return strrchr(termedBuf(), (ch));
 }
 
 int
@@ -116,7 +116,7 @@ String::cmp (char const *aString) const
     if (aString == NULL || aString[0] == '\0')
         return 1;
 
-    return strcmp(unsafeBuf(), aString);
+    return strcmp(termedBuf(), aString);
 }
 
 int
@@ -136,7 +136,7 @@ String::cmp (char const *aString, size_t count) const
     if (aString == NULL || aString[0] == '\0')
         return 1;
 
-    return strncmp(unsafeBuf(), aString, count);
+    return strncmp(termedBuf(), aString, count);
 }
 
 int
@@ -153,19 +153,19 @@ String::cmp (String const &aString) const
     if (aString.size() == 0)
         return 1;
 
-    return strcmp(unsafeBuf(), aString.unsafeBuf());
+    return strcmp(termedBuf(), aString.termedBuf());
 }
 
 int
 String::caseCmp(char const *aString) const
 {
-    return strcasecmp(unsafeBuf(), aString);
+    return strcasecmp(termedBuf(), aString);
 }
 
 int
 String::caseCmp(char const *aString, size_t count) const
 {
-    return strncasecmp(unsafeBuf(), aString, count);
+    return strncasecmp(termedBuf(), aString, count);
 }
 
 void
@@ -201,6 +201,6 @@ String::cutPointer(char const *loc)
 std::ostream &
 operator<<(std::ostream& os, String const &aString)
 {
-    os << aString.unsafeBuf();
+    os.write(aString.rawBuf(),aString.size());
     return os;
 }