3 #ifndef INCLUDE_NN_NLIB_CSTRING_H_
4 #define INCLUDE_NN_NLIB_CSTRING_H_
8 #ifndef NLIB_ISDIGIT_USE_FALLBACK
41 #ifndef NLIB_WCSCMP_USE_FALLBACK
42 return wcscmp(s1, s2);
44 return StrCmpFallback(s1, s2);
48 return StrCmpFallback(s1, s2);
51 return StrCmpFallback(s1, s2);
62 #ifndef NLIB_STRNCMP_USE_FALLBACK
63 return strncmp(s1, s2, n);
65 return StrNcmpFallback(s1, s2, n);
69 #ifndef NLIB_WCSNCMP_USE_FALLBACK
70 return wcsncmp(s1, s2, n);
72 return StrNcmpFallback(s1, s2, n);
76 return StrNcmpFallback(s1, s2, n);
79 return StrNcmpFallback(s1, s2, n);
83 inline bool StrEqual(
const char* s1,
const char* s2)
NLIB_NOEXCEPT {
84 return s1[0] == s2[0] &&
StrCmp(s1, s2) == 0;
87 return s1[0] == s2[0] &&
StrCmp(s1, s2) == 0;
90 return s1[0] == s2[0] &&
StrCmp(s1, s2) == 0;
92 inline bool StrEqual(
const wchar_t* s1,
const wchar_t* s2)
NLIB_NOEXCEPT {
93 return s1[0] == s2[0] &&
StrCmp(s1, s2) == 0;
97 inline bool StrNequal(
const char* s1,
const char* s2,
size_t n)
NLIB_NOEXCEPT {
101 return StrNcmp(s1, s2, n) == 0;
104 return StrNcmp(s1, s2, n) == 0;
106 inline bool StrNequal(
const wchar_t* s1,
const wchar_t* s2,
size_t n)
NLIB_NOEXCEPT {
107 return StrNcmp(s1, s2, n) == 0;
123 template<
class T,
size_t N>
125 return StrCpy(&dest[0], N, src);
130 return nlib_strncpy(dest, destSize, src, maxNumCopyWithoutNull);
134 return nlib_utf16ncpy(dest, destSize, src, maxNumCopyWithoutNull);
138 return nlib_utf32ncpy(dest, destSize, src, maxNumCopyWithoutNull);
142 return nlib_wcsncpy(dest, destSize, src, maxNumCopyWithoutNull);
145 template<
class T,
size_t N>
148 return StrNcpy(&dest[0], N, src, maxNumCopyWithoutNull);
167 template<
class T,
size_t N>
169 return StrCat(&dest[0], N, src);
174 return nlib_strncat(dest, destSize, src, maxNumCopyWithoutNull);
179 return nlib_wcsncat(dest, destSize, src, maxNumCopyWithoutNull);
182 template<
class T,
size_t N>
185 return StrNcat(&dest[0], N, src, maxNumCopyWithoutNull);
196 #ifndef NLIB_ISDIGIT_USE_FALLBACK
218 return (
'0' <= ch && ch <=
'9') || (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
221 return (
'A' <= ch && ch <=
'Z') || (
'a' <= ch && ch <=
'z');
227 inline int IsGrpah(
int ch)
NLIB_NOEXCEPT {
return ch >= 0x21 && ch <= 0x7E; }
236 return static_cast<unsigned int>(ch -
'0') < 10u ||
237 static_cast<unsigned int>((ch | 0x20) -
'a') < 6u;
241 return (ch >=
'A' && ch <=
'Z') ? ch + (
'a' -
'A') : ch;
244 return (ch >=
'a' && ch <=
'z') ? ch - (
'a' -
'A') : ch;
252 inline int VsnPrintf(
char* buf,
size_t size,
const char* fmt, va_list args) NLIB_NOEXCEPT {
255 #ifndef NLIB_NO_ERRNO
256 if (e != 0) errno = e;
258 return (e == 0) ?
static_cast<int>(count) : -1;
266 inline int SnPrintf(
char* buf,
size_t size,
const char* fmt, ...) NLIB_NOEXCEPT {
269 int rval =
VsnPrintf(buf, size, fmt, args);
286 va_list args) NLIB_NOEXCEPT {
287 return VsnPrintfFallback(buf, N, fmt, args);
290 inline int SnPrintfFallback(
char* buf,
size_t size,
const char* fmt, ...) NLIB_NOEXCEPT {
293 int rval = VsnPrintfFallback(buf, size, fmt, args);
300 const char* fmt, ...) NLIB_NOEXCEPT {
311 inline int VsnPrintf(
wchar_t* buf,
size_t size,
const wchar_t* fmt, va_list args) NLIB_NOEXCEPT {
314 #ifndef NLIB_NO_ERRNO
315 if (e != 0) errno = e;
317 return (e == 0) ?
static_cast<int>(count) : -1;
325 inline int SnPrintf(
wchar_t* buf,
size_t size,
const wchar_t* fmt, ...) NLIB_NOEXCEPT {
328 int rval =
VsnPrintf(buf, size, fmt, args);
344 va_list args) NLIB_NOEXCEPT {
345 return VsnPrintfFallback(buf, N, fmt, args);
348 inline int SnPrintfFallback(
wchar_t* buf,
size_t size,
const wchar_t* fmt, ...) NLIB_NOEXCEPT {
351 int rval = VsnPrintfFallback(buf, size, fmt, args);
358 const wchar_t* fmt, ...) NLIB_NOEXCEPT {
368 #endif // INCLUDE_NN_NLIB_CSTRING_H_
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
int VsnPrintf(wchar_t(&buf)[N], const wchar_t *fmt, va_list args) noexcept
内部でVsnPrintf(buf, N, fmt, args)を実行します。
int IsCntrl(int c) noexcept
std::iscntrl(static_cast(c))を返します。
errno_t StrCpy(T(&dest)[N], const T *src) noexcept
内部でStrCpy(&dest[0], N, src)を呼び出します。
int IsPunct(int c) noexcept
std::ispunct(static_cast(c))を返します。
int SnPrintf(wchar_t(&buf)[N], const wchar_t *fmt,...) noexcept
内部でVsnPrintf()を実行します。
int IsDigit(int c) noexcept
std::isdigit(static_cast(c))を返します。
int ToUpper(int c) noexcept
std::toupper(static_cast(c))を返します。
int IsAlnum(int c) noexcept
std::isalnum(static_cast(c))を返します。
errno_t MemCpy(void *dest, size_t destSize, const void *src, size_t srcSize) noexcept
nlib_memcpy()をラップします。
errno_t StrNcpy(T(&dest)[N], const T *src, size_t maxNumCopyWithoutNull) noexcept
内部でStrNcpy(&dest[0], N, src, maxNumCopyWithoutNull)を呼び出します。
int VsnPrintfFallback(char *buf, size_t size, const char *fmt, va_list args) noexcept
VsnPrintfのフォールバックです。ワイド文字版も実装されています。
errno_t StrNcat(T(&dest)[N], const T *src, size_t maxNumCopyWithoutNull) noexcept
内部でStrNcat(&dest[0], N, src, maxNumCopyWithoutNull)を呼び出します。
int IsAlpha(int c) noexcept
std::isalpha(static_cast(c))を返します。
int StrCmp(const nlib_utf32_t *s1, const nlib_utf32_t *s2) noexcept
UTF-32文字列をstrcmp()と同様に比較します。
int IsGraph(int c) noexcept
std::isgraph(static_cast(c))を返します。
int StrNcmp(const nlib_utf32_t *s1, const nlib_utf32_t *s2, size_t n) noexcept
UTF-32文字列をstrncmp()と同様に比較します。
int IsPrint(int c) noexcept
std::isprint(static_cast(c))を返します。
int IsLower(int c) noexcept
std::islower(static_cast(c))を返します。
errno_t CodePointCount(const wchar_t *str, size_t *count) noexcept
nlib_wcscplen()をラップします。
errno_t MemMove(void *dest, size_t destSize, const void *src, size_t srcSize) noexcept
nlib_memmove()をラップします。
int IsUpper(int c) noexcept
std::isupper(static_cast(c))を返します。
size_t StrLen(const wchar_t *str) noexcept
nlib_wcslen()をラップします。
int IsSpace(int c) noexcept
std::isspace(static_cast(c))を返します。
int ToLower(int c) noexcept
std::tolower(static_cast(c))を返します。
int IsXdigit(int c) noexcept
std::isxdigit(static_cast(c))を返します。
errno_t StrCat(T(&dest)[N], const T *src) noexcept
内部でStrCat(&dest[0], N, src)を呼び出します。