diff options
author | David Robillard <d@drobilla.net> | 2022-11-14 10:39:05 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-11-14 16:07:28 -0500 |
commit | 8334438cb5cb9756885248a952b9feb480eebc8c (patch) | |
tree | 3712d121273ea71f05b92a4b2e5db9b8ddade95f /src | |
parent | 655c7fcf6c7ce9f98106dfca9cff5dede749b1bd (diff) | |
download | serd-8334438cb5cb9756885248a952b9feb480eebc8c.tar.gz serd-8334438cb5cb9756885248a952b9feb480eebc8c.tar.bz2 serd-8334438cb5cb9756885248a952b9feb480eebc8c.zip |
Add Windows path separator support to serd_node_new_file_uri()
Diffstat (limited to 'src')
-rw-r--r-- | src/node.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -170,6 +170,16 @@ is_uri_path_char(const uint8_t c) } } +static bool +is_dir_sep(const char c) +{ + #ifdef _WIN32 + return c == '\\' || c == '/'; + #else + return c == '/'; + #endif +} + SerdNode serd_node_new_file_uri(const uint8_t* const path, const uint8_t* const hostname, @@ -182,7 +192,7 @@ serd_node_new_file_uri(const uint8_t* const path, size_t uri_len = 0; uint8_t* uri = NULL; - if (path[0] == '/' || is_windows) { + if (is_dir_sep(path[0]) || is_windows) { uri_len = strlen("file://") + hostname_len + is_windows; uri = (uint8_t*)calloc(uri_len + 1, 1); @@ -199,12 +209,14 @@ serd_node_new_file_uri(const uint8_t* const path, SerdChunk chunk = {uri, uri_len}; for (size_t i = 0; i < path_len; ++i) { - if (is_windows && path[i] == '\\') { - serd_chunk_sink("/", 1, &chunk); - } else if (path[i] == '%') { + if (path[i] == '%') { serd_chunk_sink("%%", 2, &chunk); } else if (!escape || is_uri_path_char(path[i])) { serd_chunk_sink(path + i, 1, &chunk); +#ifdef _WIN32 + } else if (path[i] == '\\') { + serd_chunk_sink("/", 1, &chunk); +#endif } else { char escape_str[4] = {'%', 0, 0, 0}; snprintf(escape_str + 1, sizeof(escape_str) - 1, "%X", (unsigned)path[i]); |