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)
|
||||
{
|
||||
ValueT accum = 0;
|
||||
for (auto const i: src) {
|
||||
accum *= 36;
|
||||
|
||||
switch (i) {
|
||||
case '0'...'9': accum += i - '0'; continue;
|
||||
case 'a'...'z': accum += i - 'a' + 10; continue;
|
||||
case 'A'...'Z': accum += i - 'A' + 10; continue;
|
||||
default:
|
||||
throw std::invalid_argument ("invalid character");
|
||||
auto cursor = src.begin ();
|
||||
for (auto last = src.end (); cursor != last; ++cursor) {
|
||||
switch (auto i = *cursor; i) {
|
||||
case '0'...'9': accum = accum * 36 + i - '0'; continue;
|
||||
case 'a'...'z': accum = accum * 36 + i - 'a' + 10; continue;
|
||||
case 'A'...'Z': accum = accum * 36 + i - 'A' + 10; continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
src = { cursor, src.end () };
|
||||
return accum;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user