Spreadsheet: Fix column index string to number conversion

Fixed convert_from_string() function to return correct output.
The value of a number is equal to sum of each digit multiplied by it's
positional weight.
This commit is contained in:
Mandar Kulkarni 2021-08-04 23:22:55 +05:30 committed by Ali Mohammad Pur
parent 151c940827
commit 2c44f2dc3c
Notes: sideshowbarker 2024-07-18 07:12:08 +09:00

View File

@ -90,12 +90,13 @@ static size_t convert_from_string(StringView str, unsigned base = 26, StringView
VERIFY(base >= 2 && base <= map.length());
size_t value = 0;
for (size_t i = str.length(); i > 0; --i) {
auto digit_value = map.find(str[i - 1]).value_or(0);
auto const len = str.length();
for (auto i = 0u; i < len; i++) {
size_t digit_value = map.find(str[i]).value_or(0);
// NOTE: Refer to the note in `String::bijective_base_from()'.
if (i == str.length() && str.length() > 1)
if (i == 0 && len > 1)
++digit_value;
value = value * base + digit_value;
value += digit_value * AK::pow<float>(base, len - 1 - i);
}
return value;