summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-02-24 22:43:29 +0000
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2023-02-26 21:06:21 +0330
commitec5d2a51445298ebc822e6a6d933152eca42778e (patch)
tree7fc902902781ab468cd44241def1c546188ad01a /Userland
parent6b2f3ad6c83f255f00e73b8ec9b21aab5d4edfbd (diff)
downloadserenity-ec5d2a51445298ebc822e6a6d933152eca42778e.zip
Spreadsheet: Fix column index to number conversion
The output of Spreadsheet::convert_from_string() is now correct for numbers larger than 26^2.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Spreadsheet/Spreadsheet.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp
index a0175e9aa2..e42cd6a2e9 100644
--- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp
+++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp
@@ -98,6 +98,9 @@ static Optional<size_t> convert_from_string(StringView str, unsigned base = 26,
VERIFY(base >= 2 && base <= map.length());
+ if (str.is_empty())
+ return {};
+
size_t value = 0;
auto const len = str.length();
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())
return {};
size_t digit_value = maybe_index.value();
- // NOTE: Refer to the note in `String::bijective_base_from()'.
- if (i == 0 && len > 1)
- ++digit_value;
- value += digit_value * AK::pow<float>(base, len - 1 - i);
+ value += (digit_value + 1) * AK::pow<float>(base, len - 1 - i);
}
- return value;
+ return value - 1;
}
DeprecatedString Sheet::add_column()