summaryrefslogtreecommitdiffhomepage
path: root/FoundationEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-03-27 22:40:16 +0200
committerAki <please@ignore.pl>2022-03-27 22:40:16 +0200
commita8c5ec05320d58347ed434964e05818b082f00b4 (patch)
tree27fdd593b874f00a3d95349ee588e115c74a4cc7 /FoundationEx
parent1cf689a6ad9d6c5cd29e11a6a96cb075eb2bbbb8 (diff)
downloadstarshatter-a8c5ec05320d58347ed434964e05818b082f00b4.zip
starshatter-a8c5ec05320d58347ed434964e05818b082f00b4.tar.gz
starshatter-a8c5ec05320d58347ed434964e05818b082f00b4.tar.bz2
Moved FoundationEx closer to c++ standard
It now builds with gcc on Linux
Diffstat (limited to 'FoundationEx')
-rw-r--r--FoundationEx/Text.cpp75
-rw-r--r--FoundationEx/Text.h14
-rw-r--r--FoundationEx/Utils.cpp2
3 files changed, 51 insertions, 40 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));
diff --git a/FoundationEx/Text.h b/FoundationEx/Text.h
index 0ade946..736c6b9 100644
--- a/FoundationEx/Text.h
+++ b/FoundationEx/Text.h
@@ -15,10 +15,12 @@
#define Text_h
#include <atomic>
+#include <cstring>
#include <ostream>
-#include <string.h>
-#include <windows.h>
+#ifndef _WIN32
+#include <strings.h>
+#endif
// +-------------------------------------------------------------------+
@@ -138,7 +140,11 @@ inline int Text::compare(const char* s) const
if (rep->sensitive)
return strcmp(sym, s);
else
+#ifdef _WIN32
return _stricmp(sym, s);
+#else
+ return strcasecmp(sym, s);
+#endif
}
inline int Text::compare(const Text& s) const
@@ -146,7 +152,11 @@ inline int Text::compare(const Text& s) const
if (rep->sensitive && s.rep->sensitive)
return strcmp(sym, s.sym);
else
+#ifdef _WIN32
return _stricmp(sym, s.sym);
+#else
+ return strcasecmp(sym, s.sym);
+#endif
}
// +-------------------------------------------------------------------+
diff --git a/FoundationEx/Utils.cpp b/FoundationEx/Utils.cpp
index b030678..d666b7d 100644
--- a/FoundationEx/Utils.cpp
+++ b/FoundationEx/Utils.cpp
@@ -30,7 +30,7 @@ void Print(const char* fmt, ...)
if (!ErrLog) return;
va_list args;
va_start(args, fmt);
- vfprintf_s(ErrLog, fmt, args);
+ vfprintf(ErrLog, fmt, args);
fflush(ErrLog);
va_end(args);
}