activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r758919 - in /activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils: OpenwireStringSupport.cpp OpenwireStringSupport.h
Date Thu, 26 Mar 2009 23:19:14 GMT
Author: tabish
Date: Thu Mar 26 23:19:14 2009
New Revision: 758919

URL: http://svn.apache.org/viewvc?rev=758919&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-232

Modified:
    activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
    activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h

Modified: activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp?rev=758919&r1=758918&r2=758919&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
(original)
+++ activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp
Thu Mar 26 23:19:14 2009
@@ -36,51 +36,56 @@
 
         short utflen = dataIn.readShort();
 
-        if( utflen > -1 )
-        {
+        if( utflen > -1 ) {
+
             // Let the stream get us all that data.
             std::vector<unsigned char> value;
             value.resize( utflen );
             dataIn.readFully( value );
 
-            int c = 0;
+            std::vector<unsigned char> byteArr;
+            byteArr.resize( utflen );
+
             int count = 0;
+            for( unsigned int i = 0; i < value.size(); ++i ) {
+
+                unsigned int z = (unsigned char) value[i];
 
-            while( count < utflen )
-            {
-                c = value[count] & 0xff;
-                switch( c >> 4 )
-                {
-                    case 0:
-                    case 1:
-                    case 2:
-                    case 3:
-                    case 4:
-                    case 5:
-                    case 6:
-                    case 7:
-                        /* 0xxxxxxx */
-                        count++;
-                        break;
-                    case 12:
-                    case 13:
-                    case 14:
-                    default :
-                    {
-                        /* 10xx xxxx, 1111 xxxx */
-                        throw IOException(
-                            __FILE__,
-                            __LINE__,
-                            "OpenwireStringSupport::readString - Encoding not supported"
);
-                    }
+                if( (z >= 0x0001) && (z <= 0x007F) )  {
+                    byteArr[count++] = (unsigned char)z;
+                } else if( (z >= 0x00C0) && (z <= 0x00DF) ) {
+                    unsigned int y = (unsigned char) value[++i];
+                    byteArr[count++] = (unsigned char)((z-192)*64 + (y-128));
+                } else if ((z >= 0x00E0) && (z <= 0x00EF) ) {
+                    unsigned int y = (unsigned char) value[++i];
+                    unsigned int x = (unsigned char) value[++i];
+                    byteArr[count++] = (unsigned char)((z-224)*4096 + (y-128)*64 + (x-128));
+                } else if( (z >= 0x00F0) && (z <= 0x00F7) ) {
+                    unsigned int y = (unsigned char) value[++i];
+                    unsigned int x = (unsigned char) value[++i];
+                    unsigned int w = (unsigned char) value[++i];
+                    byteArr[count++] = (unsigned char)((z-240)*262144 + (y-128)*4096 + (x-128)*64
+ (w-128));
+                } else if( (z >= 0x00F8) && (z <= 0x00FB) ) {
+                    unsigned int y = (unsigned char) value[++i];
+                    unsigned int x = (unsigned char) value[++i];
+                    unsigned int w = (unsigned char) value[++i];
+                    unsigned int v = (unsigned char) value[++i];
+                    byteArr[count++] = (unsigned char)((z-248)*16777216 + (y-128)*262144
+ (x-128)*4096 + (w-128)*64 + (v-128));
+                } else if( (z >= 0x00FC) && (z <= 0x00FD) ) {
+                    unsigned int y = (unsigned char) value[++i];
+                    unsigned int x = (unsigned char) value[++i];
+                    unsigned int w = (unsigned char) value[++i];
+                    unsigned int v = (unsigned char) value[++i];
+                    unsigned int u = (unsigned char) value[++i];
+                    byteArr[count++] = (unsigned char)((z-252)*1073741824 + (y-128)*16777216
+ (x-128)*262144 + (w-128)*4096 + (v-128)*64 + (u-128));
                 }
             }
 
             // C++ strings need a NULL terminator
-            value.push_back( '\0' );
+            byteArr.push_back( '\0' );
 
             // Let the Compiler give us a string.
-            return reinterpret_cast<const char*>( &value[0] );
+            return reinterpret_cast<const char*>( &byteArr[0] );
         }
 
         return "";
@@ -110,12 +115,12 @@
             }
 
             unsigned short utflen = 0;
-            int c, count = 0;
+            unsigned int c, count = 0;
 
             std::string::const_iterator iter = str->begin();
 
             for(; iter != str->end(); ++iter ) {
-                c = *iter;
+                c = (unsigned char) *iter;
                 if( (c >= 0x0001) && (c <= 0x007F) ) {
                     utflen++;
                 } else if( c > 0x07FF ) {
@@ -131,16 +136,16 @@
 
             for( iter = str->begin(); iter != str->end(); ++iter ) {
 
-                c = *iter;
+                c = (unsigned char) *iter;
                 if( (c >= 0x0001) && (c <= 0x007F) ) {
                     byteArr[count++] = (unsigned char)c;
-                } else if ( c > 0x07FF ) {
-                    byteArr[count++] = (unsigned char)( 0xE0 | ( (c >> 12) & 0x0F)
);
-                    byteArr[count++] = (unsigned char)( 0x80 | ( (c >> 6) & 0x3F)
);
-                    byteArr[count++] = (unsigned char)( 0x80 | ( (c >> 0) & 0x3F)
);
+                } else if( c <= 0x07FF ) {
+                    byteArr[count++] = (unsigned char)( 192 + (c / 64));
+                    byteArr[count++] = (unsigned char)( 128 + (c % 64));
                 } else {
-                    byteArr[count++] = (unsigned char)( 0xC0 | ( (c >> 6) & 0x1F)
);
-                    byteArr[count++] = (unsigned char)( 0x80 | ( (c >> 0) & 0x3F)
);
+                    byteArr[count++] = (unsigned char)( 224 + (c / 4096));
+                    byteArr[count++] = (unsigned char)( 192 + ((c / 64) % 64));
+                    byteArr[count++] = (unsigned char)( 128 + (c % 64));
                 }
             }
 

Modified: activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h?rev=758919&r1=758918&r2=758919&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h
(original)
+++ activemq/activemq-cpp/branches/activemq-cpp-2.x/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h
Thu Mar 26 23:19:14 2009
@@ -40,10 +40,10 @@
          * Static method used for reading a string that uses the Openwire format
          * from a DataInputStream, this can throw an IOException for the same
          * reason as a DataInputStream.readUTF might, as well as if the string
-         * that is received doesn't conform to the supported charactor encoding.
+         * that is received doesn't conform to the supported character encoding.
          * @param dataIn - DataInputStream to read from
          * @returns A string that has been read
-         * @throws IOException on Errror.
+         * @throws IOException on Error.
          */
         static std::string readString( decaf::io::DataInputStream& dataIn )
             throw ( decaf::io::IOException );
@@ -55,7 +55,7 @@
          * @param dataOut - DataOutputStream to write to
          * @param str - A pointer to a string that should be written, NULL needs
          *              to be an option here as its written as -1.
-         * @throws IOException on Errror.
+         * @throws IOException on Error.
          */
         static void writeString( decaf::io::DataOutputStream& dataOut,
                                  const std::string* str )



Mime
View raw message