Skip to content

Commit

Permalink
Strings: Add Windows only UTF16 StringView::fromNullTerminated
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagghiu committed Mar 18, 2024
1 parent 32e5fb4 commit 2098dd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Libraries/Strings/StringView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ SC::StringView SC::StringView::fromNullTerminated(const char* text, StringEncodi
return StringView({text, ::strlen(text)}, true, encoding);
}

#if SC_PLATFORM_WINDOWS
SC::StringView SC::StringView::fromNullTerminated(const wchar_t* text, StringEncoding)
{
return StringView({text, ::wcslen(text)}, true);
}
#endif

bool SC::StringView::parseInt32(int32_t& value) const
{
if (text == nullptr)
Expand Down
8 changes: 8 additions & 0 deletions Libraries/Strings/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ struct SC::StringView
/// @return The StringView containing text with given encoding
static StringView fromNullTerminated(const char* text, StringEncoding encoding);

#if SC_PLATFORM_WINDOWS
/// @brief Constructs a StringView from a null-terminated C-String
/// @param text The null-terminated C-String
/// @param encoding The encoding of the text contained in this StringView
/// @return The StringView containing text with given encoding
static StringView fromNullTerminated(const wchar_t* text, StringEncoding encoding);
#endif

/// @brief Get encoding of this StringView
/// @return This StringView encoding
[[nodiscard]] constexpr StringEncoding getEncoding() const { return static_cast<StringEncoding>(encoding); }
Expand Down

0 comments on commit 2098dd8

Please sign in to comment.