Exemplo n.º 1
0
Zstring zen::getFormattedDirectoryPath(const Zstring& dirpassPhrase) // throw()
{
    //formatting is needed since functions expect the directory to end with '\' to be able to split the relative names.

    Zstring dirpath = dirpassPhrase;

    //remove leading/trailing whitespace before allowing misinterpretation in applyLongPathPrefix()
    trim(dirpath, true, false);
    while (endsWith(dirpath, Zstr(' '))) //don't remove all whitespace from right, e.g. 0xa0 may be used as part of dir name
        dirpath.resize(dirpath.size() - 1);

    if (dirpath.empty()) //an empty string would later be resolved as "\"; this is not desired
        return Zstring();

    dirpath = expandMacros(dirpath);
    dirpath = expandVolumeName(dirpath); //may block for slow USB sticks!
    /*
    need to resolve relative paths:
    WINDOWS:
     - \\?\-prefix which needs absolute names
     - Volume Shadow Copy: volume name needs to be part of each file path
     - file icon buffer (at least for extensions that are actually read from disk, like "exe")
     - ::SHFileOperation(): Using relative path names is not thread safe
    WINDOWS/LINUX:
     - detection of dependent directories, e.g. "\" and "C:\test"
     */
    dirpath = resolveRelativePath(dirpath);

    return appendSeparator(dirpath);
}
Exemplo n.º 2
0
Zstring makeUpperCopy(const Zstring& str)
{
    const size_t len = str.size();

    Zstring output;
    output.resize(len);

    std::transform(str.begin(), str.end(), output.begin(), [](char c) {
        return static_cast<char>(::toupper(static_cast<unsigned char>(c)));
    }); //locale-dependent!

    //result of toupper() is an unsigned char mapped to int range, so the char representation is in the last 8 bits and we need not care about signedness!
    //this should work for UTF-8, too: all chars >= 128 are mapped upon themselves!

    return output;
}