Sfoglia il codice sorgente

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

Andreas Kling 5 anni fa
parent
commit
c4a6d6ae9f
6 ha cambiato i file con 39 aggiunte e 16 eliminazioni
  1. 5 0
      AK/FlyString.cpp
  2. 2 0
      AK/FlyString.h
  3. 6 0
      AK/LogStream.cpp
  4. 2 3
      AK/LogStream.h
  5. 20 0
      AK/String.cpp
  6. 4 13
      AK/String.h

+ 5 - 0
AK/FlyString.cpp

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

+ 2 - 0
AK/FlyString.h

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

+ 6 - 0
AK/LogStream.cpp

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

+ 2 - 3
AK/LogStream.h

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

+ 20 - 0
AK/String.cpp

@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <AK/FlyString.h>
 #include <AK/Memory.h>
 #include <AK/StdLibExtras.h>
 #include <AK/String.h>
@@ -321,4 +322,23 @@ String escape_html_entities(const StringView& html)
     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();
+}
+
 }

+ 4 - 13
AK/String.h

@@ -111,25 +111,16 @@ public:
     {
     }
 
+    String(const FlyString&);
+
     static String repeated(char, size_t count);
     bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
 
     int to_int(bool& ok) const;
     unsigned to_uint(bool& ok) const;
 
-    String to_lowercase() 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();
-    }
+    String to_lowercase() const;
+    String to_uppercase() const;
 
     bool equals_ignoring_case(const StringView&) const;