diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-09-25 17:59:25 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-09-25 17:59:25 -0400 |
commit | bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6 (patch) | |
tree | e6e430aff788ded4e2e64d4a774c55b1f1dc0cb9 /cpp/src | |
parent | Fixed VC8 compilation error (diff) | |
download | ice-bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6.tar.bz2 ice-bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6.tar.xz ice-bf92b3d33fdf15bc8eacacb1baf35fdd17131ee6.zip |
Fixed bug #2440
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Glacier2/FilterManager.cpp | 67 | ||||
-rw-r--r-- | cpp/src/IceUtil/StringUtil.cpp | 43 | ||||
-rw-r--r-- | cpp/src/Slice/PythonUtil.cpp | 48 | ||||
-rw-r--r-- | cpp/src/Slice/RubyUtil.cpp | 42 | ||||
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 4 |
5 files changed, 52 insertions, 152 deletions
diff --git a/cpp/src/Glacier2/FilterManager.cpp b/cpp/src/Glacier2/FilterManager.cpp index 492ad3c78e2..48112725aa6 100755 --- a/cpp/src/Glacier2/FilterManager.cpp +++ b/cpp/src/Glacier2/FilterManager.cpp @@ -10,6 +10,7 @@ #include <Ice/Communicator.h> #include <Ice/Logger.h> #include <Ice/Properties.h> +#include <IceUtil/IceUtil.h> #include <Glacier2/FilterManager.h> #include <Glacier2/FilterI.h> @@ -23,71 +24,11 @@ using namespace Ice; static void stringToSeq(const string& str, vector<string>& seq) { - string const ws = " \t"; - + IceUtil::splitString(str, " \t", seq); + // - // Eat white space. + // TODO: do something about unmatched quotes // - string::size_type current = str.find_first_not_of(ws, 0); - string::size_type end = 0; - while(current != string::npos) - { - switch(str[current]) - { - case '"': - case '\'': - { - char quote = str[current]; - end = current+1; - while(true) - { - end = str.find(quote, end); - - if(end == string::npos) - { - // - // TODO: should this be an unmatched quote error? - // - seq.push_back(str.substr(current)); - break; - } - - bool markString = true; - for(string::size_type r = end -1 ; r > current && str[r] == '\\' ; --r) - { - markString = !markString; - } - // - // We don't want the quote so we skip that. - // - if(markString) - { - ++current; - seq.push_back(str.substr(current, end-current)); - break; - } - else - { - ++end; - } - } - if(end != string::npos) - { - ++end; - } - break; - } - - default: - { - end = str.find_first_of(ws, current); - string::size_type len = (end == string::npos) ? string::npos : end - current; - seq.push_back(str.substr(current, len)); - break; - } - } - current = str.find_first_not_of(ws, end); - } } static void diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp index 30029300f59..92acea288ca 100644 --- a/cpp/src/IceUtil/StringUtil.cpp +++ b/cpp/src/IceUtil/StringUtil.cpp @@ -308,6 +308,49 @@ IceUtil::unescapeString(const string& s, string::size_type start, string::size_t } } +bool +IceUtil::splitString(const string& str, const string& delim, vector<string>& result) +{ + string::size_type beg; + string::size_type end = 0; + while(true) + { + beg = str.find_first_not_of(delim, end); + if(beg == string::npos) + { + break; + } + + // + // Check for quoted argument. + // + char ch = str[beg]; + if(ch == '"' || ch == '\'') + { + beg++; + end = str.find(ch, beg); + if(end == string::npos) + { + return false; + } + result.push_back(str.substr(beg, end - beg)); + end++; // Skip end quote. + } + else + { + end = str.find_first_of(delim + "'\"", beg); + if(end == string::npos) + { + end = str.length(); + } + result.push_back(str.substr(beg, end - beg)); + } + } + + return true; +} + + // // If a single or double quotation mark is found at the start position, // then the position of the matching closing quote is returned. If no diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index 1a88d964376..2add3c47571 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -9,7 +9,7 @@ #include <Slice/PythonUtil.h> #include <Slice/Checksum.h> -#include <IceUtil/Functional.h> +#include <IceUtil/IceUtil.h> #ifdef __BCPLUSPLUS__ # include <iterator> #endif @@ -255,7 +255,7 @@ Slice::Python::ModuleVisitor::visitModuleStart(const ModulePtr& p) if(!pkg.empty()) { vector<string> v; - splitString(pkg, v, "."); + splitString(pkg, ".", v); string mod; for(vector<string>::iterator q = v.begin(); q != v.end(); ++q) { @@ -318,7 +318,7 @@ Slice::Python::CodeVisitor::visitModuleStart(const ModulePtr& p) if(!pkg.empty()) { vector<string> v; - splitString(pkg, v, "."); + splitString(pkg, ".", v); string mod; for(vector<string>::iterator q = v.begin(); q != v.end(); ++q) { @@ -1865,48 +1865,6 @@ Slice::Python::generate(const UnitPtr& un, bool all, bool checksum, const vector out << nl; // Trailing newline. } -bool -Slice::Python::splitString(const string& str, vector<string>& args, const string& delim) -{ - string::size_type beg; - string::size_type end = 0; - while(true) - { - beg = str.find_first_not_of(delim, end); - if(beg == string::npos) - { - break; - } - - // - // Check for quoted argument. - // - char ch = str[beg]; - if(ch == '"' || ch == '\'') - { - beg++; - end = str.find(ch, beg); - if(end == string::npos) - { - return false; - } - args.push_back(str.substr(beg, end - beg)); - end++; // Skip end quote. - } - else - { - end = str.find_first_of(delim + "'\"", beg); - if(end == string::npos) - { - end = str.length(); - } - args.push_back(str.substr(beg, end - beg)); - } - } - - return true; -} - string Slice::Python::scopedToName(const string& scoped) { diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp index 07bdebd46d6..b0f9f82a8ae 100644 --- a/cpp/src/Slice/RubyUtil.cpp +++ b/cpp/src/Slice/RubyUtil.cpp @@ -1684,48 +1684,6 @@ Slice::Ruby::generate(const UnitPtr& un, bool all, bool checksum, const vector<s out << nl; // Trailing newline. } -bool -Slice::Ruby::splitString(const string& str, vector<string>& args, const string& delim) -{ - string::size_type beg; - string::size_type end = 0; - while(true) - { - beg = str.find_first_not_of(delim, end); - if(beg == string::npos) - { - break; - } - - // - // Check for quoted argument. - // - char ch = str[beg]; - if(ch == '"' || ch == '\'') - { - beg++; - end = str.find(ch, beg); - if(end == string::npos) - { - return false; - } - args.push_back(str.substr(beg, end - beg)); - end++; // Skip end quote. - } - else - { - end = str.find_first_of(delim + "'\"", beg); - if(end == string::npos) - { - end = str.length(); - } - args.push_back(str.substr(beg, end - beg)); - } - } - - return true; -} - string Slice::Ruby::fixIdent(const string& ident, IdentStyle style) { diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index a038f99002e..de1bbf839a2 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -8,7 +8,7 @@ // ********************************************************************** #include <IceUtil/DisableWarnings.h> -#include <IceUtil/Options.h> +#include <IceUtil/IceUtil.h> #include <Slice/Preprocessor.h> #include <Slice/PythonUtil.h> @@ -116,7 +116,7 @@ PackageVisitor::visitModuleStart(const ModulePtr& p) if(!package.empty()) { vector<string> v; - if(!splitString(package, v, ".")) + if(!IceUtil::splitString(package, ".", v)) { return false; } |