diff --git a/CMakeLists.txt b/CMakeLists.txt index 77d547e4..1d10f1a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,6 +180,7 @@ add_library(NintendoSDK OBJECT include/nn/util/util_IntrusiveList.h include/nn/util/util_BitUtil.h include/nn/util/util_ResDic.h + include/nn/util/util_StringUtil.h include/nn/util/util_StringView.h include/nn/ui2d/detail/TexCoordArray.h include/nn/ui2d/Layout.h diff --git a/include/nn/util/util_StringUtil.h b/include/nn/util/util_StringUtil.h new file mode 100644 index 00000000..54eb949c --- /dev/null +++ b/include/nn/util/util_StringUtil.h @@ -0,0 +1,51 @@ +#include + +namespace nn::util { +template +inline s32 Strlcpy(T* pOutDst, const T* pSrc, s32 count) { + s32 length = 0; + + if (count > 0) { + while (--count && *pSrc) { + *pOutDst++ = *pSrc++; + ++length; + } + *pOutDst++ = '\0'; + } + + while (*pSrc++) + ++length; + + return length; +} + +template +inline s32 Strnlen(const T* pStr, s32 count) { + s32 length = 0; + + if (count > 0) { + while (count && *pStr) { + ++pStr; + ++length; + --count; + } + } + + return length; +} + +template +inline s32 Strncmp(const T* pStr1, const T* pStr2, s32 count) { + if (count == 0) + return 0; + + T c1, c2; + + do { + c1 = *pStr1++; + c2 = *pStr2++; + } while (c1 && c1 == c2 && --count); + + return c1 - c2; +} +} // namespace nn::util \ No newline at end of file