mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 04:29:31 +00:00
ICU-3335 CharString, option for default conversion.
X-SVN-Rev: 13478
This commit is contained in:
parent
c643cf9577
commit
22ec938fdf
1 changed files with 13 additions and 8 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue