diff options
author | Mark Spruiell <mes@zeroc.com> | 2004-09-03 22:18:01 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2004-09-03 22:18:01 +0000 |
commit | 4cc07e685727da155c0fc372b3d1ab25805e15ac (patch) | |
tree | 1d9827e41d0f56561cde8664d72372cef5f42ad7 /py/modules/IcePy/Util.cpp | |
parent | test fixes (diff) | |
download | ice-4cc07e685727da155c0fc372b3d1ab25805e15ac.tar.bz2 ice-4cc07e685727da155c0fc372b3d1ab25805e15ac.tar.xz ice-4cc07e685727da155c0fc372b3d1ab25805e15ac.zip |
eliminating duplicate functions in Util and PythonUtil
Diffstat (limited to 'py/modules/IcePy/Util.cpp')
-rw-r--r-- | py/modules/IcePy/Util.cpp | 134 |
1 files changed, 2 insertions, 132 deletions
diff --git a/py/modules/IcePy/Util.cpp b/py/modules/IcePy/Util.cpp index 990cbb4b569..a25677805e9 100644 --- a/py/modules/IcePy/Util.cpp +++ b/py/modules/IcePy/Util.cpp @@ -10,8 +10,10 @@ #include <Util.h> #include <Identity.h> #include <Ice/LocalException.h> +#include <Slice/PythonUtil.h> using namespace std; +using namespace Slice::Python; IcePy::PyObjectHandle::PyObjectHandle(PyObject* p) : _p(p) @@ -183,138 +185,6 @@ IcePy::contextToDictionary(const Ice::Context& ctx, PyObject* dict) return true; } -bool -IcePy::splitString(const string& str, Ice::StringSeq& args) -{ - string delim = " \t\n\r"; - 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) - { - PyErr_Format(PyExc_RuntimeError, "unterminated quote in `%s'", str.c_str()); - 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 -IcePy::scopedToName(const string& scoped) -{ - string result = fixIdent(scoped); - if(result.find("::") == 0) - { - result.erase(0, 2); - } - - string::size_type pos; - while((pos = result.find("::")) != string::npos) - { - result.replace(pos, 2, "."); - } - - return result; -} - -static string -lookupKwd(const string& name) -{ - // - // Keyword list. *Must* be kept in alphabetical order. - // - static const string keywordList[] = - { - "and", "assert", "break", "class", "continue", "def", "del", "elif", "else", "except", "exec", - "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "not", "or", "pass", - "print", "raise", "return", "try", "while", "yield" - }; - bool found = binary_search(&keywordList[0], - &keywordList[sizeof(keywordList) / sizeof(*keywordList)], - name); - return found ? "_" + name : name; -} - -// -// Split a scoped name into its components and return the components as a list of (unscoped) identifiers. -// -static Ice::StringSeq -splitScopedName(const string& scoped) -{ - assert(scoped[0] == ':'); - Ice::StringSeq ids; - string::size_type next = 0; - string::size_type pos; - while((pos = scoped.find("::", next)) != string::npos) - { - pos += 2; - if(pos != scoped.size()) - { - string::size_type endpos = scoped.find("::", pos); - if(endpos != string::npos) - { - ids.push_back(scoped.substr(pos, endpos - pos)); - } - } - next = pos; - } - if(next != scoped.size()) - { - ids.push_back(scoped.substr(next)); - } - else - { - ids.push_back(""); - } - - return ids; -} - -string -IcePy::fixIdent(const string& ident) -{ - if(ident[0] != ':') - { - return lookupKwd(ident); - } - Ice::StringSeq ids = splitScopedName(ident); - transform(ids.begin(), ids.end(), ids.begin(), ptr_fun(lookupKwd)); - stringstream result; - for(Ice::StringSeq::const_iterator i = ids.begin(); i != ids.end(); ++i) - { - result << "::" + *i; - } - return result.str(); -} - PyObject* IcePy::lookupType(const string& typeName) { |