Boost logo

Boost :

Subject: [boost] Query for interest in including a shim class converting between char*, wchar_t, string, wstring
From: Tan, Tom (Shanghai) (TTan_at_[hidden])
Date: 2011-08-25 05:11:10


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..





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk