ICU-3335 CharString, option for default conversion.

X-SVN-Rev: 13478
This commit is contained in:
Andy Heninger 2003-10-23 18:34:43 +00:00
parent c643cf9577
commit 22ec938fdf

View file

@ -25,7 +25,11 @@ U_NAMESPACE_BEGIN
class U_COMMON_API CharString : public UMemory {
public:
inline CharString(const UnicodeString& str);
// Constructor
// @param str The unicode string to be converted to char *
// @param codepage The char * code page. "" for invariant conversion.
// NULL for default code page.
inline CharString(const UnicodeString& str, const char *codepage = "");
inline ~CharString();
inline operator const char*() const { return ptr; }
@ -37,14 +41,15 @@ private:
CharString &operator=(const CharString &other); // forbid copying of this class
};
inline CharString::CharString(const UnicodeString& str) {
// Invariant converter should create str.length() chars
if (str.length() >= (int32_t)sizeof(buf)) {
ptr = (char *)uprv_malloc(str.length() + 8);
} else {
ptr = buf;
inline CharString::CharString(const UnicodeString& str, const char *codepage) {
int32_t len;
ptr = buf;
len = str.extract(0, 0x7FFFFFFF, buf ,sizeof(buf)-1, codepage);
buf[sizeof(buf)-1] = 0; // extract does not add null if it thinks there is no space for it.
if (len >= sizeof(buf)-1) {
ptr = (char *)uprv_malloc(len+1);
str.extract(0, 0x7FFFFFFF, ptr, len+1, codepage);
}
str.extract(0, 0x7FFFFFFF, ptr, "");
}
inline CharString::~CharString() {