From 7405536a1abcc23d6a54565687800b14bde3db53 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Tue, 29 Jun 2021 17:06:21 +0200 Subject: AK+Everywhere: Use mostly StringView in LexicalPath This changes the m_parts, m_dirname, m_basename, m_title and m_extension member variables to StringViews onto the m_string String. It also removes the m_is_absolute member in favour of computing if a path is absolute in the is_absolute() getter. Due to this, the canonicalize() method has been completely rewritten. The parts() getter still returns a Vector, although it is no longer a const reference as m_parts is no longer a Vector. Rather, it is constructed from the StringViews in m_parts upon request. The parts_view() getter has been added, which returns Vector const&. Most previous users of parts() have been changed to use parts_view(), except where Strings are required. Due to this change, it's is now no longer allow to create temporary LexicalPath objects to call the dirname, basename, title, or extension getters on them because the returned StringViews will point to possible freed memory. --- Userland/Libraries/LibGUI/EmojiInputDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Userland/Libraries/LibGUI/EmojiInputDialog.cpp') diff --git a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp index 098a2ce1ab..7a25e701c3 100644 --- a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp @@ -26,10 +26,10 @@ static Vector supported_emoji_code_points() auto lexical_path = LexicalPath(filename); if (lexical_path.extension() != "png") continue; - auto basename = lexical_path.basename(); + auto& basename = lexical_path.basename(); if (!basename.starts_with("U+")) continue; - u32 code_point = strtoul(basename.characters() + 2, nullptr, 16); + u32 code_point = strtoul(basename.to_string().characters() + 2, nullptr, 16); code_points.append(code_point); } return code_points; -- cgit v1.2.3