From 29649cf062dc618d3550a9dfe67ffe21be464a48 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 26 Jul 2009 01:32:38 +0000 Subject: [PATCH] String docs addenum, OEM charset in GetEnv (thanks Zbigniew), BLOB in MySql (thanks Sergey) git-svn-id: svn://ultimatepp.org/upp/trunk@1442 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/App.cpp | 12 +++++++++--- uppsrc/Core/Util.cpp | 14 ++++++++++++-- uppsrc/Core/Util.h | 1 + uppsrc/Core/src.tpp/String$en-us.tpp | 16 +++++++++++----- uppsrc/MySql/MySqlSchema.h | 6 ++++++ 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/uppsrc/Core/App.cpp b/uppsrc/Core/App.cpp index cc6277b5b..8eeee3070 100644 --- a/uppsrc/Core/App.cpp +++ b/uppsrc/Core/App.cpp @@ -6,13 +6,14 @@ NAMESPACE_UPP +#ifdef PLATFORM_WIN32 + + String GetEnv(const char *id) { - return FromSystemCharset(getenv(id)); + return FromOEMCharset(getenv(id)); } -#ifdef PLATFORM_WIN32 - String GetExeFilePath() { return GetModuleFileName(); @@ -26,6 +27,11 @@ String GetHomeDirectory() { #ifdef PLATFORM_POSIX +String GetEnv(const char *id) +{ + return FromSystemCharset(getenv(id)); +} + char Argv0__[_MAX_PATH + 1]; static void sSetArgv0__(const char *title) diff --git a/uppsrc/Core/Util.cpp b/uppsrc/Core/Util.cpp index ad73ab5b2..a07127bbe 100644 --- a/uppsrc/Core/Util.cpp +++ b/uppsrc/Core/Util.cpp @@ -608,16 +608,26 @@ String ToSystemCharset(const String& src) return b; } -String FromSystemCharset(const String& src) +String FromWin32Charset(const String& src, int cp) { WStringBuffer b(src.GetLength()); - int q = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength()); + int q = MultiByteToWideChar(cp, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength()); if(q <= 0) return src; b.SetCount(q); return WString(b).ToString(); } +String FromOEMCharset(const String& src) +{ + return FromWin32Charset(src, CP_OEMCP); +} + +String FromSystemCharset(const String& src) +{ + return FromWin32Charset(src, CP_ACP); +} + WString ToSystemCharsetW(const char *src) { return String(src).ToWString(); diff --git a/uppsrc/Core/Util.h b/uppsrc/Core/Util.h index 5b6a55e92..e9d962394 100644 --- a/uppsrc/Core/Util.h +++ b/uppsrc/Core/Util.h @@ -50,6 +50,7 @@ String FromSystemCharsetW(const wchar *src); #endif #ifdef PLATFORM_WIN32 +String FromOEMCharset(const String& src); String GetErrorMessage(dword dwError); #endif diff --git a/uppsrc/Core/src.tpp/String$en-us.tpp b/uppsrc/Core/src.tpp/String$en-us.tpp index 4c2ee7b31..8ec3664cd 100644 --- a/uppsrc/Core/src.tpp/String$en-us.tpp +++ b/uppsrc/Core/src.tpp/String$en-us.tpp @@ -15,11 +15,17 @@ topic "String and WString"; veable][@(0.0.255)3 <][*3 String][3 , ][_^AString^3 AString][@(0.0.255)3 <][_^String0^3 Strin g0][@(0.0.255)3 >][3 _>_]&] [s0;3%- &] -[s0; String is a value class that contains an array of characters. -It is designed to have fast copy operations. The array of characters -is zero terminated. String provides non`-mutable access to the -array of characters. String can store 8 bit encoded string or -an Utf8 encoded string&] +[s0; String is a value class that contains an array of characters +(or bytes). It is designed to have fast copy operations. The +array of characters is zero terminated. String provides non`-mutable +access to the array of characters. String can store 8 bit encoded +string or an UTF`-8 encoded string. For UTF`-8 strings, however, +String works with raw 8 bit values `- there are not automatic +conversions performed e.g. in operator`[`]. If you need to access +individual UTF`-8 characters, the best practice in most cases +is to convert it to WString (and eventually back after processing).&] +[s0; &] +[s0; String is also often used to store raw binary data.&] [s0; &] [s0; WString is similar to String, but it uses 16 bit Ucs2 encoding. String and WString share a number of common functions through diff --git a/uppsrc/MySql/MySqlSchema.h b/uppsrc/MySql/MySqlSchema.h index 30ff4ef9f..012620dc9 100644 --- a/uppsrc/MySql/MySqlSchema.h +++ b/uppsrc/MySql/MySqlSchema.h @@ -33,6 +33,9 @@ #define STRING_(x, n) COLUMN_(MySqlTextType(n), String, x, n, 0) #define STRING_ARRAY_(x, n, items) COLUMN_ARRAY_(MySqlTextType(n), String, x, n, 0, items) +#define BLOB(x) COLUMN("longblob", String, x, 0, 0) +#define BLOB_(x) COLUMN_("longblob", String, x, 0, 0) + #define PRIMARY_KEY INLINE_ATTRIBUTE("primary key") #define AUTO_INCREMENT INLINE_ATTRIBUTE("auto_increment") #define KEY INLINE_ATTRIBUTE("key") @@ -81,6 +84,9 @@ #undef STRING_ #undef STRING_ARRAY_ +#undef BLOB +#undef BLOB_ + #undef PRIMARY_KEY #undef AUTO_INCREMENT #undef KEY