fixed normalization without segment

This commit is contained in:
Leonard Iklé committed 2018-09-02 01:47:14 +02:00
1 parent 4b66b93e89
commit b74ed69aec
7 files changed
+56 -34

No files matched your search

+1
View File
@@ -97,6 +97,7 @@ create_test(DEFAULT normalize remove_current)
create_test(DEFAULT normalize mixed)
create_test(DEFAULT normalize overlap)
create_test(DEFAULT normalize empty)
create_test(DEFAULT normalize only_separators)
create_test(DEFAULT segment first)
create_test(DEFAULT segment last)
create_test(DEFAULT segment next)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

+8 -6
View File
@@ -701,9 +701,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="309.96846"
inkscape:cy="94.127192"
inkscape:zoom="0.98994949"
inkscape:cx="461.05643"
inkscape:cy="9.8466849"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
@@ -802,9 +802,11 @@
id="tspan1120"
x="261.41824"
y="250.22784"
style="font-style:normal;font-variant:normal;font-weight:900;font-stretch:normal;font-size:22.57777786px;font-family:'Montserrat Alternates';-inkscape-font-specification:'Montserrat Alternates Heavy';text-align:end;text-anchor:end;fill:#216778;stroke-width:0.26458332px">c<tspan
style="fill:#37abc8"
id="tspan1128">walk</tspan></tspan></text>
style="font-style:normal;font-variant:normal;font-weight:900;font-stretch:normal;font-size:22.57777786px;font-family:'Montserrat Alternates';-inkscape-font-specification:'Montserrat Alternates Heavy';text-align:end;text-anchor:end;fill:#216778;stroke-width:0.26458332px"><tspan
style="fill:#217821"
id="tspan1784">c</tspan><tspan
style="fill:#5fd35f"
id="tspan1128">walk</tspan></tspan></text>
<path
style="opacity:1;fill:#37c871;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal"
d="m 24.321527,286.84376 4.625731,-8.012 4.633571,8.02558 z"

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

+19 -20
View File
@@ -47,21 +47,23 @@ enum cwk_path_style
/**
* @brief Generates an absolute path based on a base.
*
* This function generates an absolute path based on a base path and a relative
* path. 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).
* This function generates an absolute path based on a base path and another
* path. It is guaranteed to return an absolute path. If the second submitted
* path is absolute, it will override the base path. 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 base The base path on which the relative path will be applied.
* @param path The relative path which will be applied on the base path.
* @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 path.
* @return Returns the total amount of characters of the new absolute path.
*/
size_t cwk_path_get_absolute_path(const char *base, const char *path,
char *buffer, size_t buffer_size);
size_t cwk_path_get_absolute(const char *base, const char *path, char *buffer,
size_t buffer_size);
/**
* @brief Generates a relative path based on a base.
@@ -79,25 +81,25 @@ size_t cwk_path_get_absolute_path(const char *base, const char *path,
* @param buffer_size The size of the result buffer.
* @return Returns the total amount of characters of the full path.
*/
size_t cwk_path_get_relative_path(const char *base, const char *path,
char *buffer, size_t buffer_size);
size_t cwk_path_get_relative(const char *base, const char *path, 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, but unlike the absolute path function it will
* not resolve relative back-links. 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
* will remove double separators, and unlike cwk_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_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 path.
* @return Returns the total amount of characters of the full, combined path.
*/
size_t cwk_path_join(const char *path_a, const char *path_b, char *buffer,
size_t buffer_size);
@@ -194,9 +196,6 @@ bool cwk_path_get_extension(const char *path, const char **extension,
*/
bool cwk_path_has_extension(const char *path);
size_t cwk_path_set_extension(const char *path, const char *new_extension,
char *buffer, size_t buffer_size);
/**
* @brief Creates a normalized version of the path.
*
+3 -2
View File
@@ -480,7 +480,7 @@ static size_t cwk_path_join_and_normalize_multiple(const char **paths,
// So we just grab the first segment. If there is no segment we will always
// output a "/", since we currently only support absolute paths here.
if (!cwk_path_get_first_segment_joined(paths, &sj)) {
return pos;
goto done;
}
// Let's assume that we don't have any segment output for now. We will toggle
@@ -521,6 +521,7 @@ static size_t cwk_path_join_and_normalize_multiple(const char **paths,
// We must append a '\0' in any case, unless the buffer size is zero. If the
// buffer size is zero, which means we can not.
done:
if (buffer_size > 0) {
if (pos >= buffer_size) {
buffer[buffer_size - 1] = '\0';
@@ -534,7 +535,7 @@ static size_t cwk_path_join_and_normalize_multiple(const char **paths,
return pos;
}
size_t cwk_path_get_absolute_path(const char *base, const char *path,
size_t cwk_path_get_absolute(const char *base, const char *path,
char *buffer, size_t buffer_size)
{
size_t i;
+6 -6
View File
@@ -10,7 +10,7 @@ int absolute_too_far()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute_path("/hello/there", "../../../../../", buffer,
length = cwk_path_get_absolute("/hello/there", "../../../../../", buffer,
sizeof(buffer));
if (length != 1) {
@@ -30,7 +30,7 @@ int absolute_normalization()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute_path("/hello//../there", "test//thing", buffer,
length = cwk_path_get_absolute("/hello//../there", "test//thing", buffer,
sizeof(buffer));
if (length != 17) {
@@ -50,7 +50,7 @@ int absolute_mixed()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute_path("hello/there", "/test", buffer,
length = cwk_path_get_absolute("hello/there", "/test", buffer,
sizeof(buffer));
if (length != 5) {
@@ -70,7 +70,7 @@ int absolute_relative_base()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute_path("hello/there", "test", buffer,
length = cwk_path_get_absolute("hello/there", "test", buffer,
sizeof(buffer));
if (length != 17) {
@@ -90,7 +90,7 @@ int absolute_absolute_path()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute_path("/hello/there", "/test", buffer,
length = cwk_path_get_absolute("/hello/there", "/test", buffer,
sizeof(buffer));
if (length != 5) {
@@ -110,7 +110,7 @@ int absolute_simple()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute_path("/hello/there", "..", buffer,
length = cwk_path_get_absolute("/hello/there", "..", buffer,
sizeof(buffer));
if (length != 6) {
+19
View File
@@ -6,6 +6,25 @@
#include <stdlib.h>
#include <string.h>
int normalize_only_separators()
{
size_t count;
char result[FILENAME_MAX];
char *input, *expected;
cwk_path_set_style(CWK_STYLE_UNIX);
input = "////";
strcpy(result, input);
expected = "/";
count = cwk_path_normalize(result, result, sizeof(result));
if (count != strlen(expected) || strcmp(result, expected) != 0) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int normalize_empty()
{
size_t count;