summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-27 19:58:24 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-27 19:58:24 +0200
commitb40ba0cf91603b695f1f2380cbd39966a458f22f (patch)
tree1fec48ddc59eb1392fac38495b230e4b2cbf7528 /src/Core
parente1d8490f0654a3da0b900407d80d91d8d0da68c8 (diff)
downloadmad-b40ba0cf91603b695f1f2380cbd39966a458f22f.tar
mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.zip
Use Unicode-aware String class instead of std::string
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/CMakeLists.txt2
-rw-r--r--src/Core/ConfigEntry.cpp4
-rw-r--r--src/Core/ConfigEntry.h14
-rw-r--r--src/Core/ConfigManager.cpp6
-rw-r--r--src/Core/Exception.h2
-rw-r--r--src/Core/LogManager.cpp14
-rw-r--r--src/Core/LogManager.h4
-rw-r--r--src/Core/String.cpp (renamed from src/Core/UnicodeString.cpp)8
-rw-r--r--src/Core/String.h88
-rw-r--r--src/Core/Tokenizer.cpp14
-rw-r--r--src/Core/Tokenizer.h8
-rw-r--r--src/Core/UnicodeString.h64
12 files changed, 123 insertions, 105 deletions
diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt
index 9828f61..60a5a25 100644
--- a/src/Core/CMakeLists.txt
+++ b/src/Core/CMakeLists.txt
@@ -20,7 +20,7 @@ mad_library(Core
LogManager.cpp LogManager.h
Signals.h
ThreadManager.cpp ThreadManager.h
+ String.cpp String.h
Tokenizer.cpp Tokenizer.h
- UnicodeString.cpp UnicodeString.h
)
target_link_libraries(Core ${Boost_LIBRARIES} ${ICU_LIBRARIES})
diff --git a/src/Core/ConfigEntry.cpp b/src/Core/ConfigEntry.cpp
index b587043..04ed08f 100644
--- a/src/Core/ConfigEntry.cpp
+++ b/src/Core/ConfigEntry.cpp
@@ -22,7 +22,7 @@
namespace Mad {
namespace Core {
-ConfigEntry::String& ConfigEntry::Entry::operator[] (std::size_t i) {
+String& ConfigEntry::Entry::operator[] (std::size_t i) {
try {
return value.at(i);
}
@@ -32,7 +32,7 @@ ConfigEntry::String& ConfigEntry::Entry::operator[] (std::size_t i) {
}
}
-const ConfigEntry::String& ConfigEntry::Entry::operator[] (std::size_t i) const {
+const String& ConfigEntry::Entry::operator[] (std::size_t i) const {
try {
return value.at(i);
}
diff --git a/src/Core/ConfigEntry.h b/src/Core/ConfigEntry.h
index d4cacc9..26e77d2 100644
--- a/src/Core/ConfigEntry.h
+++ b/src/Core/ConfigEntry.h
@@ -22,7 +22,7 @@
#include "export.h"
-#include "UnicodeString.h"
+#include "String.h"
#include <stdexcept>
#include <vector>
@@ -32,16 +32,6 @@ namespace Core {
class MAD_CORE_EXPORT ConfigEntry {
public:
- class String : public UnicodeString {
- public:
- String() {}
- String(const UnicodeString &str) : UnicodeString(str) {}
-
- bool matches(const UnicodeString &str) const {
- return (str.caseCompare(*this, 0) == 0);
- }
- };
-
class MAD_CORE_EXPORT Entry {
private:
String key;
@@ -51,7 +41,7 @@ class MAD_CORE_EXPORT ConfigEntry {
public:
Entry() {}
- Entry(const std::vector<UnicodeString> &args) {
+ Entry(const std::vector<String> &args) {
if(args.empty())
return;
diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp
index 51d8647..d79ce32 100644
--- a/src/Core/ConfigManager.cpp
+++ b/src/Core/ConfigManager.cpp
@@ -26,6 +26,8 @@
#include <fstream>
#include <stdexcept>
+#include <iostream>
+
namespace Mad {
namespace Core {
@@ -55,9 +57,9 @@ bool ConfigManager::loadFile(const std::string &filename) {
std::ifstream file(filename.c_str());
ConfigEntry entry;
- UnicodeString line, input;
+ String line, input;
UChar delim;
- std::vector<UnicodeString> splitLine, lastConfigLine;
+ std::vector<String> splitLine, lastConfigLine;
if(!file.good())
return false;
diff --git a/src/Core/Exception.h b/src/Core/Exception.h
index f12b3df..8e0342d 100644
--- a/src/Core/Exception.h
+++ b/src/Core/Exception.h
@@ -22,6 +22,8 @@
#include "export.h"
+#include "String.h"
+
#include <exception>
#include <string>
diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp
index 4a4cc0d..c2a90de 100644
--- a/src/Core/LogManager.cpp
+++ b/src/Core/LogManager.cpp
@@ -42,13 +42,13 @@ void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, M
}
-LogManager::MessageLevel LogManager::parseLevel(const UnicodeString &str) throw (Exception) {
- static const UnicodeString DEBUG_LEVEL("debug");
- static const UnicodeString VERBOSE_LEVEL("verbose");
- static const UnicodeString DEFAULT_LEVEL("default");
- static const UnicodeString WARNING_LEVEL("warning");
- static const UnicodeString ERROR_LEVEL("error");
- static const UnicodeString CRITICAL_LEVEL("critical");
+LogManager::MessageLevel LogManager::parseLevel(const String &str) throw (Exception) {
+ static const String DEBUG_LEVEL("debug");
+ static const String VERBOSE_LEVEL("verbose");
+ static const String DEFAULT_LEVEL("default");
+ static const String WARNING_LEVEL("warning");
+ static const String ERROR_LEVEL("error");
+ static const String CRITICAL_LEVEL("critical");
if(str.isEmpty())
return Logger::LOG_DEFAULT;
diff --git a/src/Core/LogManager.h b/src/Core/LogManager.h
index 9b47a7e..4f7c500 100644
--- a/src/Core/LogManager.h
+++ b/src/Core/LogManager.h
@@ -25,7 +25,7 @@
#include "Configurable.h"
#include "Exception.h"
#include "Logger.h"
-#include "UnicodeString.h"
+#include "String.h"
#include <queue>
#include <set>
@@ -100,7 +100,7 @@ class MAD_CORE_EXPORT LogManager : public Configurable {
virtual void configFinished();
public:
- static MessageLevel parseLevel(const UnicodeString &str) throw (Exception);
+ static MessageLevel parseLevel(const String &str) throw (Exception);
void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source = std::string());
diff --git a/src/Core/UnicodeString.cpp b/src/Core/String.cpp
index ccace47..d9d357e 100644
--- a/src/Core/UnicodeString.cpp
+++ b/src/Core/String.cpp
@@ -1,5 +1,5 @@
/*
- * UnicodeString.cpp
+ * String.cpp
*
* Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
*
@@ -17,12 +17,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "UnicodeString.h"
+#include "String.h"
namespace Mad {
namespace Core {
-boost::int32_t UnicodeString::findFirstOf(const UnicodeString &chars, boost::int32_t start) const {
+boost::int32_t String::findFirstOf(const String &chars, boost::int32_t start) const {
for(boost::int32_t i = start; i < length(); ++i) {
if(chars.indexOf(charAt(i)) >= 0)
return i;
@@ -31,7 +31,7 @@ boost::int32_t UnicodeString::findFirstOf(const UnicodeString &chars, boost::int
return -1;
}
-boost::int32_t UnicodeString::findFirstNotOf(const UnicodeString &chars, boost::int32_t start) const {
+boost::int32_t String::findFirstNotOf(const String &chars, boost::int32_t start) const {
for(boost::int32_t i = start; i < length(); ++i) {
if(chars.indexOf(charAt(i)) < 0)
return i;
diff --git a/src/Core/String.h b/src/Core/String.h
new file mode 100644
index 0000000..1c93902
--- /dev/null
+++ b/src/Core/String.h
@@ -0,0 +1,88 @@
+/*
+ * String.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_STRING_H_
+#define MAD_CORE_STRING_H_
+
+#include "export.h"
+
+#include <ostream>
+#include <string>
+#include <boost/cstdint.hpp>
+#include <boost/scoped_array.hpp>
+
+#define U_USING_ICU_NAMESPACE 0
+#include <unicode/unistr.h>
+
+namespace Mad {
+namespace Core {
+
+class MAD_CORE_EXPORT String : public icu::UnicodeString {
+ private:
+ std::string extractCodepage(const char *codepage) const {
+ boost::uint32_t len = static_cast<boost::uint32_t>(icu::UnicodeString::extract(0, length(), 0, codepage));
+
+ boost::scoped_array<char> buf(new char[len]);
+ icu::UnicodeString::extract(0, length(), buf.get(), len, codepage);
+
+ return std::string(buf.get(), len);
+ }
+
+ public:
+ String() {}
+ String(const icu::UnicodeString &str) : icu::UnicodeString(str) {}
+ String(const char *str) : icu::UnicodeString(str, -1, US_INV) {}
+
+ String substr(boost::int32_t start, boost::int32_t length = -1) const {
+ if(length < 0)
+ return icu::UnicodeString(*this, start);
+ else
+ return icu::UnicodeString(*this, start, length);
+ }
+
+ bool matches(const String &str) const {
+ return (str.caseCompare(*this, 0) == 0);
+ }
+
+ boost::int32_t findFirstOf(const String &chars, boost::int32_t start = 0) const;
+ boost::int32_t findFirstNotOf(const String &chars, boost::int32_t start = 0) const;
+
+ std::string extract() const {
+ return extractCodepage(0);
+ }
+
+ std::string extractUTF8() const {
+ return extractCodepage("UTF-8");
+ }
+
+ static String fromUTF8(const char *str) {
+ return icu::UnicodeString(str, "UTF-8");
+ }
+};
+
+template<typename ElemType, typename Traits>
+std::basic_ostream<ElemType, Traits>& operator<<(std::basic_ostream<ElemType, Traits> &stream, const String &string) {
+ stream << string.extract();
+ return stream;
+}
+
+}
+}
+
+#endif /* MAD_CORE_STRING_H_ */
diff --git a/src/Core/Tokenizer.cpp b/src/Core/Tokenizer.cpp
index 93c853a..9e0553e 100644
--- a/src/Core/Tokenizer.cpp
+++ b/src/Core/Tokenizer.cpp
@@ -24,11 +24,11 @@
namespace Mad {
namespace Core {
-const UnicodeString Tokenizer::delimiters(" \t\n\"'\\");
+const String Tokenizer::delimiters(" \t\n\"'\\");
-std::vector<UnicodeString> Tokenizer::split(const UnicodeString &str) {
- std::vector<UnicodeString> ret;
+std::vector<String> Tokenizer::split(const String &str) {
+ std::vector<String> ret;
for(boost::int32_t s = 0; s < str.length();) {
boost::int32_t index = str.findFirstOf(delimiters, s);
@@ -55,16 +55,16 @@ std::vector<UnicodeString> Tokenizer::split(const UnicodeString &str) {
return ret;
}
-bool Tokenizer::tokenize(const UnicodeString &str, std::vector<UnicodeString> &out) {
- std::vector<UnicodeString> splitString = split(str);
+bool Tokenizer::tokenize(const String &str, std::vector<String> &out) {
+ std::vector<String> splitString = split(str);
bool singleQuotes = false, doubleQuotes = false, escape = false;
- UnicodeString token;
+ String token;
bool forceToken = false;
out.clear();
- for(std::vector<UnicodeString>::iterator s = splitString.begin(); s != splitString.end(); ++s) {
+ for(std::vector<String>::iterator s = splitString.begin(); s != splitString.end(); ++s) {
token += *s;
escape = false;
diff --git a/src/Core/Tokenizer.h b/src/Core/Tokenizer.h
index f65d44c..fbeeeda 100644
--- a/src/Core/Tokenizer.h
+++ b/src/Core/Tokenizer.h
@@ -22,7 +22,7 @@
#include "export.h"
-#include "UnicodeString.h"
+#include "String.h"
#include <vector>
namespace Mad {
@@ -30,14 +30,14 @@ namespace Core {
class MAD_CORE_EXPORT Tokenizer {
private:
- static const UnicodeString delimiters;
+ static const String delimiters;
Tokenizer();
- static std::vector<UnicodeString> split(const UnicodeString &str);
+ static std::vector<String> split(const String &str);
public:
- static bool tokenize(const UnicodeString &str, std::vector<UnicodeString> &out);
+ static bool tokenize(const String &str, std::vector<String> &out);
};
}
diff --git a/src/Core/UnicodeString.h b/src/Core/UnicodeString.h
deleted file mode 100644
index aed53b6..0000000
--- a/src/Core/UnicodeString.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * UnicodeString.h
- *
- * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MAD_CORE_UNICODESTRING_H_
-#define MAD_CORE_UNICODESTRING_H_
-
-#include "export.h"
-
-#include <string>
-#include <boost/cstdint.hpp>
-#include <boost/scoped_array.hpp>
-
-#define U_USING_ICU_NAMESPACE 0
-#include <unicode/unistr.h>
-
-namespace Mad {
-namespace Core {
-
-class MAD_CORE_EXPORT UnicodeString : public icu::UnicodeString {
- public:
- UnicodeString() {}
- UnicodeString(const icu::UnicodeString &str) : icu::UnicodeString(str) {}
- UnicodeString(const char *str) : icu::UnicodeString(str) {}
-
- UnicodeString substr(boost::int32_t start, boost::int32_t length = -1) const {
- if(length < 0)
- return icu::UnicodeString(*this, start);
- else
- return icu::UnicodeString(*this, start, length);
- }
-
- boost::int32_t findFirstOf(const UnicodeString &chars, boost::int32_t start = 0) const;
- boost::int32_t findFirstNotOf(const UnicodeString &chars, boost::int32_t start = 0) const;
-
- std::string extract() const {
- boost::uint32_t len = (boost::uint32_t)icu::UnicodeString::extract(0, length(), (char*)0, 0u);
-
- boost::scoped_array<char> buf(new char[len]);
- icu::UnicodeString::extract(0, length(), buf.get(), len);
-
- return std::string(buf.get(), len);
- }
-};
-
-}
-}
-
-#endif /* MAD_CORE_UNICODESTRING_H_ */