Skip to content
Browse files

Some cleanup

  • Loading branch information...
1 parent afaf8de commit 81e530cb3f878be7496c940a93f3744d429feea3 @tabish121 tabish121 committed Oct 21, 2013
Showing with 315 additions and 334 deletions.
  1. +285 −301 activemq-cpp/src/main/decaf/net/URI.cpp
  2. +30 −33 activemq-cpp/src/main/decaf/net/URI.h
View
586 activemq-cpp/src/main/decaf/net/URI.cpp
@@ -44,220 +44,214 @@ URI::URI() : uri(), uriString() {
}
////////////////////////////////////////////////////////////////////////////////
-URI::URI( const URI& uri ) : uri(uri.uri), uriString(uri.uriString) {
+URI::URI(const URI& uri) : uri(uri.uri), uriString(uri.uriString) {
}
////////////////////////////////////////////////////////////////////////////////
-URI::URI( const std::string& uri ) : uri(), uriString(uri) {
- this->parseURI( uri, false );
+URI::URI(const std::string& uri) : uri(), uriString(uri) {
+ this->parseURI(uri, false);
}
////////////////////////////////////////////////////////////////////////////////
-URI::URI( const std::string& scheme, const std::string& ssp, const std::string& fragment ) : uri(), uriString() {
+URI::URI(const std::string& scheme, const std::string& ssp, const std::string& fragment) : uri(), uriString() {
std::string uri = "";
- if( scheme != "" ) {
- uri.append( scheme );
- uri.append( ":" );
+ if (scheme != "") {
+ uri.append(scheme);
+ uri.append(":");
}
- if( ssp != "" ) {
+ if (ssp != "") {
// QUOTE ILLEGAL CHARACTERS
- uri.append( quoteComponent( ssp, allLegal ) );
+ uri.append(quoteComponent(ssp, allLegal));
}
- if( fragment != "" ) {
- uri.append( "#" );
+ if (fragment != "") {
+ uri.append("#");
// QUOTE ILLEGAL CHARACTERS
- uri.append( quoteComponent( fragment, allLegal ) );
+ uri.append(quoteComponent(fragment, allLegal));
}
// Now hand of to the main parse function.
- this->parseURI( uri, false );
+ this->parseURI(uri, false);
}
////////////////////////////////////////////////////////////////////////////////
-URI::URI( const std::string& scheme, const std::string& userInfo,
- const std::string& host, int port,
- const std::string& path, const std::string& query,
- const std::string& fragment ) : uri(), uriString() {
-
- if( scheme == "" && userInfo == "" && host == "" &&
- path == "" && query == "" && fragment == "" ) {
+URI::URI(const std::string& scheme, const std::string& userInfo,
+ const std::string& host, int port,
+ const std::string& path, const std::string& query,
+ const std::string& fragment) : uri(), uriString() {
+ if (scheme == "" && userInfo == "" && host == "" && path == "" && query == "" && fragment == "") {
return;
}
- if( scheme != "" && !path.empty() && path.at(0) != '/') {
-
+ if (scheme != "" && !path.empty() && path.at(0) != '/') {
throw URISyntaxException(
__FILE__, __LINE__, path,
"URI::URI - Path string: %s starts with invalid char '/'" );
}
std::string uri = "";
- if( scheme != "" ) {
- uri.append( scheme );
- uri.append( ":" );
+ if (scheme != "") {
+ uri.append(scheme);
+ uri.append(":");
}
- uri.append( "//" );
+ uri.append("//");
- if( userInfo != "" ) {
+ if (userInfo != "") {
// QUOTE ILLEGAL CHARACTERS in userinfo
- uri.append(quoteComponent( userInfo, someLegal ) );
- uri.append( "@" );
+ uri.append(quoteComponent(userInfo, someLegal));
+ uri.append("@");
}
- if( host != "" ) {
+ if (host != "") {
std::string newHost = host;
// check for ipv6 addresses that hasn't been enclosed
// in square brackets
- if( host.find( ":" ) != std::string::npos &&
- host.find( "]" ) == std::string::npos &&
- host.find( "[" ) == std::string::npos ) {
+ if (host.find(":") != std::string::npos &&
+ host.find("]") == std::string::npos &&
+ host.find("[") == std::string::npos) {
- newHost = std::string( "[" ) + host + "]";
+ newHost = std::string("[") + host + "]";
}
- uri.append( newHost );
+ uri.append(newHost);
}
- if( port != -1 ) {
- uri.append( ":" );
- uri.append( Integer::toString( port ) );
+ if (port != -1) {
+ uri.append(":");
+ uri.append(Integer::toString(port));
}
- if( path != "" ) {
+ if (path != "") {
// QUOTE ILLEGAL CHARS
- uri.append( quoteComponent( path, "/@" + someLegal ) );
+ uri.append(quoteComponent(path, "/@" + someLegal));
}
- if( query != "" ) {
- uri.append( "?" );
+ if (query != "") {
+ uri.append("?");
// QUOTE ILLEGAL CHARS
- uri.append( quoteComponent( query, allLegal ) );
+ uri.append(quoteComponent(query, allLegal));
}
- if( fragment != "" ) {
+ if (fragment != "") {
// QUOTE ILLEGAL CHARS
- uri.append( "#" );
- uri.append( quoteComponent( fragment, allLegal ) );
+ uri.append("#");
+ uri.append(quoteComponent(fragment, allLegal));
}
- this->parseURI( uri, true );
+ this->parseURI(uri, true);
}
////////////////////////////////////////////////////////////////////////////////
-URI::URI( const std::string& scheme, const std::string& host,
- const std::string& path, const std::string& fragment ) : uri(), uriString() {
+URI::URI(const std::string& scheme, const std::string& host,
+ const std::string& path, const std::string& fragment) : uri(), uriString() {
- if( scheme == "" && host == "" && path == "" && fragment == "" ) {
+ if (scheme == "" && host == "" && path == "" && fragment == "") {
return;
}
- if( scheme != "" && !path.empty() && path.at(0) != '/') {
-
+ if (scheme != "" && !path.empty() && path.at(0) != '/') {
throw URISyntaxException(
__FILE__, __LINE__, path,
"URI::URI - Path string: %s starts with invalid char '/'" );
}
std::string uri = "";
- if( scheme != "" ) {
- uri.append( scheme );
- uri.append( ":" );
+ if (scheme != "") {
+ uri.append(scheme);
+ uri.append(":");
}
- if( host != "" ) {
- uri.append( "//" );
+ if (host != "") {
+ uri.append("//");
}
- if( host != "" ) {
+ if (host != "") {
std::string newHost = host;
// check for ipv6 addresses that hasn't been enclosed
// in square brackets
- if( host.find( ":" ) != std::string::npos &&
- host.find( "]" ) == std::string::npos &&
- host.find( "[" ) == std::string::npos ) {
+ if (host.find(":") != std::string::npos &&
+ host.find("]") == std::string::npos &&
+ host.find("[") == std::string::npos) {
- newHost = std::string( "[" ) + host + "]";
+ newHost = std::string("[") + host + "]";
}
- uri.append( newHost );
+ uri.append(newHost);
}
- if( path != "" ) {
+ if (path != "") {
// QUOTE ILLEGAL CHARS
- uri.append( quoteComponent( path, "/@" + someLegal ) );
+ uri.append(quoteComponent(path, "/@" + someLegal));
}
- if( fragment != "" ) {
+ if (fragment != "") {
// QUOTE ILLEGAL CHARS
- uri.append( "#" );
- uri.append( quoteComponent( fragment, allLegal ) );
+ uri.append("#");
+ uri.append(quoteComponent(fragment, allLegal));
}
- this->parseURI( uri, true );
-
+ this->parseURI(uri, true);
}
////////////////////////////////////////////////////////////////////////////////
-URI::URI( const std::string& scheme, const std::string& authority,
- const std::string& path, const std::string& query,
- const std::string& fragment ) : uri(), uriString() {
+URI::URI(const std::string& scheme, const std::string& authority,
+ const std::string& path, const std::string& query,
+ const std::string& fragment) : uri(), uriString() {
- if( scheme != "" && !path.empty() && path.at(0) != '/' ) {
+ if (scheme != "" && !path.empty() && path.at(0) != '/') {
throw URISyntaxException(
__FILE__, __LINE__, path,
"URI::URI - Path String %s must start with a '/'" );
}
- std::string uri = "";
+ std::string uri = "";
- if( scheme != "" ) {
- uri.append( scheme );
- uri.append( ":" );
- }
+ if (scheme != "") {
+ uri.append(scheme);
+ uri.append(":");
+ }
- uri.append("//");
+ uri.append("//");
- if( authority != "" ) {
- // QUOTE ILLEGAL CHARS
- uri.append( quoteComponent( authority, "@[]" + someLegal ) );
- }
+ if (authority != "") {
+ // QUOTE ILLEGAL CHARS
+ uri.append(quoteComponent(authority, "@[]" + someLegal));
+ }
- if( path != "" ) {
- // QUOTE ILLEGAL CHARS
- uri.append( quoteComponent( path, "/@" + someLegal ) );
- }
+ if (path != "") {
+ // QUOTE ILLEGAL CHARS
+ uri.append(quoteComponent(path, "/@" + someLegal));
+ }
- if( query != "" ) {
- // QUOTE ILLEGAL CHARS
- uri.append( "?" );
- uri.append( quoteComponent( query, allLegal ) );
- }
+ if (query != "") {
+ // QUOTE ILLEGAL CHARS
+ uri.append("?");
+ uri.append(quoteComponent(query, allLegal));
+ }
- if( fragment != "" ) {
- // QUOTE ILLEGAL CHARS
- uri.append( "#" );
- uri.append( quoteComponent( fragment, allLegal ) );
- }
+ if (fragment != "") {
+ // QUOTE ILLEGAL CHARS
+ uri.append("#");
+ uri.append(quoteComponent(fragment, allLegal));
+ }
- this->parseURI( uri, false );
+ this->parseURI(uri, false);
}
////////////////////////////////////////////////////////////////////////////////
-void URI::parseURI( const std::string& uri, bool forceServer ) {
-
- try{
- this->uri = URIHelper().parseURI( uri, forceServer );
+void URI::parseURI(const std::string& uri, bool forceServer) {
+ try {
+ this->uri = URIHelper().parseURI(uri, forceServer);
}
- DECAF_CATCH_RETHROW( URISyntaxException )
- DECAF_CATCHALL_THROW( URISyntaxException )
+ DECAF_CATCH_RETHROW(URISyntaxException)
+ DECAF_CATCHALL_THROW(URISyntaxException)
}
////////////////////////////////////////////////////////////////////////////////
@@ -266,103 +260,100 @@ int URI::compareTo( const URI& uri ) const {
int ret = 0;
// compare schemes
- if( this->uri.getScheme() == "" && uri.getScheme() != "" ) {
+ if (this->uri.getScheme() == "" && uri.getScheme() != "") {
return -1;
- } else if( this->uri.getScheme() != "" && uri.getScheme() == "" ) {
+ } else if (this->uri.getScheme() != "" && uri.getScheme() == "") {
return 1;
- } else if( this->uri.getScheme() != "" && uri.getScheme() != "" ) {
+ } else if (this->uri.getScheme() != "" && uri.getScheme() != "") {
ret = StringUtils::compareIgnoreCase(this->uri.getScheme().c_str(), uri.getScheme().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
}
// compare opacities
- if( !this->uri.isOpaque() && uri.isOpaque() ) {
+ if (!this->uri.isOpaque() && uri.isOpaque()) {
return -1;
- } else if( this->uri.isOpaque() && !uri.isOpaque() ) {
+ } else if (this->uri.isOpaque() && !uri.isOpaque()) {
return 1;
- } else if( this->uri.isOpaque() && uri.isOpaque() ) {
+ } else if (this->uri.isOpaque() && uri.isOpaque()) {
ret = StringUtils::compare(this->getSchemeSpecificPart().c_str(),
uri.getSchemeSpecificPart().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
} else {
// otherwise both must be hierarchical
// compare authorities
- if( this->uri.getAuthority() != "" && uri.getAuthority() == "" ) {
+ if (this->uri.getAuthority() != "" && uri.getAuthority() == "") {
return 1;
- } else if( this->uri.getAuthority() == "" && uri.getAuthority() != "" ) {
+ } else if (this->uri.getAuthority() == "" && uri.getAuthority() != "") {
return -1;
- } else if( this->uri.getAuthority() != "" && uri.getAuthority() != "" ) {
+ } else if (this->uri.getAuthority() != "" && uri.getAuthority() != "") {
- if( this->uri.getHost() != "" && uri.getHost() != "" ) {
+ if (this->uri.getHost() != "" && uri.getHost() != "") {
// both are server based, so compare userinfo, host, port
- if( this->getUserInfo() != "" && uri.getUserInfo() == "" ) {
+ if (this->getUserInfo() != "" && uri.getUserInfo() == "") {
return 1;
- } else if( this->getUserInfo() == "" && uri.getUserInfo() != "" ) {
+ } else if (this->getUserInfo() == "" && uri.getUserInfo() != "") {
return -1;
- } else if( this->getUserInfo() != "" && uri.getUserInfo() != "" ) {
+ } else if (this->getUserInfo() != "" && uri.getUserInfo() != "") {
ret = StringUtils::compare(this->getUserInfo().c_str(),
uri.getUserInfo().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
}
// userinfo's are the same, compare hostname
ret = StringUtils::compareIgnoreCase(this->uri.getHost().c_str(), uri.getHost().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
// compare port
- if( this->getPort() != uri.getPort() ) {
- return ( getPort() - uri.getPort() ) > 0 ? 1 : -1;
+ if (this->getPort() != uri.getPort()) {
+ return (getPort() - uri.getPort()) > 0 ? 1 : -1;
}
-
} else {
-
// one or both are registry based, compare the whole authority
ret = StringUtils::compare(this->uri.getAuthority().c_str(), uri.getAuthority().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
}
}
- // authorities are the same
- // compare paths
+ // authorities are the same, compare paths
ret = StringUtils::compare(this->getPath().c_str(), uri.getPath().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
// compare queries
- if( this->getQuery() != "" && uri.getQuery() == "" ) {
+ if (this->getQuery() != "" && uri.getQuery() == "") {
return 1;
- } else if( this->getQuery() == "" && uri.getQuery() != "" ) {
+ } else if (this->getQuery() == "" && uri.getQuery() != "") {
return -1;
- } else if( this->getQuery() != "" && uri.getQuery() != "" ) {
+ } else if (this->getQuery() != "" && uri.getQuery() != "") {
ret = StringUtils::compare(this->getQuery().c_str(), uri.getQuery().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
}
}
// everything else is identical, so compare fragments
- if( this->getFragment() != "" && uri.getFragment() == "" ) {
+ if (this->getFragment() != "" && uri.getFragment() == "") {
return 1;
- } else if( this->getFragment() == "" && uri.getFragment() != "" ) {
+ } else if (this->getFragment() == "" && uri.getFragment() != "") {
return -1;
- } else if( this->getFragment() != "" && uri.getFragment() != "" ) {
+ } else if (this->getFragment() != "" && uri.getFragment() != "") {
ret = StringUtils::compare(this->getFragment().c_str(), uri.getFragment().c_str());
- if( ret != 0 ) {
+ if (ret != 0) {
return ret > 0 ? 1 : -1;
}
}
@@ -374,49 +365,48 @@ int URI::compareTo( const URI& uri ) const {
////////////////////////////////////////////////////////////////////////////////
bool URI::equals( const URI& uri ) const {
- if( ( uri.uri.getFragment() == "" && this->uri.getFragment() != "" ) ||
- ( uri.uri.getFragment() != "" && this->uri.getFragment() == "" ) ) {
+ if ((uri.uri.getFragment() == "" && this->uri.getFragment() != "") ||
+ (uri.uri.getFragment() != "" && this->uri.getFragment() == "")) {
return false;
- } else if( uri.uri.getFragment() != "" && this->uri.getFragment() != "" ) {
+ } else if (uri.uri.getFragment() != "" && this->uri.getFragment() != "") {
- if( !equalsHexCaseInsensitive( uri.uri.getFragment(), this->uri.getFragment() ) ) {
+ if (!equalsHexCaseInsensitive(uri.uri.getFragment(), this->uri.getFragment())) {
return false;
}
}
- if( ( uri.uri.getScheme() == "" && this->uri.getScheme() != "" ) ||
- ( uri.uri.getScheme() != "" && this->uri.getScheme() == "" ) ) {
+ if ((uri.uri.getScheme() == "" && this->uri.getScheme() != "") ||
+ (uri.uri.getScheme() != "" && this->uri.getScheme() == "")) {
return false;
- } else if( uri.uri.getScheme() != "" && this->uri.getScheme() != "" ) {
+ } else if (uri.uri.getScheme() != "" && this->uri.getScheme() != "") {
- if( StringUtils::compareIgnoreCase(uri.uri.getScheme().c_str(), this->uri.getScheme().c_str() ) != 0) {
+ if (StringUtils::compareIgnoreCase(uri.uri.getScheme().c_str(), this->uri.getScheme().c_str()) != 0) {
return false;
}
}
- if( uri.uri.isOpaque() && this->uri.isOpaque() ) {
+ if (uri.uri.isOpaque() && this->uri.isOpaque()) {
return equalsHexCaseInsensitive(
- uri.uri.getSchemeSpecificPart(), this->uri.getSchemeSpecificPart() );
+ uri.uri.getSchemeSpecificPart(), this->uri.getSchemeSpecificPart());
- } else if( !uri.uri.isOpaque() && !this->uri.isOpaque() ) {
+ } else if (!uri.uri.isOpaque() && !this->uri.isOpaque()) {
- if( !equalsHexCaseInsensitive( this->uri.getPath(), uri.uri.getPath() ) ) {
+ if (!equalsHexCaseInsensitive(this->uri.getPath(), uri.uri.getPath())) {
return false;
}
- if( ( uri.uri.getQuery() != "" && this->uri.getQuery() == "" ) ||
- ( uri.uri.getQuery() == "" && this->uri.getQuery() != "" ) ) {
+ if ((uri.uri.getQuery() != "" && this->uri.getQuery() == "") ||
+ (uri.uri.getQuery() == "" && this->uri.getQuery() != "")) {
return false;
- } else if( uri.uri.getQuery() != "" && this->uri.getQuery() != "" ) {
-
- if( !equalsHexCaseInsensitive( uri.uri.getQuery(), this->uri.getQuery() ) ) {
+ } else if(uri.uri.getQuery() != "" && this->uri.getQuery() != "") {
+ if (!equalsHexCaseInsensitive(uri.uri.getQuery(), this->uri.getQuery())) {
return false;
}
}
@@ -426,36 +416,36 @@ bool URI::equals( const URI& uri ) const {
return false;
- } else if( uri.uri.getAuthority() != "" && this->uri.getAuthority() != "" ) {
+ } else if (uri.uri.getAuthority() != "" && this->uri.getAuthority() != "") {
- if( ( uri.uri.getHost() != "" && this->uri.getHost() == "" ) ||
- ( uri.uri.getHost() == "" && this->uri.getHost() != "" ) ) {
+ if ((uri.uri.getHost() != "" && this->uri.getHost() == "") ||
+ (uri.uri.getHost() == "" && this->uri.getHost() != "")) {
return false;
- } else if( uri.uri.getHost() == "" && this->uri.getHost() == "" ) {
+ } else if (uri.uri.getHost() == "" && this->uri.getHost() == "") {
// both are registry based, so compare the whole authority
return equalsHexCaseInsensitive(
- uri.uri.getAuthority(), this->uri.getAuthority() );
+ uri.uri.getAuthority(), this->uri.getAuthority());
} else { // uri.host != "" && host != "", so server-based
- if( StringUtils::compareIgnoreCase(uri.uri.getHost().c_str(), this->uri.getHost().c_str() ) != 0) {
+ if (StringUtils::compareIgnoreCase(uri.uri.getHost().c_str(), this->uri.getHost().c_str()) != 0) {
return false;
}
- if( this->uri.getPort() != uri.uri.getPort() ) {
+ if (this->uri.getPort() != uri.uri.getPort()) {
return false;
}
- if( ( uri.uri.getUserInfo() != "" && this->uri.getUserInfo() == "" ) ||
- ( uri.uri.getUserInfo() == "" && this->uri.getUserInfo() != "" ) ) {
+ if ((uri.uri.getUserInfo() != "" && this->uri.getUserInfo() == "") ||
+ (uri.uri.getUserInfo() == "" && this->uri.getUserInfo() != "")) {
return false;
- } else if( uri.uri.getUserInfo() != "" && this->uri.getUserInfo() != "" ) {
- return equalsHexCaseInsensitive( this->uri.getUserInfo(), uri.uri.getUserInfo() );
+ } else if (uri.uri.getUserInfo() != "" && this->uri.getUserInfo() != "") {
+ return equalsHexCaseInsensitive(this->uri.getUserInfo(), uri.uri.getUserInfo());
} else {
return true;
}
@@ -472,28 +462,27 @@ bool URI::equals( const URI& uri ) const {
}
////////////////////////////////////////////////////////////////////////////////
-bool URI::operator==( const URI& value ) const {
- return compareTo( value ) == 0 ? true : false;
+bool URI::operator==(const URI& value) const {
+ return compareTo(value) == 0 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////
-bool URI::operator<( const URI& value ) const {
- return compareTo( value ) == -1 ? true : false;
+bool URI::operator<(const URI& value) const {
+ return compareTo(value) == -1 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////
-URI URI::create( const std::string uri ) {
+URI URI::create(const std::string uri) {
try {
- return URI( uri );
- } catch( URISyntaxException& e ) {
- throw IllegalArgumentException( e );
+ return URI(uri);
+ } catch (URISyntaxException& e) {
+ throw IllegalArgumentException(e);
}
}
////////////////////////////////////////////////////////////////////////////////
-std::string URI::quoteComponent( const std::string& component,
- const std::string& legalset ) {
+std::string URI::quoteComponent(const std::string& component, const std::string& legalset) {
try {
@@ -505,12 +494,12 @@ std::string URI::quoteComponent( const std::string& component,
*/
return URIEncoderDecoder::quoteIllegal(component, legalset);
}
- DECAF_CATCH_RETHROW( decaf::lang::Exception )
- DECAF_CATCHALL_THROW( decaf::lang::Exception )
+ DECAF_CATCH_RETHROW(decaf::lang::Exception)
+ DECAF_CATCHALL_THROW(decaf::lang::Exception)
}
////////////////////////////////////////////////////////////////////////////////
-std::string URI::encodeOthers( const std::string& src ) const {
+std::string URI::encodeOthers(const std::string& src) const {
try {
/*
@@ -519,78 +508,77 @@ std::string URI::encodeOthers( const std::string& src ) const {
* UTF-8 char set needs to be used for encoding instead of default
* platform one 3. Only other chars need to be converted
*/
- return URIEncoderDecoder::encodeOthers( src );
+ return URIEncoderDecoder::encodeOthers(src);
}
- DECAF_CATCH_RETHROW( decaf::lang::Exception )
- DECAF_CATCHALL_THROW( decaf::lang::Exception )
+ DECAF_CATCH_RETHROW(decaf::lang::Exception)
+ DECAF_CATCHALL_THROW(decaf::lang::Exception)
}
////////////////////////////////////////////////////////////////////////////////
-std::string URI::decode( const std::string& src ) const {
+std::string URI::decode(const std::string& src) const {
- if( src == "" ) {
+ if (src == "") {
return src;
}
try {
- return URIEncoderDecoder::decode( src );
+ return URIEncoderDecoder::decode(src);
}
- DECAF_CATCH_RETHROW( decaf::lang::Exception )
- DECAF_CATCHALL_THROW( decaf::lang::Exception )
+ DECAF_CATCH_RETHROW(decaf::lang::Exception)
+ DECAF_CATCHALL_THROW(decaf::lang::Exception)
}
////////////////////////////////////////////////////////////////////////////////
-bool URI::equalsHexCaseInsensitive( const std::string& first, const std::string& second ) const {
+bool URI::equalsHexCaseInsensitive(const std::string& first, const std::string& second) const {
- if( first.find( '%' ) != second.find( '%' ) ) {
+ if (first.find('%') != second.find('%')) {
return StringUtils::compare(first.c_str(), second.c_str()) == 0;
}
std::size_t index = 0;
std::size_t previndex = 0;
- while( ( index = first.find( '%', previndex ) ) != string::npos &&
- second.find( '%', previndex ) == index ) {
+ while ((index = first.find('%', previndex)) != string::npos && second.find('%', previndex) == index) {
- bool match = first.substr( previndex, index - previndex ) ==
- second.substr( previndex, index - previndex );
+ bool match = first.substr(previndex, index - previndex) ==
+ second.substr(previndex, index - previndex);
- if( !match ) {
+ if (!match) {
return false;
}
- match = StringUtils::compareIgnoreCase(first.substr(index + 1, 3).c_str(),
- second.substr(index + 1, 3).c_str()) == 0;
+ match = StringUtils::compareIgnoreCase(
+ first.substr(index + 1, 3).c_str(), second.substr(index + 1, 3).c_str()) == 0;
- if( !match ) {
+ if (!match) {
return false;
}
index += 3;
previndex = index;
}
- return first.substr( previndex ) == second.substr( previndex );
+ return first.substr(previndex) == second.substr(previndex);
}
////////////////////////////////////////////////////////////////////////////////
-std::string URI::convertHexToLowerCase( const std::string& s ) const {
+std::string URI::convertHexToLowerCase(const std::string& s) const {
string result = "";
- if( s.find('%') == string::npos ) {
+ if (s.find('%') == string::npos) {
return s;
}
std::size_t index = 0;
std::size_t previndex = 0;
- while( ( index = s.find( '%', previndex ) ) != string::npos ) {
- result.append( s.substr( previndex, ( index - previndex ) + 1 ) );
+ while ((index = s.find('%', previndex)) != string::npos) {
+ result.append(s.substr(previndex, (index - previndex) + 1));
- string temp = s.substr( index + 1, 3 );
+ string temp = s.substr(index + 1, 3);
- for( size_t i = 0; i < temp.length(); ++i ) {
+ for (size_t i = 0; i < temp.length(); ++i) {
result.append(1, Character::toLowerCase(temp.at(i)));
}
@@ -602,9 +590,9 @@ std::string URI::convertHexToLowerCase( const std::string& s ) const {
}
////////////////////////////////////////////////////////////////////////////////
-std::string URI::normalize( const std::string& path ) const {
+std::string URI::normalize(const std::string& path) const {
- if( path == "" ) {
+ if (path == "") {
return path;
}
@@ -613,81 +601,80 @@ std::string URI::normalize( const std::string& path ) const {
std::size_t pathlen = path.length();
unsigned int size = 0;
- if( pathlen > 0 && path.at(0) != '/' ) {
+ if (pathlen > 0 && path.at(0) != '/') {
size++;
}
- while( ( index = path.find( '/', index + 1 ) ) != string::npos ) {
- if( index + 1 < pathlen && path.at( index + 1 ) != '/' ) {
+ while ((index = path.find('/', index + 1)) != string::npos) {
+ if (index + 1 < pathlen && path.at(index + 1) != '/') {
size++;
}
}
- std::vector<string> seglist( size );
- std::vector<bool> include( size );
+ std::vector<string> seglist(size);
+ std::vector<bool> include(size);
// break the path into segments and store in the list
std::size_t current = 0;
std::size_t index2 = 0;
- index = ( pathlen > 0 && path.at(0) == '/' ) ? 1 : 0;
- while( ( index2 = path.find( '/', index + 1 ) ) != string::npos ) {
- seglist[current++] = path.substr( index, index2 - index );
+ index = (pathlen > 0 && path.at(0) == '/') ? 1 : 0;
+ while ((index2 = path.find('/', index + 1)) != string::npos) {
+ seglist[current++] = path.substr(index, index2 - index);
index = index2 + 1;
}
// if current==size, then the last character was a slash
// and there are no more segments
- if( current < size ) {
- seglist[current] = path.substr( index );
+ if (current < size) {
+ seglist[current] = path.substr(index);
}
// determine which segments get included in the normalized path
- for( unsigned int i = 0; i < size; i++ ) {
+ for (unsigned int i = 0; i < size; i++) {
include[i] = true;
- if( seglist[i] == ".." ) {
+ if (seglist[i] == "..") {
int remove = i - 1;
// search back to find a segment to remove, if possible
- while( remove > -1 && !include[remove] ) {
+ while (remove > -1 && !include[remove]) {
remove--;
}
// if we find a segment to remove, remove it and the ".."
// segment
- if( remove > -1 && !( seglist[remove] == "..") ) {
+ if (remove > -1 && !(seglist[remove] == "..")) {
include[remove] = false;
include[i] = false;
}
- } else if( seglist[i] == "." ) {
+ } else if (seglist[i] == ".") {
include[i] = false;
}
}
// put the path back together
string newpath;
- if( path.at(0) == '/' ) {
- newpath.append( "/" );
+ if (path.at(0) == '/') {
+ newpath.append("/");
}
- for( unsigned int i = 0; i < seglist.size(); i++ ) {
- if( include[i] ) {
- newpath.append( seglist[i] );
- newpath.append( "/" );
+ for (unsigned int i = 0; i < seglist.size(); i++) {
+ if (include[i]) {
+ newpath.append(seglist[i]);
+ newpath.append("/");
}
}
// if we used at least one segment and the path previously ended with
// a slash and the last segment is still used, then delete the extra
// trailing '/'
- if( path.at( path.length() - 1 ) != '/' && seglist.size() > 0 &&
- include[seglist.size() - 1] ) {
+ if (path.at(path.length() - 1) != '/' && seglist.size() > 0 && include[seglist.size() - 1]) {
- newpath.erase( newpath.length() - 1, 1 );
+ newpath.erase(newpath.length() - 1, 1);
}
string result = newpath;
@@ -697,8 +684,8 @@ std::string URI::normalize( const std::string& path ) const {
index = result.find(':');
index2 = result.find('/');
- if( index != string::npos && ( index < index2 || index2 == string::npos ) ) {
- newpath.insert( 0, "./" );
+ if (index != string::npos && (index < index2 || index2 == string::npos)) {
+ newpath.insert(0, "./");
result = newpath;
}
@@ -708,21 +695,21 @@ std::string URI::normalize( const std::string& path ) const {
////////////////////////////////////////////////////////////////////////////////
URI URI::normalize() const {
- if( isOpaque() ) {
+ if (isOpaque()) {
return *this;
}
- string normalizedPath = normalize( this->uri.getPath() );
+ string normalizedPath = normalize(this->uri.getPath());
// if the path is already normalized, return this
- if( this->uri.getPath() == normalizedPath ) {
+ if (this->uri.getPath() == normalizedPath) {
return *this;
}
// get an exact copy of the URI re-calculate the scheme specific part
// since the path of the normalized URI is different from this URI.
URI result = *this;
- result.uri.setPath( normalizedPath );
+ result.uri.setPath(normalizedPath);
result.setSchemeSpecificPart();
return result;
@@ -734,19 +721,19 @@ void URI::setSchemeSpecificPart() {
// ssp = [//authority][path][?query]
string ssp;
- if( this->uri.getAuthority() != "" ) {
- ssp.append( string("//") + this->uri.getAuthority() );
+ if (this->uri.getAuthority() != "") {
+ ssp.append(string("//") + this->uri.getAuthority());
}
- if( this->uri.getPath() != "" ) {
- ssp.append( this->uri.getPath() );
+ if (this->uri.getPath() != "") {
+ ssp.append(this->uri.getPath());
}
- if( this->uri.getQuery() != "" ) {
- ssp.append( "?" + this->uri.getQuery() );
+ if (this->uri.getQuery() != "") {
+ ssp.append("?" + this->uri.getQuery());
}
- this->uri.setSchemeSpecificPart( ssp );
+ this->uri.setSchemeSpecificPart(ssp);
// reset string, so that it can be re-calculated correctly when asked.
this->uriString = "";
@@ -757,8 +744,8 @@ URI URI::parseServerAuthority() const {
URI newURI = *this;
- if( !newURI.uri.isServerAuthority() ) {
- newURI.uri = URIHelper().parseAuthority( true, this->uri.getAuthority() );
+ if (!newURI.uri.isServerAuthority()) {
+ newURI.uri = URIHelper().parseAuthority(true, this->uri.getAuthority());
}
return newURI;
@@ -767,18 +754,18 @@ URI URI::parseServerAuthority() const {
////////////////////////////////////////////////////////////////////////////////
URI URI::relativize( const URI& relative ) const {
- if( relative.isOpaque() || this->isOpaque() ) {
+ if (relative.isOpaque() || this->isOpaque()) {
return relative;
}
- if( this->uri.getScheme() == "" ? relative.uri.getScheme() != "" :
- this->uri.getScheme() != relative.uri.getScheme() ) {
+ if (this->uri.getScheme() == "" ? relative.uri.getScheme() != "" :
+ this->uri.getScheme() != relative.uri.getScheme()) {
return relative;
}
- if( this->uri.getAuthority() == "" ? relative.uri.getAuthority() != "" :
- this->uri.getAuthority() != relative.uri.getAuthority() ) {
+ if (this->uri.getAuthority() == "" ? relative.uri.getAuthority() != "" :
+ this->uri.getAuthority() != relative.uri.getAuthority()) {
return relative;
}
@@ -791,10 +778,10 @@ URI URI::relativize( const URI& relative ) const {
* if the paths aren't equal, then we need to determine if this URI's
* path is a parent path (begins with) the relative URI's path
*/
- if( thisPath != relativePath ) {
+ if (thisPath != relativePath) {
// if this URI's path doesn't end in a '/', add one
- if( thisPath.empty() || thisPath.at( thisPath.length() - 1 ) != '/' ) {
+ if (thisPath.empty() || thisPath.at(thisPath.length() - 1) != '/') {
thisPath = thisPath + '/';
}
@@ -803,53 +790,52 @@ URI URI::relativize( const URI& relative ) const {
* then just return the relative URI; the URIs have nothing in
* common
*/
- if( relativePath.find( thisPath ) != 0 ) {
+ if (relativePath.find(thisPath) != 0) {
return relative;
}
}
URI result;
- result.uri.setFragment( relative.uri.getFragment() );
- result.uri.setQuery( relative.uri.getQuery() );
+ result.uri.setFragment(relative.uri.getFragment());
+ result.uri.setQuery(relative.uri.getQuery());
// the result URI is the remainder of the relative URI's path
- result.uri.setPath( relativePath.substr( thisPath.length() ) );
+ result.uri.setPath(relativePath.substr(thisPath.length()));
result.setSchemeSpecificPart();
return result;
}
////////////////////////////////////////////////////////////////////////////////
-URI URI::resolve( const URI& relative ) const {
+URI URI::resolve(const URI& relative) const {
- if( relative.isAbsolute() || this->isOpaque() ) {
+ if (relative.isAbsolute() || this->isOpaque()) {
return relative;
}
URI result;
- if( relative.uri.getPath() == "" && relative.uri.getScheme() == "" &&
- relative.uri.getAuthority() == "" && relative.uri.getQuery() == "" &&
- relative.uri.getFragment() != "" ) {
+ if (relative.uri.getPath() == "" && relative.uri.getScheme() == "" && relative.uri.getAuthority() == ""
+ && relative.uri.getQuery() == "" && relative.uri.getFragment() != "") {
// if the relative URI only consists of fragment,
// the resolved URI is very similar to this URI,
// except that it has the fragment from the relative URI.
result = *this;
- result.uri.setFragment( relative.uri.getFragment() );
+ result.uri.setFragment(relative.uri.getFragment());
result.uriString = "";
// no need to re-calculate the scheme specific part,
// since fragment is not part of scheme specific part.
return result;
}
- if( relative.uri.getAuthority() != "" ) {
+ if (relative.uri.getAuthority() != "") {
// if the relative URI has authority,
// the resolved URI is almost the same as the relative URI,
// except that it has the scheme of this URI.
result = relative;
- result.uri.setScheme( this->uri.getScheme() );
- result.uri.setAbsolute( this->uri.isAbsolute() );
+ result.uri.setScheme(this->uri.getScheme());
+ result.uri.setAbsolute(this->uri.isAbsolute());
result.uriString = "";
} else {
@@ -859,17 +845,17 @@ URI URI::resolve( const URI& relative ) const {
// except that it has the query and fragment of the relative URI,
// and the path is different.
result = *this;
- result.uri.setFragment( relative.uri.getFragment() );
- result.uri.setQuery( relative.uri.getQuery() );
+ result.uri.setFragment(relative.uri.getFragment());
+ result.uri.setQuery(relative.uri.getQuery());
result.uriString = "";
- if( relative.uri.getPath().at(0) == '/' ) {
- result.uri.setPath( relative.uri.getPath() );
+ if (relative.uri.getPath().at(0) == '/') {
+ result.uri.setPath(relative.uri.getPath());
} else {
// resolve a relative reference
std::size_t endindex = this->uri.getPath().find_last_of('/') + 1;
- result.uri.setPath( normalize(
- this->uri.getPath().substr( 0, endindex ) + relative.uri.getPath() ) );
+ result.uri.setPath(normalize(
+ this->uri.getPath().substr(0, endindex) + relative.uri.getPath()));
}
// re-calculate the scheme specific part since
@@ -881,45 +867,44 @@ URI URI::resolve( const URI& relative ) const {
}
////////////////////////////////////////////////////////////////////////////////
-URI URI::resolve( const std::string& relative ) const {
-
- return resolve( create( relative ) );
+URI URI::resolve(const std::string& relative) const {
+ return resolve(create(relative));
}
////////////////////////////////////////////////////////////////////////////////
string URI::toString() const {
- if( this->uriString == "" ) {
+ if (this->uriString == "") {
string result = "";
- if( this->uri.getScheme() != "" ) {
- result.append( this->uri.getScheme() );
- result.append( ":" );
+ if (this->uri.getScheme() != "") {
+ result.append(this->uri.getScheme());
+ result.append(":");
}
- if( this->isOpaque() ) {
- result.append( this->uri.getSchemeSpecificPart() );
+ if (this->isOpaque()) {
+ result.append(this->uri.getSchemeSpecificPart());
} else {
- if( this->uri.getAuthority() != "" ) {
- result.append( "//" );
- result.append( this->uri.getAuthority() );
+ if (this->uri.getAuthority() != "") {
+ result.append("//");
+ result.append(this->uri.getAuthority());
}
- if( this->uri.getPath() != "" ) {
- result.append( this->uri.getPath() );
+ if (this->uri.getPath() != "") {
+ result.append(this->uri.getPath());
}
- if( this->uri.getQuery() != "" ) {
- result.append( "?" );
- result.append( this->uri.getQuery() );
+ if (this->uri.getQuery() != "") {
+ result.append("?");
+ result.append(this->uri.getQuery());
}
}
- if( this->uri.getFragment() != "" ) {
- result.append( "#" );
- result.append( this->uri.getFragment() );
+ if (this->uri.getFragment() != "") {
+ result.append("#");
+ result.append(this->uri.getFragment());
}
this->uriString = result;
@@ -931,23 +916,22 @@ string URI::toString() const {
////////////////////////////////////////////////////////////////////////////////
URL URI::toURL() const {
- if( !this->isAbsolute() ) {
+ if (!this->isAbsolute()) {
throw IllegalArgumentException(
- __FILE__, __LINE__,
- "URI is not absolute, cannot convert to an URL." );
+ __FILE__, __LINE__, "URI is not absolute, cannot convert to an URL.");
}
- return URL( this->toString() );
+ return URL(this->toString());
}
////////////////////////////////////////////////////////////////////////////////
std::string URI::getAuthority() const {
- return this->decode( this->uri.getAuthority() );
+ return this->decode(this->uri.getAuthority());
}
////////////////////////////////////////////////////////////////////////////////
std::string URI::getFragment() const {
- return this->decode( this->uri.getFragment() );
+ return this->decode(this->uri.getFragment());
}
////////////////////////////////////////////////////////////////////////////////
@@ -957,7 +941,7 @@ std::string URI::getHost() const {
////////////////////////////////////////////////////////////////////////////////
std::string URI::getPath() const {
- return this->decode( this->uri.getPath() );
+ return this->decode(this->uri.getPath());
}
////////////////////////////////////////////////////////////////////////////////
@@ -967,7 +951,7 @@ int URI::getPort() const {
////////////////////////////////////////////////////////////////////////////////
std::string URI::getQuery() const {
- return this->decode( this->uri.getQuery() );
+ return this->decode(this->uri.getQuery());
}
////////////////////////////////////////////////////////////////////////////////
@@ -1007,12 +991,12 @@ std::string URI::getScheme() const {
////////////////////////////////////////////////////////////////////////////////
std::string URI::getSchemeSpecificPart() const {
- return this->decode( this->uri.getSchemeSpecificPart() );
+ return this->decode(this->uri.getSchemeSpecificPart());
}
////////////////////////////////////////////////////////////////////////////////
std::string URI::getUserInfo() const {
- return this->decode( this->uri.getUserInfo() );
+ return this->decode(this->uri.getUserInfo());
}
////////////////////////////////////////////////////////////////////////////////
View
63 activemq-cpp/src/main/decaf/net/URI.h
@@ -27,13 +27,13 @@
#include <decaf/internal/net/URIType.h>
#include <string>
-namespace decaf{
-namespace net{
+namespace decaf {
+namespace net {
/**
* This class represents an instance of a URI as defined by RFC 2396.
*/
- class DECAF_API URI : public lang::Comparable<URI> {
+ class DECAF_API URI: public lang::Comparable<URI> {
private:
// The structure that holds the parsed URI data.
@@ -62,7 +62,7 @@ namespace net{
*
* @throws URISyntaxException if the URI passed is malformed.
*/
- URI( const URI& uri );
+ URI(const URI& uri);
/**
* Constructs a URI from the given string.
@@ -71,7 +71,7 @@ namespace net{
*
* @throws URISyntaxException if the URI passed is malformed.
*/
- URI( const std::string& uri );
+ URI(const std::string& uri);
/**
* Constructs a URI from the given components.
@@ -82,7 +82,7 @@ namespace net{
*
* @throws URISyntaxException if the URI passed is malformed.
*/
- URI( const std::string& scheme, const std::string& ssp, const std::string& fragment );
+ URI(const std::string& scheme, const std::string& ssp, const std::string& fragment);
/**
* Constructs a URI from the given components.
@@ -97,10 +97,8 @@ namespace net{
*
* @throws URISyntaxException if the URI passed is malformed.
*/
- URI( const std::string& scheme, const std::string& userInfo,
- const std::string& host, int port,
- const std::string& path, const std::string& query,
- const std::string& fragment );
+ URI(const std::string& scheme, const std::string& userInfo, const std::string& host, int port,
+ const std::string& path, const std::string& query, const std::string& fragment);
/**
* Constructs a URI from the given components.
@@ -111,8 +109,8 @@ namespace net{
*
* @throws URISyntaxException if the URI passed is malformed.
*/
- URI( const std::string& scheme, const std::string& host,
- const std::string& path, const std::string& fragment );
+ URI(const std::string& scheme, const std::string& host,
+ const std::string& path, const std::string& fragment);
/**
* Constructs a URI from the given components.
@@ -124,9 +122,9 @@ namespace net{
*
* @throws URISyntaxException if the URI passed is malformed.
*/
- URI( const std::string& scheme, const std::string& authority,
- const std::string& path, const std::string& query,
- const std::string& fragment );
+ URI(const std::string& scheme, const std::string& authority,
+ const std::string& path, const std::string& query,
+ const std::string& fragment);
virtual ~URI() {}
@@ -137,27 +135,27 @@ namespace net{
* @param value - the value to compare to this one.
* @returns zero if equal minus one if less than and one if greater than.
*/
- virtual int compareTo( const URI& value ) const;
+ virtual int compareTo(const URI& value) const;
/**
* @return true if this value is considered equal to the passed value.
*/
- virtual bool equals( const URI& value ) const;
+ virtual bool equals(const URI& value) const;
/**
* Compares equality between this object and the one passed.
* @param value - the value to be compared to this one.
* @return true if this object is equal to the one passed.
*/
- virtual bool operator==( const URI& value ) const;
+ virtual bool operator==(const URI& value) const;
/**
* Compares this object to another and returns true if this object
* is considered to be less than the one passed. This
* @param value - the value to be compared to this one.
* @return true if this object is equal to the one passed.
*/
- virtual bool operator<( const URI& value ) const;
+ virtual bool operator<(const URI& value) const;
/**
* @returns the decoded authority component of this URI.
@@ -339,7 +337,7 @@ namespace net{
* @param uri - The URI to be relativized against this URI
* @returns The resulting URI
*/
- URI relativize( const URI& uri ) const;
+ URI relativize(const URI& uri) const;
/**
* Constructs a new URI by parsing the given string and then resolving it
@@ -351,7 +349,7 @@ namespace net{
* @returns The resulting URI
* @throws IllegalArgumentException - If the given string violates RFC 2396
*/
- URI resolve( const std::string& str ) const;
+ URI resolve(const std::string& str) const;
/**
* Resolves the given URI against this URI.
@@ -389,7 +387,7 @@ namespace net{
* @param uri - The URI to be resolved against this URI
* @returns The resulting URI
*/
- URI resolve( const URI& uri ) const;
+ URI resolve(const URI& uri) const;
/**
* Returns the content of this URI as a string.
@@ -417,7 +415,8 @@ namespace net{
*/
URL toURL() const;
- public: // Static Methods
+ public:
+ // Static Methods
/**
* Creates a URI by parsing the given string.
@@ -429,7 +428,7 @@ namespace net{
*
* @throws IllegalArgumentException
*/
- static URI create( const std::string uri );
+ static URI create(const std::string uri);
private:
@@ -441,7 +440,7 @@ namespace net{
* @param forceServer - should a server authority be enforced.
* @throws URISyntaxException if an error occurs.
*/
- void parseURI( const std::string& uri, bool forceServer );
+ void parseURI(const std::string& uri, bool forceServer);
/*
* Quote illegal chars for each component, but not the others
@@ -450,8 +449,7 @@ namespace net{
* @param legalset the legal character set allowed in the component strng
* @return the converted string
*/
- std::string quoteComponent( const std::string& component,
- const std::string& legalset );
+ std::string quoteComponent(const std::string& component, const std::string& legalset);
/*
* Encode Unicode chars that are not part of US-ASCII char set into the
@@ -462,39 +460,38 @@ namespace net{
* @param src the string to be encoded
* @return the converted string
*/
- std::string encodeOthers( const std::string& src ) const;
+ std::string encodeOthers(const std::string& src) const;
/**
* Decode an encoded URI String.
*
* @param src - the encoded string
* @return the unencoded string version of src.
*/
- std::string decode( const std::string& src ) const;
+ std::string decode(const std::string& src) const;
/**
* Compare the Two Hexadecimal encoded strings and return if they are equal.
*
* @param first - First String to compare.
* @param second - The second string to compare.
*/
- bool equalsHexCaseInsensitive( const std::string& first,
- const std::string& second ) const;
+ bool equalsHexCaseInsensitive(const std::string& first, const std::string& second) const;
/*
* Takes a string that may contain hex sequences like %F1 or %2b and
* converts the hex values following the '%' to lowercase.
*
* @param s - String to convert the hex in.
*/
- std::string convertHexToLowerCase( const std::string& s ) const;
+ std::string convertHexToLowerCase(const std::string& s) const;
/*
* Normalize path, and return the resulting string.
*
* @param path - the path value to normalize.
*/
- std::string normalize( const std::string& path ) const;
+ std::string normalize(const std::string& path) const;
/**
* Helper method used to re-calculate the scheme specific part of the

0 comments on commit 81e530c

Please sign in to comment.
Something went wrong with that request. Please try again.