mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
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:
parent
151c940827
commit
2c44f2dc3c
Notes:
sideshowbarker
2024-07-18 07:12:08 +09:00
Author: https://github.com/Mandar12 Commit: https://github.com/SerenityOS/serenity/commit/2c44f2dc3cb Pull-request: https://github.com/SerenityOS/serenity/pull/9237 Reviewed-by: https://github.com/TobyAsE Reviewed-by: https://github.com/alimpfard
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user