From f24e7084d5ebce8689e02d5f322d175d4108cf00 Mon Sep 17 00:00:00 2001 From: Dwayne Boone Date: Wed, 9 Jan 2008 10:46:08 -0330 Subject: Use mcpp instead of icecpp --- cpp/src/Slice/Util.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 cpp/src/Slice/Util.cpp (limited to 'cpp/src/Slice/Util.cpp') diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp new file mode 100644 index 00000000000..1c4e82ff0f4 --- /dev/null +++ b/cpp/src/Slice/Util.cpp @@ -0,0 +1,85 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include +#include + +#ifdef __hpux +# include +#endif + +using namespace std; +using namespace Slice; + +string +Slice::getCwd() +{ +#ifdef _WIN32 + wchar_t cwdbuf[_MAX_PATH]; + if(_wgetcwd(cwdbuf, _MAX_PATH) != NULL) + { + return IceUtil::wstringToString(cwdbuf); + } +#else + char cwdbuf[PATH_MAX]; + if(::getcwd(cwdbuf, PATH_MAX) != NULL) + { + return cwdbuf; + } +#endif + return ""; +} + +bool +Slice::isAbsolute(const string& path) +{ +#ifdef _WIN32 + if(path[0] == '\\' || path[0] == '/' || path.size() > 1 && isalpha(path[0]) && path[1] == ':') +#else + if(path[0] == '/') +#endif + { + return true; + } + + return false; +} + +string +Slice::normalizePath(const string& path, bool removeDriveLetter) +{ + string result = path; + replace(result.begin(), result.end(), '\\', '/'); + string::size_type pos; + while((pos = result.find("//")) != string::npos) + { + result.replace(pos, 2, "/"); + } + pos = 0; + while((pos = result.find("/..", pos)) != string::npos) + { + string::size_type last = result.find_last_of("/", pos - 1); + if(last != string::npos && result.substr(last, 4) != "/../") + { + result.erase(last, pos - last + 3); + pos = last; + } + else + { + ++pos; + } + } + + if(removeDriveLetter && result.size() > 1 && isalpha(result[0]) && result[1] == ':') + { + result = result.substr(2); + } + + return result; +} -- cgit v1.2.3