]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/io/ustream.cpp
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / io / ustream.cpp
index e9f57643d927845ef56844f6e98da58887f8f203..25c54eb55532f91023bb920bc4d8d7f4cbcb7083 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 2001-2007, International Business Machines
+*   Copyright (C) 2001-2016, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *  FILE NAME : ustream.cpp
 ******************************************************************************
 */
 
-
 #include "unicode/utypes.h"
+
+#if !UCONFIG_NO_CONVERSION
+
 #include "unicode/uobject.h"
 #include "unicode/ustream.h"
 #include "unicode/ucnv.h"
 #include "unicode/uchar.h"
+#include "unicode/utf16.h"
 #include "ustr_cnv.h"
+#include "cmemory.h"
 #include <string.h>
 
 // console IO
 
-#if U_IOSTREAM_SOURCE >= 198506
-
 #if U_IOSTREAM_SOURCE >= 199711
+
 #define STD_NAMESPACE std::
-#else
-#define STD_NAMESPACE
-#endif
 
 #define STD_OSTREAM STD_NAMESPACE ostream
 #define STD_ISTREAM STD_NAMESPACE istream
@@ -49,15 +49,16 @@ operator<<(STD_OSTREAM& stream, const UnicodeString& str)
         if(U_SUCCESS(errorCode)) {
             const UChar *us = str.getBuffer();
             const UChar *uLimit = us + str.length();
-            char *s, *sLimit = buffer + sizeof(buffer);
+            char *s, *sLimit = buffer + (sizeof(buffer) - 1);
             do {
                 errorCode = U_ZERO_ERROR;
                 s = buffer;
                 ucnv_fromUnicode(converter, &s, sLimit, &us, uLimit, 0, FALSE, &errorCode);
+                *s = 0;
 
                 // write this chunk
                 if(s > buffer) {
-                    stream.write(buffer, (int32_t)(s - buffer));
+                    stream << buffer;
                 }
             } while(errorCode == U_BUFFER_OVERFLOW_ERROR);
             u_releaseDefaultConverter(converter);
@@ -87,7 +88,7 @@ operator>>(STD_ISTREAM& stream, UnicodeString& str)
     converter = u_getDefaultConverter(&errorCode);
     if(U_SUCCESS(errorCode)) {
         UChar *us = uBuffer;
-        const UChar *uLimit = uBuffer + sizeof(uBuffer)/sizeof(*uBuffer);
+        const UChar *uLimit = uBuffer + UPRV_LENGTHOF(uBuffer);
         const char *s, *sLimit;
         char ch;
         UChar ch32;
@@ -167,4 +168,4 @@ STOP_READING:
 U_NAMESPACE_END
 
 #endif
-
+#endif