AK: Add FlyString::to_lowercase() and LogStream operator<<(FlyString)

This commit is contained in:
Andreas Kling 2020-03-22 19:07:02 +01:00
parent 7f8dc347b5
commit c4a6d6ae9f
Notes: sideshowbarker 2024-07-19 08:10:58 +09:00
6 changed files with 39 additions and 16 deletions

View file

@ -93,4 +93,9 @@ bool FlyString::equals_ignoring_case(const StringView& other) const
return StringUtils::equals_ignoring_case(view(), other); return StringUtils::equals_ignoring_case(view(), other);
} }
FlyString FlyString::to_lowercase() const
{
return String(*m_impl).to_lowercase();
}
} }

View file

@ -46,6 +46,8 @@ public:
StringView view() const { return { characters(), length() }; } StringView view() const { return { characters(), length() }; }
FlyString to_lowercase() const;
int to_int(bool& ok) const; int to_int(bool& ok) const;
bool equals_ignoring_case(const StringView&) const; bool equals_ignoring_case(const StringView&) const;

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/FlyString.h>
#include <AK/LogStream.h> #include <AK/LogStream.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
@ -41,6 +42,11 @@ const LogStream& operator<<(const LogStream& stream, const String& value)
return stream; return stream;
} }
const LogStream& operator<<(const LogStream& stream, const FlyString& value)
{
return stream << value.view();
}
const LogStream& operator<<(const LogStream& stream, const StringView& value) const LogStream& operator<<(const LogStream& stream, const StringView& value)
{ {
stream.write(value.characters_without_null_termination(), value.length()); stream.write(value.characters_without_null_termination(), value.length());

View file

@ -26,6 +26,7 @@
#pragma once #pragma once
#include <AK/Forward.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/kstdio.h> #include <AK/kstdio.h>
@ -38,9 +39,6 @@
namespace AK { namespace AK {
class String;
class StringView;
class LogStream { class LogStream {
public: public:
LogStream() LogStream()
@ -95,6 +93,7 @@ inline const LogStream& operator<<(const LogStream& stream, const char* value)
return stream; return stream;
} }
const LogStream& operator<<(const LogStream&, const FlyString&);
const LogStream& operator<<(const LogStream&, const String&); const LogStream& operator<<(const LogStream&, const String&);
const LogStream& operator<<(const LogStream&, const StringView&); const LogStream& operator<<(const LogStream&, const StringView&);
const LogStream& operator<<(const LogStream&, int); const LogStream& operator<<(const LogStream&, int);

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/FlyString.h>
#include <AK/Memory.h> #include <AK/Memory.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/String.h> #include <AK/String.h>
@ -321,4 +322,23 @@ String escape_html_entities(const StringView& html)
return builder.to_string(); return builder.to_string();
} }
String::String(const FlyString& string)
: m_impl(string.impl())
{
}
String String::to_lowercase() const
{
if (!m_impl)
return {};
return m_impl->to_lowercase();
}
String String::to_uppercase() const
{
if (!m_impl)
return {};
return m_impl->to_uppercase();
}
} }

View file

@ -111,25 +111,16 @@ public:
{ {
} }
String(const FlyString&);
static String repeated(char, size_t count); static String repeated(char, size_t count);
bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
int to_int(bool& ok) const; int to_int(bool& ok) const;
unsigned to_uint(bool& ok) const; unsigned to_uint(bool& ok) const;
String to_lowercase() const String to_lowercase() const;
{ String to_uppercase() const;
if (!m_impl)
return String();
return m_impl->to_lowercase();
}
String to_uppercase() const
{
if (!m_impl)
return String();
return m_impl->to_uppercase();
}
bool equals_ignoring_case(const StringView&) const; bool equals_ignoring_case(const StringView&) const;