summaryrefslogtreecommitdiff
path: root/shared/string_utf8.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:12:46 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:12:46 +0200
commitb338e29fd3eaf700f8c8360aa0310048ba941d54 (patch)
tree122f8ef3790d12cd10275ef7453a9e8053322d78 /shared/string_utf8.h
parent3.18 (diff)
downloadFreeFileSync-b338e29fd3eaf700f8c8360aa0310048ba941d54.tar.gz
FreeFileSync-b338e29fd3eaf700f8c8360aa0310048ba941d54.tar.bz2
FreeFileSync-b338e29fd3eaf700f8c8360aa0310048ba941d54.zip
3.19
Diffstat (limited to 'shared/string_utf8.h')
-rw-r--r--shared/string_utf8.h50
1 files changed, 26 insertions, 24 deletions
diff --git a/shared/string_utf8.h b/shared/string_utf8.h
index f6f12d8f..26f4c3f2 100644
--- a/shared/string_utf8.h
+++ b/shared/string_utf8.h
@@ -15,20 +15,22 @@
namespace zen
{
-//Example: std::string tmp = toUtf8<std::string>(L"abc");
+//convert any(!) "string-like" object into target string by applying a UTF8 conversion (only if necessary!)
+template <class TargetString, class SourceString> TargetString utf8CvrtTo(const SourceString& str);
+
+//convert wide to utf8 string; example: std::string tmp = toUtf8<std::string>(L"abc");
template <class CharString, class WideString>
CharString wideToUtf8(const WideString& str);
-//Example: std::wstring tmp = utf8To<std::wstring>("abc");
+//convert utf8 string to wide; example: std::wstring tmp = utf8To<std::wstring>("abc");
template <class WideString, class CharString>
WideString utf8ToWide(const CharString& str);
const char BYTE_ORDER_MARK_UTF8[] = "\xEF\xBB\xBF";
-//convert any(!) "string-like" object into a UTF8 encoded std::string
-template <class String> std::string toStdString(const String& str);
-//convert a UTF8 encoded std::string to any(!) string-class
-template <class String> String stdStringTo(const std::string& str);
+
+
+
@@ -190,7 +192,7 @@ Function utf8ToCodePoint(CharIterator first, CharIterator last, Function f) //f
};
CodePoint cp = static_cast<Char8>(*first);
- switch (getUtf8Len(cp))
+ switch (getUtf8Len(static_cast<Char8>(cp)))
{
case 1:
break;
@@ -238,13 +240,13 @@ template <class String>
class AppendStringIterator: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
public:
- explicit AppendStringIterator (String& x) : str(x) {}
- AppendStringIterator& operator= (typename String::value_type value) { str += value; return *this; }
+ explicit AppendStringIterator (String& x) : str(&x) {}
+ AppendStringIterator& operator= (typename String::value_type value) { *str += value; return *this; }
AppendStringIterator& operator* () { return *this; }
AppendStringIterator& operator++ () { return *this; }
AppendStringIterator operator++ (int) { return *this; }
private:
- String& str;
+ String* str;
};
@@ -310,24 +312,24 @@ CharString wideToUtf8(const WideString& str)
//-------------------------------------------------------------------------------------------
-template <class String> inline
-std::string toStdString(const String& str, wchar_t) { return wideToUtf8<std::string>(str); } //convert wide character string to UTF8
+template <class TargetString, class SourceString> inline
+TargetString utf8CvrtTo(const SourceString& str, char, wchar_t) { return utf8ToWide<TargetString>(str); }
-template <class String> inline
-std::string toStdString(const String& str, char) { return cvrtString<std::string>(str); } //directly process string without UTF8 conversion
+template <class TargetString, class SourceString> inline
+TargetString utf8CvrtTo(const SourceString& str, wchar_t, char) { return wideToUtf8<TargetString>(str); }
-template <class String> inline
-std::string toStdString(const String& str) { return toStdString(str, typename StringTraits<String>::CharType()); }
-//-------------------------------------------------------------------------------------------
-
-template <class String> inline
-String stdStringTo(const std::string& str, wchar_t) { return utf8ToWide<String>(str); } //convert UTF8 to wide character string
+template <class TargetString, class SourceString> inline
+TargetString utf8CvrtTo(const SourceString& str, char, char) { return cvrtString<TargetString>(str); }
-template <class String> inline
-String stdStringTo(const std::string& str, char) { return cvrtString<String>(str); } //directly process string without UTF8 conversion
+template <class TargetString, class SourceString> inline
+TargetString utf8CvrtTo(const SourceString& str, wchar_t, wchar_t) { return cvrtString<TargetString>(str); }
-template <class String> inline
-String stdStringTo(const std::string& str) { return stdStringTo<String>(str, typename StringTraits<String>::CharType()); }
+template <class TargetString, class SourceString> inline
+TargetString utf8CvrtTo(const SourceString& str)
+{
+ return utf8CvrtTo<TargetString>(str, typename StringTraits<SourceString>::CharType(),
+ typename StringTraits<TargetString>::CharType());
+}
}
#endif //STRING_UTF8_HEADER_01832479146991573473545
bgstack15