]> Dogcows Code - chaz/yoink/blobdiff - src/moof/string.cc
the massive refactoring effort
[chaz/yoink] / src / moof / string.cc
similarity index 64%
rename from src/Moof/StringTools.cc
rename to src/moof/string.cc
index 34d2f61a72addb98bd2252a7f3f8a06e4bbb76ab..a2c27bb25cf3b670d9b04c66c498c55e53530f9e 100644 (file)
 #include <stdexcept>
 
 #include "ConvertUTF.h"
-#include "StringTools.hh"
+#include "string.hh"
 
 
-namespace Mf {
+namespace moof {
 
 
 // TODO this code is ugly
 
-std::wstring multiToWide(const std::string& multiStr)
+wstring multi_to_wide(const string& multi)
 {
-       size_t length = multiStr.length();
+       size_t length = multi.length();
 
        if (sizeof(wchar_t) == 2)
        {
-               wchar_t* wideStr = new wchar_t[length + 1];
+               wchar_t* wide = new wchar_t[length + 1];
 
-               const UTF8* srcStart = reinterpret_cast<const UTF8*>(multiStr.c_str());
+               const UTF8* srcStart = reinterpret_cast<const UTF8*>(multi.c_str());
                const UTF8* srcEnd = srcStart + length;
-               UTF16* targetStart = reinterpret_cast<UTF16*>(wideStr);
+               UTF16* targetStart = reinterpret_cast<UTF16*>(wide);
                UTF16* targetEnd = targetStart + length+1;
 
                ConversionResult res = ConvertUTF8toUTF16(&srcStart, srcEnd,
                                &targetStart, targetEnd, lenientConversion);
                if (res != conversionOK)
                {
-                       delete[] wideStr;
+                       delete[] wide;
                        throw std::runtime_error("bad conversion from multi to wide characters");
                }
 
                *targetStart = 0;
-               std::wstring convertedStr(wideStr);
-               delete[] wideStr;
+               wstring convertedStr(wide);
+               delete[] wide;
 
                return convertedStr;
        }
        else if (sizeof(wchar_t) == 4)
        {
-               wchar_t* wideStr = new wchar_t[length];
+               wchar_t* wide = new wchar_t[length];
 
-               const UTF8* srcStart = reinterpret_cast<const UTF8*>(multiStr.c_str());
+               const UTF8* srcStart = reinterpret_cast<const UTF8*>(multi.c_str());
                const UTF8* srcEnd = srcStart + length;
-               UTF32* targetStart = reinterpret_cast<UTF32*>(wideStr);
+               UTF32* targetStart = reinterpret_cast<UTF32*>(wide);
                UTF32* targetEnd = targetStart + length;
 
                ConversionResult res = ConvertUTF8toUTF32(&srcStart, srcEnd,
                                &targetStart, targetEnd, lenientConversion);
                if (res != conversionOK)
                {
-                       delete[] wideStr;
+                       delete[] wide;
                        throw std::runtime_error("bad conversion from multi to wide characters");
                }
 
                *targetStart = 0;
-               std::wstring convertedStr(wideStr);
-               delete[] wideStr;
+               wstring convertedStr(wide);
+               delete[] wide;
 
                return convertedStr;
        }
@@ -77,55 +77,55 @@ std::wstring multiToWide(const std::string& multiStr)
        return L"";
 }
 
-std::string wideToMulti(const std::wstring& wideStr)
+string wide_to_multi(const wstring& wide)
 {
-       size_t length = wideStr.length();
+       size_t length = wide.length();
 
        if (sizeof(wchar_t) == 2)
        {
                size_t multiLength = 3 * length + 1;
-               char* multiStr = new char[multiLength];
+               char* multi = new char[multiLength];
 
-               const UTF16* srcStart = reinterpret_cast<const UTF16*>(wideStr.c_str());
+               const UTF16* srcStart = reinterpret_cast<const UTF16*>(wide.c_str());
                const UTF16* srcEnd = srcStart + length;
-               UTF8* targetStart = reinterpret_cast<UTF8*>(multiStr);
+               UTF8* targetStart = reinterpret_cast<UTF8*>(multi);
                UTF8* targetEnd = targetStart + multiLength;
 
                ConversionResult res = ConvertUTF16toUTF8(&srcStart, srcEnd,
                                &targetStart, targetEnd, lenientConversion);
                if (res != conversionOK)
                {
-                       delete[] multiStr;
+                       delete[] multi;
                        throw std::runtime_error("bad conversion from wide to multi-characters");
                }
 
                *targetStart = 0;
-               std::string convertedStr(multiStr);
-               delete[] multiStr;
+               string convertedStr(multi);
+               delete[] multi;
 
                return convertedStr;
        }
        else if (sizeof(wchar_t) == 4)
        {
                size_t multiLength = 4 * length + 1;
-               char* multiStr = new char[multiLength];
+               char* multi = new char[multiLength];
 
-               const UTF32* srcStart = reinterpret_cast<const UTF32*>(wideStr.c_str());
+               const UTF32* srcStart = reinterpret_cast<const UTF32*>(wide.c_str());
                const UTF32* srcEnd = srcStart + length;
-               UTF8* targetStart = reinterpret_cast<UTF8*>(multiStr);
+               UTF8* targetStart = reinterpret_cast<UTF8*>(multi);
                UTF8* targetEnd = targetStart + multiLength;
 
                ConversionResult res = ConvertUTF32toUTF8(&srcStart, srcEnd,
                                &targetStart, targetEnd, lenientConversion);
                if (res != conversionOK)
                {
-                       delete[] multiStr;
+                       delete[] multi;
                        throw std::runtime_error("bad conversion from wide to multi-characters");
                }
 
                *targetStart = 0;
-               std::string convertedStr(multiStr);
-               delete[] multiStr;
+               string convertedStr(multi);
+               delete[] multi;
 
                return convertedStr;
        }
@@ -137,5 +137,5 @@ std::string wideToMulti(const std::wstring& wideStr)
 }
 
 
-} // namespace Mf
+} // namespace moof
 
This page took 0.022705 seconds and 4 git commands to generate.