Query for interest in including a shim class converting between char*, wchar_t, string, wstring

As a C++ programmer, often times there's a need to widen or narrow a string to match some 3rd APIs. After writing similar code again and again, I decided to have a wrapper to simplify this trivial but frequent work, hence the TR and TR2 class. Features include: - Each class serves as a shim between wide-char and marrow-char string types. It accepts a std::basic_string type or C-style literal, returns a std::basic_string type or streamming to std::basic_ostream according to the context(e.g. type on the left side of '=' operator): - 2 classes o Non-template class TR: convenient and intuitive interface, e.g. std::string s = TR(L"hello"); std::wstring s = TR("hello"); o template class TR2<SourceRange>: more verbose but faster e.g. std::string s = TR2<const wchar_t*>(L"hello"); std::wstring s = TR2<const char*>("hello"); - Many Boost libraries (e.g. Boost.Test) that output plain English (ASCII) message literals can be easily extended to support both wide-char version with this class. - The 2 classes do not involve any encoding/decoding. - The name TR is inspired from QT' tr() macro. If there's enough interest, I am ready to improve the code, including renaming, style cleaning, documenting and compiler testing etc, for a final inclusion. And I also would like to have a mentor to guide me through as I've never submitted any code to boost before. This class started as some test code snippet for boost.chrono while exchanging ideas with Vicente J. Botet Escriba. One major improvement since then is that the conversion is bi-directional now..

On 25.08.2011 11:11, Tan, Tom (Shanghai) wrote:
- The name TR is inspired from QT' tr() macro.
Qt's tr() stands for "translate" because that thing is the entry point for Qt's localization/message catalog system. In other words, you use tr() only for user-visible string that should get translated. That makes it a poor inspiration for something that is concerned with encoding conversion. Sebastian

On Thu, Aug 25, 2011 at 12:11, Tan, Tom (Shanghai) <TTan@husky.ca> wrote:
As a C++ programmer, often times there's a need to widen or narrow a string to match some 3rd APIs. After writing similar code again and again, I decided to have a wrapper to simplify this trivial but frequent work, hence the TR and TR2 class. Features include:
If something fails to compile, there must be a reason. Just shutting up the compiler doesn't make your code correct. What you're doing is like reinterpret_casting an int to float... [...]
- Many Boost libraries (e.g. Boost.Test) that output plain English (ASCII) message literals can be easily extended to support both wide-char version with this class.
They don't have to support wide-char. Many programmers are not interested in any wide-char support at all. See http://programmers.stackexchange.com/questions/102205/should-utf-16-be-consi... - The 2 classes do not involve any encoding/decoding.
tr.hpp:
* N.B. it doe not do any code conversion like: MBCS <--> UNICODE
This is just wrong. Your code is useless as it doesn't solve any real problem. This is not going to be accepted to boost, especially since it misguides programmers to write Unicode incorrect and *broken* code. Yes, you may find this library useful, and, say, half of non-expert programmers will find this library useful. The sad thing is that most of them just don't understand what Unicode is or what's text at all. Btw, you're not the first to propose some kind of tools for 'Unicode support'. I can count at least 4 other proposals trying to solve different aspects by different means. None of them was accepted to boost yet. -- Yakov
participants (3)
-
Sebastian Redl
-
Tan, Tom (Shanghai)
-
Yakov Galka