]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/charstr.h
ICU-8.11.2.tar.gz
[apple/icu.git] / icuSources / common / charstr.h
index 6666beb43789b00805422770fc0203766cebe58a..3bb11cbad35f93a86d6dcaf0ed07baeedc05e8cf 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2001, International Business Machines
+*   Copyright (c) 2001-2004, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -8,6 +8,9 @@
 **********************************************************************
 */
 
+#ifndef CHARSTRING_H
+#define CHARSTRING_H
+
 #include "unicode/utypes.h"
 #include "unicode/uobject.h"
 #include "unicode/unistr.h"
@@ -25,6 +28,15 @@ U_NAMESPACE_BEGIN
 
 class U_COMMON_API CharString : public UMemory {
 public:
+
+#if !UCONFIG_NO_CONVERSION
+    // 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);
+#endif
+
     inline CharString(const UnicodeString& str);
     inline ~CharString();
     inline operator const char*() const { return ptr; }
@@ -37,14 +49,31 @@ private:
     CharString &operator=(const CharString &other); // forbid copying of this class
 };
 
+#if !UCONFIG_NO_CONVERSION
+
+// PLEASE DON'T USE THIS FUNCTION.
+// We don't want the static dependency on conversion or the performance hit that comes from a codepage conversion.
+/*
+inline CharString::CharString(const UnicodeString& str, const char *codepage) {
+    int32_t    len;
+    ptr = buf;
+    len = str.extract(0, 0x7FFFFFFF, buf ,sizeof(buf)-1, codepage);
+    if (len >= (int32_t)(sizeof(buf)-1)) {
+        ptr = (char *)uprv_malloc(len+1);
+        str.extract(0, 0x7FFFFFFF, ptr, len+1, codepage);
+    }
+}*/
+
+#endif
+
 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;
+    int32_t    len;
+    ptr = buf;
+    len = str.extract(0, 0x7FFFFFFF, buf, (int32_t)(sizeof(buf)-1), US_INV);
+    if (len >= (int32_t)(sizeof(buf)-1)) {
+        ptr = (char *)uprv_malloc(len+1);
+        str.extract(0, 0x7FFFFFFF, ptr, len+1, US_INV);
     }
-    str.extract(0, 0x7FFFFFFF, ptr, "");
 }
 
 inline CharString::~CharString() {
@@ -55,4 +84,5 @@ inline CharString::~CharString() {
 
 U_NAMESPACE_END
 
+#endif
 //eof