mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
Spreadsheet: Fix column index to number conversion
The output of Spreadsheet::convert_from_string() is now correct for numbers larger than 26^2.
This commit is contained in:
parent
6b2f3ad6c8
commit
ec5d2a5144
1 changed files with 5 additions and 5 deletions
|
@ -98,6 +98,9 @@ static Optional<size_t> convert_from_string(StringView str, unsigned base = 26,
|
||||||
|
|
||||||
VERIFY(base >= 2 && base <= map.length());
|
VERIFY(base >= 2 && base <= map.length());
|
||||||
|
|
||||||
|
if (str.is_empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
size_t value = 0;
|
size_t value = 0;
|
||||||
auto const len = str.length();
|
auto const len = str.length();
|
||||||
for (auto i = 0u; i < len; i++) {
|
for (auto i = 0u; i < len; i++) {
|
||||||
|
@ -105,13 +108,10 @@ static Optional<size_t> convert_from_string(StringView str, unsigned base = 26,
|
||||||
if (!maybe_index.has_value())
|
if (!maybe_index.has_value())
|
||||||
return {};
|
return {};
|
||||||
size_t digit_value = maybe_index.value();
|
size_t digit_value = maybe_index.value();
|
||||||
// NOTE: Refer to the note in `String::bijective_base_from()'.
|
value += (digit_value + 1) * AK::pow<float>(base, len - 1 - i);
|
||||||
if (i == 0 && len > 1)
|
|
||||||
++digit_value;
|
|
||||||
value += digit_value * AK::pow<float>(base, len - 1 - i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Sheet::add_column()
|
DeprecatedString Sheet::add_column()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue