How to Do It Right? Wide and Multi-Byte String Conversion
Posted on September 14th, 2008 at 17:17 by fr3@K

一方面是受到 jeffhung 與 augustinus 在 我家clsung 那邊留下的迴響所啟發, 令一方面也是為了讓自己更清楚了解正確 wide string and multi-byte string 間轉換的 issue. 我寫了兩個 Wide string and Multi-Bytes string conversion functions 以及方便性的 wrapper (source code hosted by Google Code).

希望能做為一個範例提供給想進一步了解這題目的朋友 (this includes me) 把玩. 也希望能請對這題目有研究的朋友來 code review 以及留下意見, 幫助讓我完善這對 conversion functions 一起造福有這需求的使用者.

Disclaimer: 小弟對實作所使用的 API (wcrtombmbrtowc) 的行為不是非常肯定, 不敢宣稱其功能上的正確. 歡迎自行取用 (MIT-licensed), 但不提供任何保證.

del.icio.us:How to Do It Right? Wide and Multi-Byte String Conversion digg:How to Do It Right? Wide and Multi-Byte String Conversion spurl:How to Do It Right? Wide and Multi-Byte String Conversion newsvine:How to Do It Right? Wide and Multi-Byte String Conversion furl:How to Do It Right? Wide and Multi-Byte String Conversion Y!:How to Do It Right? Wide and Multi-Byte String Conversion 黑米共享書籤:How to Do It Right? Wide and Multi-Byte String Conversion 推推王:How to Do It Right? Wide and Multi-Byte String Conversion
re: string to/from wstring conversion
Posted on September 3rd, 2008 at 16:22 by fr3@K

本篇文字的內容本來是我寫給 clsung 的一篇文字 的第二個回應. 但不幸的是我的回應被 anti-spam 機制吃掉了, 並提示我 email 給站長處理. 那時 submit 的文字我是撈不回來了, 於是決定重寫並貼在自己家裡.
(more…)

del.icio.us:re: string to/from wstring conversion digg:re: string to/from wstring conversion spurl:re: string to/from wstring conversion newsvine:re: string to/from wstring conversion furl:re: string to/from wstring conversion Y!:re: string to/from wstring conversion 黑米共享書籤:re: string to/from wstring conversion 推推王:re: string to/from wstring conversion
More on WIN32 Unicoding
Posted on September 3rd, 2008 at 13:33 by fr3@K

Follow up 一下去年底沒給出結論的 WIN32 的 _TCHAR 與 std::wstring 的問題. From MSDN:

Microsoft’s C/C++ compiler defines a built-in data type, wchar_t, which represents a 16-bit Unicode (UTF-16) character.

雖然我沒在 MSDN 上找到, 據一位 MS International Fundamentals team 的 developer, Michael Kaplan, 所 blog – 從 XP 開始, WIN32 的 wchar_t 用的 encoding 是 UTF-16. 之前用的則是… 一種不理會 surrogate (原文為 surrogate neutral) 的 UTF-16 (也因此有人說它是 UCS-2).

結論, 從 XP (含) 以後, WIN32 的 wchar_t 用的 encoding 是標準的 UTF-16. 假設每一個 wchar_t 元素都能一對一地 mapping 到一個 Unicode code point 是錯誤的. 另一個說法是 std::wstring::size() 只能告訴你這個寬字串有幾個 wchar_t, 而不能正確的告訴你到底有幾個 code point.

del.icio.us:More on WIN32 Unicoding digg:More on WIN32 Unicoding spurl:More on WIN32 Unicoding newsvine:More on WIN32 Unicoding furl:More on WIN32 Unicoding Y!:More on WIN32 Unicoding 黑米共享書籤:More on WIN32 Unicoding 推推王:More on WIN32 Unicoding
WIN32 的 _TCHAR 與 std::wstring 的問題
Posted on November 20th, 2007 at 3:28 by fr3@K

我知道很多人一直是這樣做的, 可是我從沒搞懂為什麼在 windows 平台上, 用上了 _TCHAR, _TEXT 再 define 個 _UNICODE. 或是用上了 whar_t 與 std::wstring. 就能算是 Unicode 化的程式?
(more…)

del.icio.us:WIN32 的 _TCHAR 與 std::wstring 的問題 digg:WIN32 的 _TCHAR 與 std::wstring 的問題 spurl:WIN32 的 _TCHAR 與 std::wstring 的問題 newsvine:WIN32 的 _TCHAR 與 std::wstring 的問題 furl:WIN32 的 _TCHAR 與 std::wstring 的問題 Y!:WIN32 的 _TCHAR 與 std::wstring 的問題 黑米共享書籤:WIN32 的 _TCHAR 與 std::wstring 的問題 推推王:WIN32 的 _TCHAR 與 std::wstring 的問題