Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions include/nn/util/util_StringUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <nn/types.h>

namespace nn::util {
template <typename T>
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 <typename T>
inline s32 Strnlen(const T* pStr, s32 count) {
s32 length = 0;

if (count > 0) {
while (count && *pStr) {
++pStr;
++length;
--count;
}
}

return length;
}

template <typename T>
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