Explorar o código

AK: Add to_string() method to StringView

This allows easy creation of a new string from an existing StringView.
Can be used e.g. for output with printf(..., view.to_string().characters())
instead of writing printf(..., String{view}.characters()).
Emanuel Sprung %!s(int64=5) %!d(string=hai) anos
pai
achega
8fe821fae2
Modificáronse 2 ficheiros con 4 adicións e 0 borrados
  1. 2 0
      AK/StringView.cpp
  2. 2 0
      AK/StringView.h

+ 2 - 0
AK/StringView.cpp

@@ -264,4 +264,6 @@ Optional<size_t> StringView::find_last_of(const StringView& view) const
     return {};
 }
 
+String StringView::to_string() const { return String { *this }; }
+
 }

+ 2 - 0
AK/StringView.h

@@ -152,6 +152,8 @@ public:
 
     const StringImpl* impl() const { return m_impl; }
 
+    String to_string() const;
+
 private:
     friend class String;
     const StringImpl* m_impl { nullptr };