encode/number: set the view's remainder at exit

This commit is contained in:
Danny Robson 2018-12-16 18:06:28 +11:00
parent 1bb566fcda
commit a2ef7cb75c

View File

@ -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;
}