diff options
author | Nico Weber <thakis@chromium.org> | 2020-07-12 13:37:00 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-13 15:00:14 +0200 |
commit | 552789902ad5e20212a58a499a7a1120eed32ea6 (patch) | |
tree | 311914bafdbefef78a48031340882adbc78900f1 /AK | |
parent | 97cea9e61cbd88705d1ac573039659079b2fe356 (diff) | |
download | serenity-552789902ad5e20212a58a499a7a1120eed32ea6.zip |
AK: Make LexicalPath keep everything before the last dot as title
Previously, TextEditor would put "foo.txt" in the Save As dialog
for files named "foo.bar.txt". Now, it puts "foo.bar.txt" instead.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/LexicalPath.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index 9400eb01c7..20da3faf57 100644 --- a/AK/LexicalPath.cpp +++ b/AK/LexicalPath.cpp @@ -89,10 +89,18 @@ void LexicalPath::canonicalize() m_dirname = dirname_builder.to_string(); m_basename = canonical_parts.last(); - auto name_parts = m_basename.split('.'); - m_title = name_parts.is_empty() ? String() : name_parts[0]; - if (name_parts.size() > 1) - m_extension = name_parts.last(); + String dot { "." }; + Optional<size_t> last_dot, end = m_basename.index_of(dot); + while (end.has_value()) { + last_dot = end; + end = m_basename.index_of(dot, end.value() + 1); + } + if (last_dot.has_value()) { + m_title = m_basename.substring(0, last_dot.value()); + m_extension = m_basename.substring(last_dot.value() + 1, m_basename.length() - last_dot.value() - 1); + } else { + m_title = m_basename; + } StringBuilder builder(approximate_canonical_length); for (size_t i = 0; i < canonical_parts.size(); ++i) { |