mirror of
https://github.com/likle/cwalk.git
synced 2026-10-28 09:44:01 +00:00
fixed backward iteration with root
This commit is contained in:
1 parent
b74ed69aec
commit
5bbd24f359
8 files changed
+148
-35
No files matched your search
+5
-1
@@ -87,6 +87,7 @@ create_test(DEFAULT join navigate_back)
|
||||
create_test(DEFAULT join empty)
|
||||
create_test(DEFAULT join two_absolute)
|
||||
create_test(DEFAULT join two_unc)
|
||||
create_test(DEFAULT join back_after_root)
|
||||
create_test(DEFAULT normalize do_nothing)
|
||||
create_test(DEFAULT normalize navigate_back)
|
||||
create_test(DEFAULT normalize relative_too_far)
|
||||
@@ -98,11 +99,14 @@ create_test(DEFAULT normalize mixed)
|
||||
create_test(DEFAULT normalize overlap)
|
||||
create_test(DEFAULT normalize empty)
|
||||
create_test(DEFAULT normalize only_separators)
|
||||
create_test(DEFAULT normalize back_after_root)
|
||||
create_test(DEFAULT segment first)
|
||||
create_test(DEFAULT segment last)
|
||||
create_test(DEFAULT segment next)
|
||||
create_test(DEFAULT segment previous)
|
||||
create_test(DEFAULT segment previous_absolute)
|
||||
create_test(DEFAULT segment previous_relative)
|
||||
create_test(DEFAULT segment type)
|
||||
create_test(DEFAULT segment back_with_root)
|
||||
create_test(DEFAULT windows change_style)
|
||||
create_test(DEFAULT windows get_root)
|
||||
create_test(DEFAULT windows get_unc_root)
|
||||
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
+12
-12
@@ -702,8 +702,8 @@
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.98994949"
|
||||
inkscape:cx="461.05643"
|
||||
inkscape:cy="9.8466849"
|
||||
inkscape:cx="563.6607"
|
||||
inkscape:cy="49.289126"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
@@ -764,6 +764,11 @@
|
||||
d="M 152.04688 31.642578 C 113.22311 31.525841 76.032837 47.379942 40.855469 64.09375 C 27.150545 70.605365 13.532817 77.299981 0 84.162109 L 0 171.82031 L 636.22266 250 L 996.20703 250 C 962.13136 232.38114 924.56891 221.47896 889.13867 206.3125 C 824.77904 178.76237 765.74356 136.40936 697.00977 123.11133 C 651.7256 114.35013 605.03695 118.83865 559.19727 123.95117 C 513.35758 129.06369 466.96169 134.76786 421.28516 128.35938 C 375.24785 121.90027 331.75483 103.35079 290.52344 81.876953 C 269.07104 70.70427 248.02256 58.674898 225.80859 49.105469 C 203.59463 39.536039 179.98529 32.425326 155.80859 31.703125 C 154.55283 31.665613 153.29925 31.646344 152.04688 31.642578 z "
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,230.85417)"
|
||||
id="path833" />
|
||||
<path
|
||||
style="opacity:1;fill:#d5ffe6;fill-opacity:1;stroke:none;stroke-width:3.77952766;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal"
|
||||
d="M 152.04688 31.642578 C 150.71467 31.638572 149.38498 31.656459 148.05664 31.689453 C 157.99413 54.877868 203.8084 135.75946 194.45312 145.44922 L 224.25391 141.91406 C 224.62512 131.57505 179.1284 55.348352 158.27539 31.816406 C 157.45308 31.777128 156.63226 31.727729 155.80859 31.703125 C 154.55283 31.665613 153.29924 31.646344 152.04688 31.642578 z "
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,230.85417)"
|
||||
id="path1779" />
|
||||
<path
|
||||
style="fill:#80ffb3;fill-rule:evenodd;stroke:none;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 402.25781 120.0918 C 398.81967 120.06453 395.37155 120.19007 391.91992 120.47852 C 366.72686 122.58386 343.07296 133.10175 318.39062 138.57031 C 289.08359 145.0635 258.62259 144.35916 228.77539 141.16406 C 195.30031 137.58058 162.07239 130.90629 128.41016 130.38086 C 84.272134 129.6919 40.236986 139.76619 0 157.99805 L 0 239.64453 L 79.587891 250 L 588.75586 250 C 585.78955 246.78656 582.84644 243.55497 579.92969 240.31055 C 552.98948 210.34384 527.12525 178.84961 494.75586 154.84961 C 467.86012 134.90801 435.49319 120.3554 402.25781 120.0918 z "
|
||||
@@ -775,7 +780,7 @@
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,230.85417)"
|
||||
id="path894" />
|
||||
<path
|
||||
style="fill:#55ff99;fill-rule:evenodd;stroke:none;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
style="fill:#55ff99;fill-rule:evenodd;stroke:none;stroke-width:0.99999994px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;opacity:0.99"
|
||||
d="m 958.31641,144.00643 c -19.65771,-0.15764 -28.45981,6.53953 -96.42057,12.08982 -111.97115,-7.41017 -135.9315,-26.2555 -205.66272,-26.46226 -93.13254,0.97941 -116.14473,24.59859 -230.49679,24.02226 -47.00462,-0.14837 -94.18114,3.00302 -141.15235,5.55078 -46.85681,2.54158 -93.8962,4.4921 -140.13086,12.51563 C 98.218479,179.74618 52.469773,194.10969 13.132812,219.69531 8.6578098,222.60595 4.2833725,225.66991 0,228.85547 V 250 H 446.88086 1000 v -98.15958 c -4.86627,-2.07903 -9.94307,-3.68365 -15.10156,-4.875 -8.7651,-2.02431 -17.64671,-2.88733 -26.58203,-2.95899 z"
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,230.85417)"
|
||||
id="path851"
|
||||
@@ -803,10 +808,10 @@
|
||||
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"><tspan
|
||||
style="fill:#217821"
|
||||
id="tspan1784">c</tspan><tspan
|
||||
style="fill:#5fd35f"
|
||||
id="tspan1128">walk</tspan></tspan></text>
|
||||
style="fill:#55ff99;fill-opacity:1"
|
||||
id="tspan1784"><tspan
|
||||
style="fill:#37c871;fill-opacity:1"
|
||||
id="tspan1786">c</tspan>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"
|
||||
@@ -865,10 +870,5 @@
|
||||
d="m 98.689273,265.66265 -0.935445,4.07586 3.207232,0.40091 1.73726,-4.27632 z"
|
||||
id="path1761"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="opacity:1;fill:#d5ffe6;fill-opacity:1;stroke:none;stroke-width:3.77952766;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:normal"
|
||||
d="M 152.04688 31.642578 C 151.59117 31.641208 151.13689 31.653244 150.68164 31.65625 C 152.12973 45.683277 180.34746 127.53917 188.39258 135.34766 L 224.25391 141.91406 C 175.78399 118.49082 157.82779 44.614434 152.98633 31.658203 C 152.67339 31.655286 152.35965 31.643519 152.04688 31.642578 z "
|
||||
transform="matrix(0.26458333,0,0,0.26458333,0,230.85417)"
|
||||
id="path1779" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
+1
-1
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
struct cwk_segment
|
||||
{
|
||||
const char *path;
|
||||
const char *segments;
|
||||
const char *begin;
|
||||
const char *end;
|
||||
size_t size;
|
||||
|
||||
+19
-20
@@ -128,13 +128,22 @@ static const char *cwk_path_find_previous_stop(const char *begin, const char *c)
|
||||
--c;
|
||||
}
|
||||
|
||||
// Return the pointer to the previous stop.
|
||||
return c;
|
||||
// Return the pointer to the previous stop. We have to return the first
|
||||
// character after the separator, not on the separator itself.
|
||||
if (cwk_path_is_separator(c)) {
|
||||
return c + 1;
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
static bool cwk_path_get_first_segment_at(const char *path,
|
||||
struct cwk_segment *segment)
|
||||
{
|
||||
// Let's remember the path. We will move the path pointer afterwards, that's
|
||||
// why this has to be done first.
|
||||
segment->segments = path;
|
||||
|
||||
// Now let's check whether this is an empty string. An empty string has no
|
||||
// segment it could use.
|
||||
if (*path == '\0') {
|
||||
@@ -219,15 +228,9 @@ static bool cwk_path_get_next_segment_joined(struct cwk_segment_joined *sj)
|
||||
// Grab the first segment of the next path and determine whether this path
|
||||
// has anything useful in it. There is one more thing we have to consider
|
||||
// here - for the first time we do this we want to skip the root, but
|
||||
// afterwards we will consider that to be part of the segments. So let's
|
||||
// check what to do here...
|
||||
if (sj->path_index == 0) {
|
||||
result = cwk_path_get_first_segment(sj->paths[sj->path_index],
|
||||
&sj->segment);
|
||||
} else {
|
||||
result = cwk_path_get_first_segment_at(sj->paths[sj->path_index],
|
||||
&sj->segment);
|
||||
}
|
||||
// afterwards we will consider that to be part of the segments.
|
||||
result = cwk_path_get_first_segment_at(sj->paths[sj->path_index],
|
||||
&sj->segment);
|
||||
|
||||
} while (!result);
|
||||
|
||||
@@ -535,8 +538,8 @@ done:
|
||||
return pos;
|
||||
}
|
||||
|
||||
size_t cwk_path_get_absolute(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)
|
||||
{
|
||||
size_t i;
|
||||
const char *paths[4];
|
||||
@@ -778,10 +781,6 @@ bool cwk_path_get_first_segment(const char *path, struct cwk_segment *segment)
|
||||
{
|
||||
size_t length;
|
||||
|
||||
// Let's remember the path. We will move the path pointer afterwards, that's
|
||||
// why this has to be done first.
|
||||
segment->path = path;
|
||||
|
||||
// We skip the root since that's not part of the first segment. The root is
|
||||
// treated as a separate entity.
|
||||
cwk_path_get_root(path, &length);
|
||||
@@ -856,7 +855,7 @@ bool cwk_path_get_previous_segment(struct cwk_segment *segment)
|
||||
// The current position might point to the first character of the path, which
|
||||
// means there are no previous segments available.
|
||||
c = segment->begin;
|
||||
if (c <= segment->path) {
|
||||
if (c <= segment->segments) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -864,7 +863,7 @@ bool cwk_path_get_previous_segment(struct cwk_segment *segment)
|
||||
// beginning or the character is no separator anymore.
|
||||
do {
|
||||
--c;
|
||||
if (c <= segment->path) {
|
||||
if (c <= segment->segments) {
|
||||
// So we reached the beginning here and there is no segment. So we return
|
||||
// false and don't change the segment structure submitted by the caller.
|
||||
return false;
|
||||
@@ -874,7 +873,7 @@ bool cwk_path_get_previous_segment(struct cwk_segment *segment)
|
||||
// We are guaranteed now that there is another segment, since we moved before
|
||||
// the previous separator and did not reach the segment path beginning.
|
||||
segment->end = c + 1;
|
||||
segment->begin = cwk_path_find_previous_stop(segment->path, c) + 1;
|
||||
segment->begin = cwk_path_find_previous_stop(segment->segments, c);
|
||||
segment->size = segment->end - segment->begin;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -4,6 +4,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int join_back_after_root()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
length = cwk_path_join("C:\\this\\path", "C:\\..\\is\\a\\test\\", buffer,
|
||||
sizeof(buffer));
|
||||
|
||||
if (length != 22) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(buffer, "C:\\this\\path\\is\\a\\test") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int join_two_unc()
|
||||
{
|
||||
char buffer[FILENAME_MAX];
|
||||
|
||||
@@ -6,6 +6,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int normalize_back_after_root()
|
||||
{
|
||||
size_t count;
|
||||
char result[FILENAME_MAX];
|
||||
char *input, *expected;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
input = "C:\\..\\this\\is\\a\\test\\path";
|
||||
strcpy(result, input);
|
||||
expected = "C:\\this\\is\\a\\test\\path";
|
||||
count = cwk_path_normalize(result, result, sizeof(result));
|
||||
if (count != strlen(expected) || strcmp(result, expected) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int normalize_only_separators()
|
||||
{
|
||||
size_t count;
|
||||
|
||||
+72
-1
@@ -3,6 +3,37 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int segment_back_with_root()
|
||||
{
|
||||
const char *path;
|
||||
struct cwk_segment segment;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
path = "C:\\this\\path";
|
||||
if (!cwk_path_get_last_segment(path, &segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(segment.begin, "path", segment.size) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(segment.begin, "this", segment.size) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_type()
|
||||
{
|
||||
const char *path;
|
||||
@@ -55,7 +86,47 @@ int segment_type()
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_previous()
|
||||
int segment_previous_relative()
|
||||
{
|
||||
const char *path;
|
||||
struct cwk_segment segment;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
path = "now/hello_world/abc/";
|
||||
|
||||
if (!cwk_path_get_last_segment(path, &segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(segment.begin, "abc", segment.size) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(segment.begin, "hello_world", segment.size) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strncmp(segment.begin, "now", segment.size) != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_previous_absolute()
|
||||
{
|
||||
const char *path;
|
||||
struct cwk_segment segment;
|
||||
|
||||
Reference in new issue
Block a user