diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/all.dsw | 18 | ||||
-rwxr-xr-x | cpp/allTests.py | 1 | ||||
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 46 | ||||
-rw-r--r-- | cpp/src/IceUtil/Unicode.cpp | 10 | ||||
-rw-r--r-- | cpp/test/IceUtil/Makefile | 3 | ||||
-rw-r--r-- | cpp/test/IceUtil/unicode/.depend | 0 | ||||
-rw-r--r-- | cpp/test/IceUtil/unicode/Client.cpp | 43 | ||||
-rw-r--r-- | cpp/test/IceUtil/unicode/Makefile | 30 | ||||
-rwxr-xr-x | cpp/test/IceUtil/unicode/run.py | 39 | ||||
-rw-r--r-- | cpp/test/IceUtil/unicode/unicode.dsp | 105 |
10 files changed, 268 insertions, 27 deletions
diff --git a/cpp/all.dsw b/cpp/all.dsw index 6947e7ed2c6..77fdf0e7b19 100644 --- a/cpp/all.dsw +++ b/cpp/all.dsw @@ -422,6 +422,9 @@ Package=<4> Begin Project Dependency
Project_Dep_Name callbackS
End Project Dependency
+ Begin Project Dependency
+ Project_Dep_Name unicode
+ End Project Dependency
}}}
###############################################################################
@@ -1347,6 +1350,21 @@ Package=<4> ###############################################################################
+Project: "unicode"=.\test\IceUtil\unicode\unicode.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name IceUtil
+ End Project Dependency
+}}}
+
+###############################################################################
+
Project: "valueC"=.\demo\Ice\value\valueC.dsp - Package Owner=<4>
Package=<5>
diff --git a/cpp/allTests.py b/cpp/allTests.py index d66a719899b..9b308249996 100755 --- a/cpp/allTests.py +++ b/cpp/allTests.py @@ -23,6 +23,7 @@ else: # tests = [ \ "IceUtil/thread", \ + "IceUtil/unicode", \ "Slice/errorDetection", \ "Ice/operations", \ "Ice/exceptions", \ diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index 4ca75897a87..9d2bc9bf314 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -95,7 +95,7 @@ IceInternal::BasicStream::endWriteEncaps() } Int sz = b.size() - start; const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + start - sizeof(Int)); #else copy(p, p + sizeof(Int), b.begin() + start - sizeof(Int)); @@ -218,7 +218,7 @@ IceInternal::BasicStream::write(const vector<Byte>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); #else copy(p, p + sizeof(Int), b.begin() + pos); @@ -258,7 +258,7 @@ IceInternal::BasicStream::write(const vector<bool>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); #else copy(p, p + sizeof(Int), b.begin() + pos); @@ -297,7 +297,7 @@ IceInternal::BasicStream::write(Short v) int pos = b.size(); resize(pos + sizeof(Short)); const Byte* p = reinterpret_cast<const Byte*>(&v); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Short), b.begin() + pos); #else copy(p, p + sizeof(Short), b.begin() + pos); @@ -311,7 +311,7 @@ IceInternal::BasicStream::write(const vector<Short>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz * sizeof(Short)); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); pos += sizeof(Int); p = reinterpret_cast<const Byte*>(v.begin()); @@ -337,7 +337,7 @@ IceInternal::BasicStream::read(Short& v) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else copy(begin, i, reinterpret_cast<Byte*>(&v)); @@ -356,7 +356,7 @@ IceInternal::BasicStream::read(vector<Short>& v) throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } v.resize(sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN for (int j = 0 ; j < sz ; ++j) { reverse_copy(begin, begin + sizeof(Short), reinterpret_cast<Byte*>(&v[j])); @@ -373,7 +373,7 @@ IceInternal::BasicStream::write(Int v) int pos = b.size(); resize(pos + sizeof(Int)); const Byte* p = reinterpret_cast<const Byte*>(&v); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); #else copy(p, p + sizeof(Int), b.begin() + pos); @@ -387,7 +387,7 @@ IceInternal::BasicStream::write(const vector<Int>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz * sizeof(Int)); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); pos += sizeof(Int); p = reinterpret_cast<const Byte*>(v.begin()); @@ -413,7 +413,7 @@ IceInternal::BasicStream::read(Int& v) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else copy(begin, i, reinterpret_cast<Byte*>(&v)); @@ -432,7 +432,7 @@ IceInternal::BasicStream::read(vector<Int>& v) throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } v.resize(sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN for (int j = 0 ; j < sz ; ++j) { reverse_copy(begin, begin + sizeof(Int), reinterpret_cast<Byte*>(&v[j])); @@ -449,7 +449,7 @@ IceInternal::BasicStream::write(Long v) int pos = b.size(); resize(pos + sizeof(Long)); const Byte* p = reinterpret_cast<const Byte*>(&v); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Long), b.begin() + pos); #else copy(p, p + sizeof(Long), b.begin() + pos); @@ -463,7 +463,7 @@ IceInternal::BasicStream::write(const vector<Long>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz * sizeof(Long)); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); pos += sizeof(Int); p = reinterpret_cast<const Byte*>(v.begin()); @@ -489,7 +489,7 @@ IceInternal::BasicStream::read(Long& v) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else copy(begin, i, reinterpret_cast<Byte*>(&v)); @@ -508,7 +508,7 @@ IceInternal::BasicStream::read(vector<Long>& v) throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } v.resize(sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN for (int j = 0 ; j < sz ; ++j) { reverse_copy(begin, begin + sizeof(Long), reinterpret_cast<Byte*>(&v[j])); @@ -525,7 +525,7 @@ IceInternal::BasicStream::write(Float v) int pos = b.size(); resize(pos + sizeof(Float)); const Byte* p = reinterpret_cast<const Byte*>(&v); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Float), b.begin() + pos); #else copy(p, p + sizeof(Float), b.begin() + pos); @@ -539,7 +539,7 @@ IceInternal::BasicStream::write(const vector<Float>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz * sizeof(Float)); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); pos += sizeof(Int); p = reinterpret_cast<const Byte*>(v.begin()); @@ -565,7 +565,7 @@ IceInternal::BasicStream::read(Float& v) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else copy(begin, i, reinterpret_cast<Byte*>(&v)); @@ -584,7 +584,7 @@ IceInternal::BasicStream::read(vector<Float>& v) throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } v.resize(sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN for (int j = 0 ; j < sz ; ++j) { reverse_copy(begin, begin + sizeof(Float), reinterpret_cast<Byte*>(&v[j])); @@ -601,7 +601,7 @@ IceInternal::BasicStream::write(Double v) int pos = b.size(); resize(pos + sizeof(Double)); const Byte* p = reinterpret_cast<const Byte*>(&v); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Double), b.begin() + pos); #else copy(p, p + sizeof(Double), b.begin() + pos); @@ -615,7 +615,7 @@ IceInternal::BasicStream::write(const vector<Double>& v) Int sz = v.size(); resize(pos + sizeof(Int) + sz * sizeof(Double)); const Byte* p = reinterpret_cast<const Byte*>(&sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(p, p + sizeof(Int), b.begin() + pos); pos += sizeof(Int); p = reinterpret_cast<const Byte*>(v.begin()); @@ -641,7 +641,7 @@ IceInternal::BasicStream::read(Double& v) { throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN reverse_copy(begin, i, reinterpret_cast<Byte*>(&v)); #else copy(begin, i, reinterpret_cast<Byte*>(&v)); @@ -660,7 +660,7 @@ IceInternal::BasicStream::read(vector<Double>& v) throw UnmarshalOutOfBoundsException(__FILE__, __LINE__); } v.resize(sz); -#ifdef ICE_BIGENDIAN +#ifdef ICE_UTIL_BIGENDIAN for (int j = 0 ; j < sz ; ++j) { reverse_copy(begin, begin + sizeof(Double), reinterpret_cast<Byte*>(&v[j])); diff --git a/cpp/src/IceUtil/Unicode.cpp b/cpp/src/IceUtil/Unicode.cpp index cf996046645..3850193b76a 100644 --- a/cpp/src/IceUtil/Unicode.cpp +++ b/cpp/src/IceUtil/Unicode.cpp @@ -9,6 +9,7 @@ // ********************************************************************** #include <IceUtil/Unicode.h> +#include <algorithm> using namespace std; @@ -20,8 +21,9 @@ IceUtil::wstringToString(const wstring& str) for (unsigned int i = 0; i < str.length(); ++i) { - wchar_t wc = str[i]; - + wchar_t wc; + wc = str[i]; + if (wc < 0x80) { result += static_cast<char>(wc); @@ -110,7 +112,7 @@ IceUtil::stringToWstring(const string& str) if (i + len - 1 < str.length()) { - for (unsigned int j = 1; j < len - 1; ++j) + for (unsigned int j = 1; j < len; ++j) { if ((str[i + j] & 0xc0) != 0x80) // All other bytes must be 10xxxxxx { @@ -120,6 +122,8 @@ IceUtil::stringToWstring(const string& str) wc <<= 6; wc |= str[i + j] & 0x3f; } + + result += wc; } else { diff --git a/cpp/test/IceUtil/Makefile b/cpp/test/IceUtil/Makefile index 57a50f3ab9f..6ab01396435 100644 --- a/cpp/test/IceUtil/Makefile +++ b/cpp/test/IceUtil/Makefile @@ -12,7 +12,8 @@ top_srcdir = ../.. include $(top_srcdir)/config/Make.rules -SUBDIRS = thread +SUBDIRS = thread \ + unicode $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cpp/test/IceUtil/unicode/.depend b/cpp/test/IceUtil/unicode/.depend new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/test/IceUtil/unicode/.depend diff --git a/cpp/test/IceUtil/unicode/Client.cpp b/cpp/test/IceUtil/unicode/Client.cpp new file mode 100644 index 00000000000..2d978284191 --- /dev/null +++ b/cpp/test/IceUtil/unicode/Client.cpp @@ -0,0 +1,43 @@ +// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <IceUtil/Unicode.h>
+#include <TestCommon.h>
+
+using namespace IceUtil;
+using namespace std;
+
+int
+main(int, char**)
+{
+ cout << "testing string/wstring conversion... ";
+
+ string arabic = "لماذا لا يتكلمون اللّغة العربية فحسب؟";
+
+ wstring warabic = stringToWstring(arabic);
+ test(warabic.length() == 37);
+
+ string arabic2 = wstringToString(warabic);
+ test(arabic2.length() == arabic.length());
+ test(arabic2 == arabic);
+
+ string japanese = "なぜ、みんな日本語を話してくれないのか?";
+
+ wstring wjapanese = stringToWstring(japanese);
+ test(wjapanese.length() == 20);
+
+ string japanese2 = wstringToString(wjapanese);
+ test(japanese2.length() == japanese.length());
+ test(japanese2 == japanese);
+
+ cout << "ok" << endl;
+
+ return EXIT_SUCCESS;
+}
diff --git a/cpp/test/IceUtil/unicode/Makefile b/cpp/test/IceUtil/unicode/Makefile new file mode 100644 index 00000000000..eeefa0ca689 --- /dev/null +++ b/cpp/test/IceUtil/unicode/Makefile @@ -0,0 +1,30 @@ +# **********************************************************************
+#
+# Copyright (c) 2001
+# MutableRealms, Inc.
+# Huntsville, AL, USA
+#
+# All Rights Reserved
+#
+# **********************************************************************
+
+top_srcdir = ../../..
+
+CLIENT = client
+
+TARGETS = $(CLIENT)
+
+OBJS = Client.o
+
+
+SRCS = $(OBJS:.o=.cpp)
+
+include $(top_srcdir)/config/Make.rules
+
+CPPFLAGS := -I. -I../../include $(CPPFLAGS)
+
+$(CLIENT): $(OBJS)
+ rm -f $@
+ $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(BASELIBS)
+
+include .depend
diff --git a/cpp/test/IceUtil/unicode/run.py b/cpp/test/IceUtil/unicode/run.py new file mode 100755 index 00000000000..5481554e073 --- /dev/null +++ b/cpp/test/IceUtil/unicode/run.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2001 +# MutableRealms, Inc. +# Huntsville, AL, USA +# +# All Rights Reserved +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("IceUtil", "unicode") +testdir = os.path.join(toplevel, "test", name) + +client = os.path.join(testdir, "client") +clientOptions = ' ' + testdir; + +print "starting client...", +clientPipe = os.popen(client + clientOptions) +output = clientPipe.read().strip() +if not output: + print "failed!" + sys.exit(1) +print "ok" +print output + +sys.exit(0) diff --git a/cpp/test/IceUtil/unicode/unicode.dsp b/cpp/test/IceUtil/unicode/unicode.dsp new file mode 100644 index 00000000000..33d9508cd34 --- /dev/null +++ b/cpp/test/IceUtil/unicode/unicode.dsp @@ -0,0 +1,105 @@ +# Microsoft Developer Studio Project File - Name="unicode" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=unicode - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "unicode.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "unicode.mak" CFG="unicode - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "unicode - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "unicode - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "unicode - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /WX /GR /GX /O2 /I "." /I "../../../include" /I "../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /YX /FD /c
+# SUBTRACT CPP /Fr
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 /nologo /subsystem:console /machine:I386 /nodefaultlib /out:"client.exe" /libpath:"../../../lib"
+
+!ELSEIF "$(CFG)" == "unicode - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /WX /Gm /GR /GX /Zi /Od /I "." /I "../../../include" /I "../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /YX /FD /GZ /c
+# SUBTRACT CPP /Fr
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /out:"client.exe" /pdbtype:sept /libpath:"../../../lib"
+# SUBTRACT LINK32 /nodefaultlib
+
+!ENDIF
+
+# Begin Target
+
+# Name "unicode - Win32 Release"
+# Name "unicode - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\Client.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
|