Example #1
0
 MistString Path::GetFileNameWithoutExtension(const MistString& path) {
     MistString filename = Path::GetFileName(path);
     size_t rs = filename.rfind(L'.');
     if(rs != MistString::npos) {
         return MistString(filename.begin(), filename.begin() + rs);
     }
     return filename;
 }
Example #2
0
 MistString Path::GetDirectory(const MistString& path) {
     size_t rs = path.rfind(L'/');
     if(rs == MistString::npos) {
         rs = path.rfind(L'\\');
     }
     if(rs != MistString::npos) {
         return MistString(path.begin(), path.begin() + rs + 1);
     }
     return MistString(L"");
 }
Example #3
0
 MistString Path::GetFileName(const MistString& path) {
     size_t rs = path.rfind(L'/');
     if(rs == MistString::npos) {
         rs = path.rfind(L'\\');
     }
     if(rs != MistString::npos) {
         return MistString(path.begin() + (rs+1), path.end());
     }
     return path;
 }
Example #4
0
    MistString Path::ExpandPath(const MistString& path) {
#if defined(MIST_OS_WINDOWS)
        wchar_t buffer[_MAX_PATH];
        DWORD n = ExpandEnvironmentStringsW(path.c_str(), buffer, sizeof(buffer));
        if(n > 0 && n < sizeof(buffer)) {
            return MistString(buffer, n-1);
        } else
            return path;
        
#elif defined(MIST_OS_FAMILY_UNIX)
        MistString result;
        MistString::const_iterator it  = path.begin();
        MistString::const_iterator end = path.end();
        if (it != end && *it == L'~') {
            ++it;
            if (it != end && *it == L'/') {
                result += Path::GetHome(); ++it;
            }
            else result += '~';
        }
        while (it != end) {
            if (*it == L'$') {
                std::wstring var;
                ++it;
                if (it != end && *it == L'{') {
                    ++it;
                    while (it != end && *it != L'}') var += *it++;
                    if (it != end) ++it;
                }
                else {
                    while (it != end && (((*it >= L'a' && *it <= L'z') || (*it >= L'A' && *it <= L'Z') || (*it >= L'0' && *it <= L'9')) || *it == L'_')) var += *it++;
                }
                result += Path::GetEnv(var);
            }
            else result += *it++;
        }
        return result;
#endif    
    }