コード例 #1
0
ファイル: Common.cpp プロジェクト: nightwing/npp
generic_string PathAppend(generic_string &strDest, const generic_string str2append)
{
    if (strDest == TEXT("") && str2append == TEXT("")) // "" + ""
    {
        strDest = TEXT("\\");
        return strDest;
    }

    if (strDest == TEXT("") && str2append != TEXT("")) // "" + titi
    {
        strDest = str2append;
        return strDest;
    }

    if (strDest[strDest.length() - 1] == '\\' && (str2append != TEXT("") && str2append[0] == '\\')) // toto\ + \titi
    {
        strDest.erase(strDest.length() - 1, 1);
        strDest += str2append;
        return strDest;
    }

    if ((strDest[strDest.length() - 1] == '\\' && (str2append != TEXT("") && str2append[0] != '\\')) // toto\ + titi
            || (strDest[strDest.length() - 1] != '\\' && (str2append != TEXT("") && str2append[0] == '\\'))) // toto + \titi
    {
        strDest += str2append;
        return strDest;
    }

    // toto + titi
    strDest += TEXT("\\");
    strDest += str2append;

    return strDest;
}
コード例 #2
0
ファイル: Common.cpp プロジェクト: nightwing/npp
generic_string PathRemoveFileSpec(generic_string & path)
{
    generic_string::size_type lastBackslash = path.find_last_of(TEXT('\\'));
    if (lastBackslash == generic_string::npos)
    {
        if (path.size() >= 2 && path[1] == TEXT(':'))  // "C:foo.bar" becomes "C:"
            path.erase(2);
        else
            path.erase();
    }
    else
    {
        if (lastBackslash == 2 && path[1] == TEXT(':') && path.size() >= 3)  // "C:\foo.exe" becomes "C:\"
            path.erase(3);
        else if (lastBackslash == 0 && path.size() > 1)  //   "\foo.exe" becomes "\"
            path.erase(1);
        else
            path.erase(lastBackslash);
    }
    return path;
}