diff options
Diffstat (limited to 'cppe/src/IceE/IdentityUtil.cpp')
-rw-r--r-- | cppe/src/IceE/IdentityUtil.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/cppe/src/IceE/IdentityUtil.cpp b/cppe/src/IceE/IdentityUtil.cpp new file mode 100644 index 00000000000..54b5f9e8ca2 --- /dev/null +++ b/cppe/src/IceE/IdentityUtil.cpp @@ -0,0 +1,90 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice-E is licensed to you under the terms described in the +// ICEE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceE/IdentityUtil.h> +#include <IceE/LocalException.h> +#include <IceE/StringUtil.h> + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +Identity +Ice::stringToIdentity(const string& s) +{ + Identity ident; + + // + // Find unescaped separator. + // + string::size_type slash = string::npos, pos = 0; + while((pos = s.find('/', pos)) != string::npos) + { + if(pos == 0 || s[pos - 1] != '\\') + { + if(slash == string::npos) + { + slash = pos; + } + else + { + // + // Extra unescaped slash found. + // + IdentityParseException ex(__FILE__, __LINE__); + ex.str = s; + throw ex; + } + } + pos++; + } + + if(slash == string::npos) + { + if(!IceUtil::unescapeString(s, 0, s.size(), ident.name)) + { + IdentityParseException ex(__FILE__, __LINE__); + ex.str = s; + throw ex; + } + } + else + { + if(!IceUtil::unescapeString(s, 0, slash, ident.category)) + { + IdentityParseException ex(__FILE__, __LINE__); + ex.str = s; + throw ex; + } + if(slash + 1 < s.size()) + { + if(!IceUtil::unescapeString(s, slash + 1, s.size(), ident.name)) + { + IdentityParseException ex(__FILE__, __LINE__); + ex.str = s; + throw ex; + } + } + } + + return ident; +} + +string +Ice::identityToString(const Identity& ident) +{ + if(ident.category.empty()) + { + return IceUtil::escapeString(ident.name, "/"); + } + else + { + return IceUtil::escapeString(ident.category, "/") + '/' + IceUtil::escapeString(ident.name, "/"); + } +} |