Skip to content

Commit

Permalink
Add jerry_module_path_join_and_normalize far more simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
lygstate committed Dec 11, 2024
1 parent 8339d8b commit 64cd6b0
Show file tree
Hide file tree
Showing 4 changed files with 571 additions and 93 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ if(ENABLE_TESTS)
create_test(DEFAULT join navigate_back)
create_test(DEFAULT join empty)
create_test(DEFAULT join two_absolute)
create_test(DEFAULT join two_absolute_module)
create_test(DEFAULT join two_unc)
create_test(DEFAULT join with_two_roots)
create_test(DEFAULT join back_after_root)
create_test(DEFAULT join relative_back_after_root)
create_test(DEFAULT join relative_back_after_root_module)
create_test(DEFAULT join multiple)
create_test(DEFAULT normalize do_nothing)
create_test(DEFAULT normalize navigate_back)
Expand Down
23 changes: 23 additions & 0 deletions include/cpj.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ CPJ_PUBLIC size_t cpj_path_get_relative(enum cpj_path_style path_style,
CPJ_PUBLIC size_t cpj_path_join(enum cpj_path_style path_style,
const char *path_a, const char *path_b, char *buffer, size_t buffer_size);

/**
* @brief Joins two paths together.
*
* This function generates a new path by combining the two submitted paths. It
* will remove double separators, and unlike cpj_path_get_absolute it permits
* the use of two relative paths to combine. The result will be written to a
* buffer, which might be truncated if the buffer is not large enough to hold
* the full path. However, the truncated result will always be
* null-terminated. The returned value is the amount of characters which the
* resulting path would take if it was not truncated (excluding the
* null-terminating character).
*
* @param path_style Style depending on the operating system. So this should
* detect whether we should use windows or unix paths.
* @param path_a The first path which comes first.
* @param path_b The second path which comes after the first.
* @param buffer The buffer where the result will be written to.
* @param buffer_size The size of the result buffer.
* @return Returns the total amount of characters of the full, combined path.
*/
CPJ_PUBLIC size_t cpj_path_join_module(enum cpj_path_style path_style,
const char *path_a, const char *path_b, char *buffer, size_t buffer_size);

/**
* @brief Joins multiple paths together.
*
Expand Down
Loading

0 comments on commit 64cd6b0

Please sign in to comment.