activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r674300 - in /activemq/activemq-cpp/trunk/src/main/decaf/internal/net: URIEncoderDecoder.cpp URIEncoderDecoder.h
Date Sun, 06 Jul 2008 14:26:56 GMT
Author: tabish
Date: Sun Jul  6 07:26:55 2008
New Revision: 674300

URL: http://svn.apache.org/viewvc?rev=674300&view=rev
Log:
Finishing the implementation of the URIEncoderDecoder port from Harmony to be used in the
URI class.

Modified:
    activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.h

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.cpp?rev=674300&r1=674299&r2=674300&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.cpp Sun Jul
 6 07:26:55 2008
@@ -18,10 +18,14 @@
 #include "URIEncoderDecoder.h"
 
 #include <decaf/lang/Character.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
 
 using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::internal;
-using namespace decaf::internal::net
+using namespace decaf::internal::net;
+using namespace decaf::net;
 
 ////////////////////////////////////////////////////////////////////////////////
 const std::string URIEncoderDecoder::digits = "0123456789ABCDEF";
@@ -36,7 +40,9 @@
 
     std::string::const_iterator itr = s.begin();
 
-    for( int i = 0; itr != s.end(); ++i, ++iter ) {
+    for( std::size_t i = 0; itr != s.end(); ++i, ++itr ) {
+
+        char ch = s.at(i);
 
         if( ch == '%' ) {
             if( i + 2 >= s.length() ) {
@@ -45,8 +51,8 @@
                     "invalid Encoded data", i );
             }
 
-            int d1 = Character::digit( *(++iter), 16 );
-            int d2 = Character::digit( *(++iter), 16 );
+            int d1 = Character::digit( *(++itr), 16 );
+            int d2 = Character::digit( *(++itr), 16 );
 
             if( d1 == -1 || d2 == -1 ) {
                 throw URISyntaxException(
@@ -59,9 +65,11 @@
             continue;
         }
 
-        if( !Charactor::isLetterOrDigit( *itr ) &&
-            !Character::isSpaceChar( *itr ) &&
-            !Character::isISOControl( *itr ) ) {
+        if( ( !Character::isLetterOrDigit( *itr ) &&
+              legal.find( *itr, 0 ) == std::string::npos &&
+            ( (unsigned char)*itr > 127 &&
+              !Character::isWhitespace( *itr ) &&
+              !Character::isISOControl( *itr ) ) ) ) {
 
             throw URISyntaxException(
                 __FILE__, __LINE__, s,
@@ -79,7 +87,7 @@
 
     for( int i = 0; itr != s.end(); ++i, ++itr ) {
         if( !Character::isLetterOrDigit( *itr ) ||
-            !legal.find_first_of( *itr ) > std::string::npos ) {
+            !legal.find( *itr ) > std::string::npos ) {
 
             throw URISyntaxException(
                 __FILE__, __LINE__, s,
@@ -90,7 +98,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 std::string URIEncoderDecoder::quoteIllegal( const std::string& s,
-                                             const std::string& legal );
+                                             const std::string& legal ) {
 
     std::string buf = "";
     std::string::const_iterator iter = s.begin();
@@ -100,16 +108,16 @@
         char ch = *iter;
 
         if( Character::isLetterOrDigit( ch ) ||
-            legal.find( ch ) > string::npos ||
+            legal.find( ch ) > std::string::npos ||
             ( (unsigned char)ch > 127 &&
-              !Character.isSpaceChar(ch) &&
-              !Character.isISOControl(ch) ) ) {
+              !Character::isWhitespace(ch) &&
+              !Character::isISOControl(ch) ) ) {
 
-            buf.append(ch);
+            buf += ch;
         } else {
-            buf.append('%');
-            buf.append( digits.at( ( ch & 0xf0 ) >> 4 ) );
-            buf.append( digits.at( bytes[j] & 0xf ) );
+            buf += '%';
+            buf += digits.at( ( ch & 0xf0 ) >> 4 );
+            buf += digits.at( ch & 0xf );
         }
     }
 
@@ -119,14 +127,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string URIEncoderDecoder::encodeOthers( const std::string& s ) {
     std::string buf = "";
-    for( int i = 0; i < s.length(); i++ ) {
+    for( std::size_t i = 0; i < s.length(); i++ ) {
         char ch = s.at(i);
-        if( ch <= 127 ) {
-            buf.append( ch );
+        if( (unsigned char)ch <= 127 ) {
+            buf += ch;
         } else {
-            buf.append('%');
-            buf.append( digits.at( ( ch & 0xf0 ) >> 4 ) );
-            buf.append( digits.at( ch & 0xf ) );
+            buf += '%';
+            buf += digits.at( ( ch & 0xf0 ) >> 4 );
+            buf += digits.at( ch & 0xf );
         }
     }
     return buf;
@@ -136,8 +144,10 @@
 std::string URIEncoderDecoder::decode( const std::string& s ) {
 
     std::string result = "";
-    for( int i = 0; i < s.length(); ) {
-        char c = s.charAt(i);
+    for( std::size_t i = 0; i < s.length(); ) {
+
+        char c = s.at(i);
+
         if( c == '%' ) {
 
             do {
@@ -147,8 +157,8 @@
                         "String has invalid encoding: %s", s.c_str() );
                 }
 
-                int d1 = Character.digit( s.at(i + 1), 16);
-                int d2 = Character.digit( s.at(i + 2), 16);
+                int d1 = Character::digit( s.at(i + 1), 16);
+                int d2 = Character::digit( s.at(i + 2), 16);
 
                 if( d1 == -1 || d2 == -1 ) {
                     throw IllegalArgumentException(
@@ -157,7 +167,7 @@
                         s.c_str() );
                 }
 
-                result.append( (unsigned char)( ( d1 << 4 ) + d2 ) );
+                result += (unsigned char)( ( d1 << 4 ) + d2 );
                 i += 3;
 
             } while( i < s.length() && s.at(i) == '%' );
@@ -165,7 +175,7 @@
             continue;
         }
 
-        result.append(c);
+        result += c;
         i++;
     }
 

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.h?rev=674300&r1=674299&r2=674300&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIEncoderDecoder.h Sun Jul  6
07:26:55 2008
@@ -19,7 +19,7 @@
 #define _DECAF_INTERNAL_NET_URIENCODERDECODER_H_
 
 #include <decaf/util/Config.h>
-#include <decaf/net/URISyntaxException>
+#include <decaf/net/URISyntaxException.h>
 #include <string>
 
 namespace decaf{
@@ -48,7 +48,7 @@
          * @param legal - the characters allowed in the string s
          */
         static void validate( const std::string& s, const std::string& legal )
-            throw ( URISyntaxException );
+            throw ( decaf::net::URISyntaxException );
 
         /**
          * Validate a string by checking if it contains any characters other than:
@@ -61,7 +61,7 @@
          * @param legal - the characters allowed in the string s
          */
         static void validateSimple( const std::string& s, const std::string& legal
)
-            throw ( URISyntaxException );
+            throw ( decaf::net::URISyntaxException );
 
         /**
          * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9')



Mime
View raw message