diff options
Diffstat (limited to 'FoundationEx/Text.cpp')
-rw-r--r-- | FoundationEx/Text.cpp | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/FoundationEx/Text.cpp b/FoundationEx/Text.cpp index 972db7f..a09f333 100644 --- a/FoundationEx/Text.cpp +++ b/FoundationEx/Text.cpp @@ -12,8 +12,9 @@ */ #include "Text.h" -#include "stdio.h" -#include <ctype.h> + +#include <cctype> +#include <cstring> // +-------------------------------------------------------------------+ // SPECIAL TEXT REP FOR NULL STRINGS @@ -28,7 +29,7 @@ TextRep::TextRep() data = new char[4]; if (data) - ZeroMemory(data, 4); + std::memset(data, 0, 4); } // +-------------------------------------------------------------------+ @@ -37,12 +38,12 @@ TextRep::TextRep() TextRep::TextRep(const char* s) : ref(1), length(0), sensitive(true) { - if (s) length = ::strlen(s); + if (s) length = std::strlen(s); data = new char[length+1]; if (data) { - if (s) ::strcpy(data, s); + if (s) std::strcpy(data, s); else data[length] = '\0'; dohash(); @@ -57,7 +58,7 @@ TextRep::TextRep(const char* s, int len) data = new char[length+1]; if (data) { - ::CopyMemory(data, s, length); + std::memcpy(data, s, length); data[length] = '\0'; dohash(); } @@ -71,7 +72,7 @@ TextRep::TextRep(char c, int len) data = new char[length+1]; if (data) { - ::FillMemory(data, length, c); + std::memset(data, c, length); data[length] = '\0'; dohash(); } @@ -88,7 +89,7 @@ TextRep::TextRep(const TextRep* rep) sensitive = rep->sensitive; if (data) - ::strcpy(data, rep->data); + std::strcpy(data, rep->data); } TextRep::~TextRep() @@ -239,7 +240,7 @@ Text::operator+(char c) char* buf = new char[rep->length + 2]; if (buf) { - ::strcpy(buf, sym); + std::strcpy(buf, sym); buf[rep->length] = c; buf[rep->length+1] = '\0'; Text retval(buf); @@ -255,11 +256,11 @@ Text::operator+(char c) Text Text::operator+(const char* s) { - char* buf = new char[::strlen(s) + rep->length + 1]; + char* buf = new char[std::strlen(s) + rep->length + 1]; if (buf) { - ::strcpy(buf, sym); - ::strcat(buf, s); + std::strcpy(buf, sym); + std::strcat(buf, s); Text retval(buf); delete [] buf; return retval; @@ -276,8 +277,8 @@ Text::operator+(const Text& s) char* buf = new char[s.rep->length + rep->length + 1]; if (buf) { - ::strcpy(buf, sym); - ::strcat(buf, s.sym); + std::strcpy(buf, sym); + std::strcat(buf, s.sym); Text retval(buf); delete [] buf; return retval; @@ -306,7 +307,7 @@ Text::append(char c) char* buf = new char[rep->length + 2]; if (buf) { - ::strcpy(buf, sym); + std::strcpy(buf, sym); buf[rep->length] = c; buf[rep->length+1] = '\0'; if (rep->deref() == 0) delete rep; @@ -326,11 +327,11 @@ Text::append(char c) Text& Text::append(const char* s) { - char* buf = new char[::strlen(s) + rep->length + 1]; + char* buf = new char[std::strlen(s) + rep->length + 1]; if (buf) { - ::strcpy(buf, sym); - ::strcat(buf, s); + std::strcpy(buf, sym); + std::strcat(buf, s); if (rep->deref() == 0) delete rep; rep = new TextRep(buf); @@ -354,8 +355,8 @@ Text::append(const Text& s) int lenA = rep->length; int lenB = s.rep->length; - CopyMemory(buf, sym, lenA); - CopyMemory(buf + lenA, s.sym, lenB); + std::memcpy(buf, sym, lenA); + std::memcpy(buf + lenA, s.sym, lenB); buf[lenA + lenB] = 0; if (rep->deref() == 0) delete rep; @@ -438,7 +439,7 @@ Text::operator()(int start, int len) const char* buf = new char[len+1]; if (buf) { - ::strncpy(buf, sym+start, len); + std::strncpy(buf, sym+start, len); buf[len] = '\0'; Text retval(buf); @@ -455,14 +456,14 @@ Text::contains(char c) const if (rep->length > 0) { if (!rep->sensitive) { char alt = c; - if (islower(alt)) alt = toupper(alt); - else if (isupper(alt)) alt = tolower(alt); + if (std::islower(alt)) alt = std::toupper(alt); + else if (std::isupper(alt)) alt = std::tolower(alt); - if (strchr(rep->data, alt) != 0) + if (std::strchr(rep->data, alt) != 0) return true; } - if (strchr(rep->data, c) != 0) + if (std::strchr(rep->data, c) != 0) return true; } @@ -474,7 +475,7 @@ Text::contains(const char* pattern) const { if (rep->length > 0 && pattern && *pattern) { if (rep->sensitive) { - if (strstr(rep->data, pattern) != 0) + if (std::strstr(rep->data, pattern) != 0) return true; } else { @@ -483,7 +484,7 @@ Text::contains(const char* pattern) const Text smash2(pattern); smash2.toLower(); - if (strstr(smash1.data(), smash2.data()) != 0) + if (std::strstr(smash1.data(), smash2.data()) != 0) return true; } } @@ -519,16 +520,16 @@ Text::indexOf(char c) const if (rep->length > 0) { if (!rep->sensitive) { char alt = c; - if (islower(alt)) alt = toupper(alt); - else if (isupper(alt)) alt = tolower(alt); + if (std::islower(alt)) alt = std::toupper(alt); + else if (std::isupper(alt)) alt = std::tolower(alt); - const char* p = strchr(rep->data, alt); + const char* p = std::strchr(rep->data, alt); if (p) return (p - rep->data); } - const char* p = strchr(rep->data, c); + const char* p = std::strchr(rep->data, c); if (p) return (p - rep->data); @@ -542,7 +543,7 @@ Text::indexOf(const char* pattern) const { if (rep->length > 0 && pattern && *pattern) { if (rep->sensitive) { - const char* p = strstr(rep->data, pattern); + const char* p = std::strstr(rep->data, pattern); if (p) return (p - rep->data); } else { @@ -551,7 +552,7 @@ Text::indexOf(const char* pattern) const Text smash2(pattern); smash2.toLower(); - const char* p = strstr(smash1.data(), smash2.data()); + const char* p = std::strstr(smash1.data(), smash2.data()); if (p) return (p - smash1.data()); } } @@ -566,7 +567,7 @@ Text::toLower() size_t n = rep->length; char* p = (char*) sym; while (n--) { - *p = tolower((unsigned char)*p); + *p = std::tolower((unsigned char)*p); p++; } @@ -580,7 +581,7 @@ Text::toUpper() size_t n = rep->length; char* p = (char*) sym; while ( n-- ) { - *p = toupper((unsigned char)*p); + *p = std::toupper((unsigned char)*p); p++; } @@ -634,9 +635,9 @@ Text::replace(const char* pattern, const char* substitution) if (rep->length && pattern && *pattern) { int index = 0; - int skip = strlen(pattern); + int skip = std::strlen(pattern); do { - const char* p = strstr(rep->data + index, pattern); + const char* p = std::strstr(rep->data + index, pattern); if (p) { int len = (p - rep->data + index); result.append(substring(index, len)); |