Skip to content

Commit 1116322

Browse files
committed
negative index => relative to end of list
web api `parseUriNode` now accepts negative index numbers for indexing relative to node end
1 parent 79e31a0 commit 1116322

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/items.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ bool prompt::async(const char*uri,navRoot& root,idx_t lvl) {
4444
return true;
4545
}
4646
idx_t menuNode::parseUriNode(const char*&uri) {
47-
if (uri[0]=='/') uri++;//TODO check who does this part!
48-
assert(strchr(numericChars,uri[0]));
47+
if (*uri=='/') uri++;//TODO check who does this part!
48+
bool neg=false;
49+
if (*uri=='-') {
50+
uri++;
51+
neg=true;
52+
}
53+
assert(*uri=='-'||strchr(numericChars,uri[0]));
4954
int n=0;
5055
while (*uri) {
5156
char* d=strchr(numericChars,uri[0]);
@@ -54,8 +59,9 @@ idx_t menuNode::parseUriNode(const char*&uri) {
5459
uri++;
5560
}
5661
//state transformation (for events preservation)
57-
if (n>=sz()) n=sz()-1;//never trusting web!
58-
else if (n<0) n=0;
62+
if (neg) n=sz()-n;//allow negative index from end of list
63+
if (n<0) n=0;
64+
else if (n>=sz()) n=sz()-1;//never trusting web!
5965
return n;
6066
}
6167

0 commit comments

Comments
 (0)