If fileUri starts with "file://", strips that prefix and URI-decodes the remaining part to a new buffer, and make outPath point to it, and returns NFD_OKAY. Otherwise, does not modify outPath and returns NFD_ERROR (with the correct error set)
| 1005 | // buffer, and make outPath point to it, and returns NFD_OKAY. Otherwise, does not modify outPath |
| 1006 | // and returns NFD_ERROR (with the correct error set) |
| 1007 | nfdresult_t AllocAndCopyFilePath(const char* fileUri, char*& outPath) { |
| 1008 | const char* prefix_begin = FILE_URI_PREFIX; |
| 1009 | const char* const prefix_end = FILE_URI_PREFIX + FILE_URI_PREFIX_LEN; |
| 1010 | for (; prefix_begin != prefix_end; ++prefix_begin, ++fileUri) { |
| 1011 | if (*prefix_begin != *fileUri) { |
| 1012 | NFDi_SetError("D-Bus freedesktop portal returned a URI that is not a file URI."); |
| 1013 | return NFD_ERROR; |
| 1014 | } |
| 1015 | } |
| 1016 | size_t decoded_len; |
| 1017 | const char* file_uri_end; |
| 1018 | if (!TryUriDecodeLen(fileUri, decoded_len, file_uri_end)) { |
| 1019 | NFDi_SetError("D-Bus freedesktop portal returned a malformed URI."); |
| 1020 | return NFD_ERROR; |
| 1021 | } |
| 1022 | char* const path_without_prefix = NFDi_Malloc<char>(decoded_len + 1); |
| 1023 | char* const out_end = UriDecodeUnchecked(fileUri, file_uri_end, path_without_prefix); |
| 1024 | *out_end = '\0'; |
| 1025 | outPath = path_without_prefix; |
| 1026 | return NFD_OKAY; |
| 1027 | } |
| 1028 | |
| 1029 | #ifdef NFD_APPEND_EXTENSION |
| 1030 | bool TryGetValidExtension(const char* extn, |
no test coverage detected