trunk/branch integration: Path::popFrontDirectory()

This commit is contained in:
Marian Krivos 2011-08-23 06:57:44 +00:00
parent 6b42ce0d0a
commit df683a59eb
4 changed files with 139 additions and 107 deletions

View File

@ -50,7 +50,11 @@
#elif defined(POCO_OS_FAMILY_UNIX)
#include "Path_UNIX.cpp"
#elif defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
#if defined(_WIN32_WCE)
#include "Path_WINCE.cpp"
#else
#include "Path_WIN32U.cpp"
#endif
#elif defined(POCO_OS_FAMILY_WINDOWS)
#include "Path_WIN32.cpp"
#endif
@ -521,6 +525,15 @@ void Path::popDirectory()
}
void Path::popFrontDirectory()
{
poco_assert (!_dirs.empty());
StringVec::iterator it = _dirs.begin();
_dirs.erase(it);
}
void Path::setFileName(const std::string& name)
{
_name = name;
@ -678,12 +691,14 @@ void Path::parseUnix(const std::string& path)
{
if (!name.empty() && *(name.rbegin()) == ':')
{
_device.assign(name, 0, name.length() - 1);
_absolute = true;
_device.assign(name, 0, name.length() - 1);
}
else
{
pushDirectory(name);
}
}
else pushDirectory(name);
}
else _name = name;
@ -714,11 +729,11 @@ void Path::parseWindows(const std::string& path)
char d = *it++;
if (it != end && *it == ':') // drive letter
{
if (_absolute || !(d >= 'a' && d <= 'z' || d >= 'A' && d <= 'Z')) throw PathSyntaxException(path);
if (_absolute || !((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z'))) throw PathSyntaxException(path);
_absolute = true;
_device += d;
++it;
if (it == end || *it != '\\' && *it != '/') throw PathSyntaxException(path);
if (it == end || (*it != '\\' && *it != '/')) throw PathSyntaxException(path);
++it;
}
else --it;

View File

@ -1,7 +1,7 @@
//
// Path_UNIX.cpp
//
// $Id: //poco/svn/Foundation/src/Path_UNIX.cpp#2 $
// $Id: //poco/1.4/Foundation/src/Path_UNIX.cpp#3 $
//
// Library: Foundation
// Package: Filesystem
@ -37,11 +37,13 @@
#include "Poco/Path_UNIX.h"
#include "Poco/Exception.h"
#include "Poco/Environment_UNIX.h"
#include "Poco/Ascii.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#if !defined(POCO_VXWORKS)
#include <pwd.h>
#include <cctype>
#endif
#include <climits>
@ -69,6 +71,12 @@ std::string PathImpl::currentImpl()
std::string PathImpl::homeImpl()
{
#if defined(POCO_VXWORKS)
if (EnvironmentImpl::hasImpl("HOME"))
return EnvironmentImpl::getImpl("HOME");
else
return "/";
#else
std::string path;
struct passwd* pwd = getpwuid(getuid());
if (pwd)
@ -84,6 +92,7 @@ std::string PathImpl::homeImpl()
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] != '/') path.append("/");
return path;
#endif
}
@ -107,7 +116,11 @@ std::string PathImpl::tempImpl()
std::string PathImpl::nullImpl()
{
#if defined(POCO_VXWORKS)
return "/null";
#else
return "/dev/null";
#endif
}
@ -139,7 +152,7 @@ std::string PathImpl::expandImpl(const std::string& path)
}
else
{
while (it != end && (std::isalnum(*it) || *it == '_')) var += *it++;
while (it != end && (Ascii::isAlphaNumeric(*it) || *it == '_')) var += *it++;
}
char* val = getenv(var.c_str());
if (val) result += val;

View File

@ -44,7 +44,7 @@ namespace Poco {
std::string PathImpl::currentImpl()
{
char buffer[_MAX_PATH];
char buffer[MAX_PATH];
DWORD n = GetCurrentDirectoryA(sizeof(buffer), buffer);
if (n > 0 && n < sizeof(buffer))
{
@ -70,16 +70,18 @@ std::string PathImpl::homeImpl()
std::string PathImpl::tempImpl()
{
char buffer[_MAX_PATH];
char buffer[MAX_PATH];
DWORD n = GetTempPathA(sizeof(buffer), buffer);
if (n > 0 && n < sizeof(buffer))
{
n = GetLongPathNameA(buffer.begin(), buffer.begin(), static_cast<DWORD>(buffer.size()));
if (n <= 0) throw SystemException("Cannot get temporary directory long path name");
std::string result(buffer, n);
if (result[n - 1] != '\\')
result.append("\\");
return result;
}
else throw SystemException("Cannot get current directory");
else throw SystemException("Cannot get temporary directory");
}
@ -91,7 +93,7 @@ std::string PathImpl::nullImpl()
std::string PathImpl::expandImpl(const std::string& path)
{
char buffer[_MAX_PATH];
char buffer[MAX_PATH];
DWORD n = ExpandEnvironmentStringsA(path.c_str(), buffer, sizeof(buffer));
if (n > 0 && n < sizeof(buffer))
return std::string(buffer, n - 1);

View File

@ -56,7 +56,7 @@ std::string PathImpl::currentImpl()
if (n > 0 && n <= len)
{
UnicodeConverter::toUTF8(buffer.begin(), result);
if (result[n - 1] != '\\')
if (result[result.size() - 1] != '\\')
result.append("\\");
return result;
}
@ -82,13 +82,15 @@ std::string PathImpl::tempImpl()
DWORD n = GetTempPathW(static_cast<DWORD>(buffer.size()), buffer.begin());
if (n > 0)
{
n = GetLongPathNameW(buffer.begin(), buffer.begin(), static_cast<DWORD>(buffer.size()));
if (n <= 0) throw SystemException("Cannot get temporary directory long path name");
std::string result;
UnicodeConverter::toUTF8(buffer.begin(), result);
if (result[n - 1] != '\\')
if (result[result.size() - 1] != '\\')
result.append("\\");
return result;
}
throw SystemException("Cannot get current directory");
throw SystemException("Cannot get temporary directory path");
}