Beispiel #1
0
/** Makes an absolute path from a relative path and a base path */
std::string Path_MakeAbsolute(const std::string & sRelativePath, const std::string & sBasePath)
{
	if (Path_IsAbsolute(sRelativePath))
		return Path_Compact(sRelativePath);
	else
	{
		if (!Path_IsAbsolute(sBasePath))
			return "";

		std::string sCompacted = Path_Compact(Path_Join(sBasePath, sRelativePath));
		if (Path_IsAbsolute(sCompacted))
			return sCompacted;
		else
			return "";
	}
}
TEST( PathTools, IsAbsolute )
{
	EXPECT_TRUE( Path_IsAbsolute( "/something/long/and/gnarly.txt" ) );
	EXPECT_TRUE( Path_IsAbsolute( "\\something\\long\\and\\gnarly.txt" ) );
	EXPECT_TRUE( Path_IsAbsolute( "/simplefile.txt" ) );
	EXPECT_TRUE( Path_IsAbsolute( "c:\\simplefile.txt" ) );
	EXPECT_FALSE( Path_IsAbsolute( "simplefile.txt" ) );
	EXPECT_FALSE( Path_IsAbsolute( "..\\simplefile.txt" ) );
	EXPECT_FALSE( Path_IsAbsolute( "../simplefile.txt" ) );
	EXPECT_FALSE( Path_IsAbsolute( "dirname/simplefile.txt" ) );
}