MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / Path_FilePathToUrl

Function Path_FilePathToUrl

src/vrcore/pathtools_public.cpp:880–903  ·  view source on GitHub ↗

---------------------------------------------------------------------------------------------------------------------------- Purpose: Turns a path to a file on disk into a URL (or just returns the value if it's already a URL) ----------------------------------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

878// Purpose: Turns a path to a file on disk into a URL (or just returns the value if it's already a URL)
879// ----------------------------------------------------------------------------------------------------------------------------
880std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::string & sBasePath )
881{
882 if ( StringHasPrefix( sRelativePath, "http://" )
883 || StringHasPrefix( sRelativePath, "https://" )
884 || StringHasPrefix( sRelativePath, "vr-input-workshop://" )
885 || StringHasPrefix( sRelativePath, "file://" )
886 )
887 {
888 return sRelativePath;
889 }
890 else
891 {
892 std::string sAbsolute = Path_MakeAbsolute( sRelativePath, sBasePath );
893 if ( sAbsolute.empty() )
894 return sAbsolute;
895 sAbsolute = Path_FixSlashes( sAbsolute, '/' );
896
897 size_t unBufferSize = sAbsolute.length() * 3;
898 char *pchBuffer = (char *)alloca( unBufferSize );
899 V_URLEncodeFullPath( pchBuffer, (int)unBufferSize, sAbsolute.c_str(), (int)sAbsolute.length() );
900
901 return std::string( FILE_URL_PREFIX ) + pchBuffer;
902 }
903}
904
905// -----------------------------------------------------------------------------------------------------
906// Purpose: Strips off file:// off a URL and returns the path. For other kinds of URLs an empty string is returned

Callers

nothing calls this directly

Calls 6

V_URLEncodeFullPathFunction · 0.85
emptyMethod · 0.80
StringHasPrefixFunction · 0.70
Path_MakeAbsoluteFunction · 0.70
Path_FixSlashesFunction · 0.70
lengthMethod · 0.45

Tested by

no test coverage detected