Exemplo n.º 1
0
const bool OTPaths::FixPath(const OTString & strPath, OTString & out_strFixedPath, const bool & bIsFolder)
{
	if (!strPath.Exists())			{ OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strPath"	); OT_ASSERT(false); }



	std::string l_strPath(strPath.Get());
	// first change all back-slashes to forward slashes:
	std::string l_strPath_noBackslash(OTString::replace_chars(l_strPath,"\\",'/'));


	// now we make sure we have the correct trailing "/".

	if ('/' == *l_strPath_noBackslash.rbegin())
	{
		if (bIsFolder)
		{
			out_strFixedPath.Set(l_strPath_noBackslash.c_str());
			return true;
		}
		else
		{
			out_strFixedPath.Set(l_strPath_noBackslash.substr(0, l_strPath_noBackslash.size()-1).c_str());
			return true;
		}
	}
	else
	{
		if (bIsFolder)
		{
			l_strPath_noBackslash += "/";
			out_strFixedPath.Set(l_strPath_noBackslash.c_str());
			return true;
		}
		else
		{
			out_strFixedPath.Set(l_strPath_noBackslash.c_str());
			return true;
		}
	}
}
Exemplo n.º 2
0
// static
bool OTPaths::FixPath(const String& strPath, String& out_strFixedPath,
                      const bool& bIsFolder)
{
    if (!strPath.Exists()) {
        otErr << __FUNCTION__ << ": Null: "
              << "strPath"
              << " passed in!\n";
        OT_FAIL;
    }

    std::string l_strPath(strPath.Get());
    // first change all back-slashes to forward slashes:
    std::string l_strPath_noBackslash(
        String::replace_chars(l_strPath, "\\", '/'));

    // now we make sure we have the correct trailing "/".

    if ('/' == *l_strPath_noBackslash.rbegin()) {
        if (bIsFolder) {
            out_strFixedPath.Set(l_strPath_noBackslash.c_str());
            return true;
        }
        else {
            out_strFixedPath.Set(
                l_strPath_noBackslash.substr(0, l_strPath_noBackslash.size() -
                                                    1).c_str());
            return true;
        }
    }
    else {
        if (bIsFolder) {
            l_strPath_noBackslash += "/";
            out_strFixedPath.Set(l_strPath_noBackslash.c_str());
            return true;
        }
        else {
            out_strFixedPath.Set(l_strPath_noBackslash.c_str());
            return true;
        }
    }
}