mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-06-02 09:06:54 +02:00
Initial commit
This commit is contained in:
60
arm9/source/core/String.h
Normal file
60
arm9/source/core/String.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include <string.h>
|
||||
#include "StringUtil.h"
|
||||
|
||||
template <typename CharType, int MaxLength>
|
||||
class String
|
||||
{
|
||||
CharType _buffer[MaxLength + 1];
|
||||
|
||||
public:
|
||||
String()
|
||||
{
|
||||
_buffer[0] = 0;
|
||||
}
|
||||
|
||||
template<class T, class = std::enable_if_t<std::is_same_v<T, CharType>>>
|
||||
String(const T* const & str)
|
||||
{
|
||||
StringUtil::Copy(_buffer, str, MaxLength + 1);
|
||||
}
|
||||
|
||||
explicit String(const char* str)
|
||||
{
|
||||
StringUtil::Copy(_buffer, str, MaxLength + 1);
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr String(const CharType(&str)[N])
|
||||
{
|
||||
if (N * sizeof(CharType) <= sizeof(_buffer))
|
||||
memcpy(_buffer, str, N * sizeof(CharType));
|
||||
else
|
||||
{
|
||||
memcpy(_buffer, str, MaxLength * sizeof(CharType));
|
||||
_buffer[MaxLength] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class = std::enable_if_t<std::is_same_v<T, CharType>>>
|
||||
void operator=(const T* const & str)
|
||||
{
|
||||
StringUtil::Copy(_buffer, str, MaxLength + 1);
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr void operator=(const CharType(&str)[N])
|
||||
{
|
||||
if (N * sizeof(CharType) <= sizeof(_buffer))
|
||||
memcpy(_buffer, str, N * sizeof(CharType));
|
||||
else
|
||||
{
|
||||
memcpy(_buffer, str, MaxLength * sizeof(CharType));
|
||||
_buffer[MaxLength] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr operator const CharType*() const { return _buffer; }
|
||||
|
||||
constexpr const CharType* GetString() const { return _buffer; }
|
||||
};
|
||||
Reference in New Issue
Block a user