---------------------------------------------------------------------------------------------------------------------------- Purpose: Turns a path to a file on disk into a URL (or just returns the value if it's already a URL) ----------------------------------------------------------------------------------------------------------------------------
| 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 | // ---------------------------------------------------------------------------------------------------------------------------- |
| 880 | std::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 |
nothing calls this directly
no test coverage detected