encode/number: set the view's remainder at exit
This commit is contained in:
parent
1bb566fcda
commit
a2ef7cb75c
@ -22,18 +22,19 @@ namespace cruft::encode {
|
|||||||
decode36 (cruft::view<char const*> &src)
|
decode36 (cruft::view<char const*> &src)
|
||||||
{
|
{
|
||||||
ValueT accum = 0;
|
ValueT accum = 0;
|
||||||
for (auto const i: src) {
|
|
||||||
accum *= 36;
|
|
||||||
|
|
||||||
switch (i) {
|
auto cursor = src.begin ();
|
||||||
case '0'...'9': accum += i - '0'; continue;
|
for (auto last = src.end (); cursor != last; ++cursor) {
|
||||||
case 'a'...'z': accum += i - 'a' + 10; continue;
|
switch (auto i = *cursor; i) {
|
||||||
case 'A'...'Z': accum += i - 'A' + 10; continue;
|
case '0'...'9': accum = accum * 36 + i - '0'; continue;
|
||||||
default:
|
case 'a'...'z': accum = accum * 36 + i - 'a' + 10; continue;
|
||||||
throw std::invalid_argument ("invalid character");
|
case 'A'...'Z': accum = accum * 36 + i - 'A' + 10; continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
src = { cursor, src.end () };
|
||||||
return accum;
|
return accum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user