30 typedef wchar_t utf16_t;
32 typedef char16_t utf16_t;
40 inline bool is_high_surrogate(_In_ utf16_t chr)
42 return 0xd800 < chr && chr < 0xdc00;
50 inline bool is_low_surrogate(_In_ utf16_t chr)
52 return 0xdc00 < chr && chr < 0xe000;
60 inline bool is_surrogate_pair(_In_reads_(2)
const utf16_t* str)
62 return is_high_surrogate(str[0]) && is_low_surrogate(str[1]);
70 inline char32_t surrogate_pair_to_ucs4(_In_reads_(2)
const utf16_t* str)
72 _Assume_(is_surrogate_pair(str));
74 ((
char32_t)(str[0] - 0xd800) << 10) +
75 (char32_t)(str[1] - 0xdc00) +
84 inline void ucs4_to_surrogate_pair(_Out_writes_(2) utf16_t* str, _In_
char32_t chr)
86 _Assume_(chr >= 0x10000);
88 str[0] = 0xd800 + (char32_t)((chr >> 10) & 0x3ff);
89 str[1] = 0xdc00 + (char32_t)(chr & 0x3ff);
97 inline bool iscombining(_In_
char32_t chr)
100 (0x0300 <= chr && chr < 0x0370) ||
101 (0x1dc0 <= chr && chr < 0x1e00) ||
102 (0x20d0 <= chr && chr < 0x2100) ||
103 (0xfe20 <= chr && chr < 0xfe30);
112 inline size_t islbreak(_In_ T chr)
114 return chr ==
'\n' || chr ==
'\r';
124 inline size_t islbreak(_In_reads_or_z_opt_(count)
const T* chr, _In_
size_t count)
126 _Assume_(chr || !count);
127 if (count >= 2 && ((chr[0] ==
'\r' && chr[1] ==
'\n') || (chr[0] ==
'\n' && chr[1] ==
'\r')))
129 if (count > 1 && (chr[0] ==
'\n' || chr[0] ==
'\r'))
140 inline size_t glyphlen(_In_reads_or_z_opt_(count)
const wchar_t* glyph, _In_
size_t count)
142 _Assume_(glyph || !count);
145 size_t i = count < 2 || !is_surrogate_pair(glyph) ? 1 : 2;
149 for (; i < count && iscombining(glyph[i]); ++i);
163 inline size_t strlen(_In_z_
const T* str)
167 for (i = 0; str[i]; ++i);
180 inline size_t strnlen(_In_reads_or_z_opt_(count)
const T* str, _In_
size_t count)
182 _Assume_(str || !count);
184 for (i = 0; i < count && str[i]; ++i);
188 constexpr auto npos{
static_cast<size_t>(-1) };
199 inline size_t strchr(_In_z_
const T* str, _In_ T chr)
202 for (
size_t i = 0; str[i]; ++i)
203 if (str[i] == chr)
return i;
217 inline size_t strnchr(
218 _In_reads_or_z_opt_(count)
const T* str,
222 _Assume_(str || !count);
223 for (
size_t i = 0; i < count && str[i]; ++i)
224 if (str[i] == chr)
return i;
238 inline size_t strrnchr(
239 _In_reads_or_z_opt_(count)
const T* str,
243 _Assume_(str || !count);
245 for (
size_t i = 0; i < count && str[i]; ++i)
246 if (str[i] == chr) z = i;
253 const inline std::locale std_locale_C(
"C");
265 _In_reads_or_z_opt_(count)
const T* str,
267 _In_
const std::locale& locale)
269 _Assume_(str || !count);
270 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
271 for (
size_t i = 0; i < count && str[i]; ++i)
272 if (!ctype.is(ctype.space, str[i]))
287 inline size_t strnichr(
288 _In_reads_or_z_opt_(count)
const T* str,
291 _In_
const std::locale& locale)
293 _Assume_(str || !count);
294 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
295 chr = ctype.tolower(chr);
296 for (
size_t i = 0; i < count && str[i]; ++i)
297 if (ctype.tolower(str[i]) == chr)
return i;
311 inline size_t strrnichr(
312 _In_reads_or_z_opt_(count)
const T* str,
315 _In_
const std::locale& locale)
317 _Assume_(str || !count);
318 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
319 chr = ctype.tolower(chr);
321 for (
size_t i = 0; i < count && str[i]; ++i)
322 if (ctype.tolower(str[i]) == chr) z = i;
334 template <
class T1,
class T2>
335 inline int strcmp(
const T1* str1,
const T2* str2)
337 _Assume_(str1 && str2);
339 for (
size_t i = 0; (a = str1[i]) | (b = str2[i]); ++i) {
340 if (a > b)
return +1;
341 if (a < b)
return -1;
356 template <
class T1,
class T2>
358 _In_reads_or_z_opt_(count1)
const T1* str1, _In_
size_t count1,
359 _In_reads_or_z_opt_(count2)
const T2* str2, _In_
size_t count2)
361 _Assume_(str1 || !count1);
362 _Assume_(str2 || !count2);
363 size_t i; T1 a; T2 b;
364 for (i = 0; i < count1 && i < count2 && ((a = str1[i]) | (b = str2[i])); ++i) {
365 if (a > b)
return +1;
366 if (a < b)
return -1;
368 if (i < count1 && str1[i])
return +1;
369 if (i < count2 && str2[i])
return -1;
382 template <
class T1,
class T2>
383 inline int strncmp(_In_reads_or_z_opt_(count)
const T1* str1, _In_reads_or_z_opt_(count)
const T2* str2, _In_
size_t count)
385 _Assume_((str1 && str2) || !count);
386 size_t i; T1 a; T2 b;
387 for (i = 0; i < count && ((a = str1[i]) | (b = str2[i])); ++i) {
388 if (a > b)
return +1;
389 if (a < b)
return -1;
391 if (i < count && str1[i])
return +1;
392 if (i < count && str2[i])
return -1;
408 _In_reads_or_z_opt_(count1)
const T* str1, _In_
size_t count1,
409 _In_reads_or_z_opt_(count2)
const T* str2, _In_
size_t count2,
410 _In_
const std::locale& locale)
412 _Assume_(str1 || !count1);
413 _Assume_(str2 || !count2);
414 auto& collate = std::use_facet<std::collate<T>>(locale);
415 return collate.compare(str1, str1 + count1, str2, str2 + count2);
426 template <
class T1,
class T2>
427 inline int stricmp(_In_z_
const T1* str1, _In_z_
const T2* str2, _In_
const std::locale& locale)
431 size_t i; T1 a; T2 b;
432 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
433 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
434 for (i = 0; (a = ctype1.tolower(str1[i])) | (b = ctype2.tolower(str2[i])); i++) {
435 if (a > b)
return +1;
436 if (a < b)
return -1;
438 if (str1[i])
return +1;
439 if (str2[i])
return -1;
452 template <
class T1,
class T2>
453 inline int strnicmp(_In_reads_or_z_opt_(count)
const T1* str1, _In_reads_or_z_opt_(count)
const T2* str2, _In_
size_t count, _In_
const std::locale& locale)
455 _Assume_(str1 || !count);
456 _Assume_(str2 || !count);
457 size_t i; T1 a; T2 b;
458 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
459 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
460 for (i = 0; i < count && ((a = ctype1.tolower(str1[i])) | (b = ctype2.tolower(str2[i]))); i++) {
461 if (a > b)
return +1;
462 if (a < b)
return -1;
464 if (i < count && str1[i])
return +1;
465 if (i < count && str2[i])
return -1;
479 template <
class T1,
class T2>
481 _In_reads_or_z_opt_(count1)
const T1* str1, _In_
size_t count1,
482 _In_reads_or_z_opt_(count2)
const T2* str2, _In_
size_t count2,
483 _In_
const std::locale& locale)
485 _Assume_(str1 || !count1);
486 _Assume_(str2 || !count2);
487 size_t i; T1 a; T2 b;
488 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
489 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
490 for (i = 0; i < count1 && i < count2 && ((a = ctype1.tolower(str1[i])) | (b = ctype2.tolower(str2[i]))); i++) {
491 if (a > b)
return +1;
492 if (a < b)
return -1;
494 if (i < count1 && str1[i])
return +1;
495 if (i < count2 && str2[i])
return -1;
507 template <
class T1,
class T2>
508 inline size_t strstr(
509 _In_z_
const T1* str,
510 _In_z_
const T2* sample)
514 for (
size_t offset = 0;; ++offset) {
515 for (
size_t i = offset, j = 0;; ++i, ++j) {
520 if (str[i] != sample[j])
535 template <
class T1,
class T2>
536 inline size_t strnstr(
537 _In_reads_or_z_opt_(count)
const T1* str,
539 _In_z_
const T2* sample)
541 _Assume_(str || !count);
543 for (
size_t offset = 0;; ++offset) {
544 for (
size_t i = offset, j = 0;; ++i, ++j) {
547 if (i >= count || !str[i])
549 if (str[i] != sample[j])
563 template <
class T1,
class T2>
564 inline size_t stristr(
565 _In_z_
const T1* str,
566 _In_z_
const T2* sample,
567 _In_
const std::locale& locale)
571 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
572 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
573 for (
size_t offset = 0;; ++offset) {
574 for (
size_t i = offset, j = 0;; ++i, ++j) {
579 if (ctype1.tolower(str[i]) != ctype2.tolower(sample[j]))
594 template <
class T1,
class T2>
595 inline size_t strnistr(
596 _In_reads_or_z_opt_(count)
const T1* str,
598 _In_z_
const T2* sample,
599 _In_
const std::locale& locale)
601 _Assume_(str || !count);
603 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
604 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
605 for (
size_t offset = 0;; ++offset) {
606 for (
size_t i = offset, j = 0;; ++i, ++j) {
609 if (i >= count || !str[i])
611 if (ctype1.tolower(str[i]) != ctype2.tolower(sample[j]))
625 template <
class T1,
class T2>
626 inline size_t strcpy(
627 _Out_writes_z_(_String_length_(src) + 1) T1* dst,
628 _In_z_
const T2* src)
630 _Assume_(dst && src);
631 for (
size_t i = 0; ; ++i) {
632 if ((dst[i] = src[i]) == 0)
646 template <
class T1,
class T2>
647 inline size_t strncpy(
648 _Out_writes_(count) _Post_maybez_ T1* dst,
649 _In_reads_or_z_opt_(count)
const T2* src, _In_
size_t count)
651 _Assume_(dst && src || !count);
652 for (
size_t i = 0; ; ++i) {
655 if ((dst[i] = src[i]) == 0)
670 template <
class T1,
class T2>
671 inline size_t strncpy(
672 _Out_writes_(count_dst) _Post_maybez_ T1* dst, _In_
size_t count_dst,
673 _In_reads_or_z_opt_(count_src)
const T2* src, _In_
size_t count_src)
675 _Assume_(dst || !count_dst);
676 _Assume_(src || !count_src);
677 for (
size_t i = 0; ; ++i)
681 if (i >= count_src) {
685 if ((dst[i] = src[i]) == 0)
698 template <
class T1,
class T2>
699 inline size_t strcat(
700 _In_z_ _Out_writes_z_(_String_length_(dst) + _String_length_(src) + 1) T1* dst,
701 _In_z_
const T2* src)
703 _Assume_(dst && src);
704 for (
size_t i = 0, j = stdex::strlen<T1>(dst); ; ++i, ++j) {
705 if ((dst[j] = src[i]) == 0)
719 template <
class T1,
class T2>
720 inline size_t strncat(
722 _In_reads_or_z_opt_(count)
const T2* src, _In_
size_t count)
724 _Assume_(dst && src || !count);
725 for (
size_t i = 0, j = stdex::strlen<T1>(dst); ; ++i, ++j) {
728 if ((dst[j] = src[i]) == 0)
743 template <
class T1,
class T2>
744 inline size_t strncat(
745 _Out_writes_(count_dst) _Post_maybez_ T1* dst, _In_
size_t count_dst,
746 _In_reads_or_z_opt_(count_src)
const T2* src, _In_
size_t count_src)
748 _Assume_(dst || !count_dst);
749 _Assume_(src || !count_src);
750 for (
size_t i = 0, j = stdex::strnlen<T1>(dst, count_dst); ; ++i, ++j)
754 if (i >= count_src) {
758 if ((dst[j] = src[i]) == 0)
774 inline _Check_return_ _Ret_maybenull_z_ T* strdup(_In_opt_z_
const T* str)
778 size_t count = strlen(str) + 1;
779 T* dst =
new T[count];
780 strncpy(dst, count, str, SIZE_MAX);
796 inline _Ret_z_ T* strndup(
797 _In_reads_or_z_opt_(count)
const T* str,
800 T* dst =
new T[count];
801 strncpy(dst, count, str, SIZE_MAX);
815 inline size_t crlf2nl(_Out_writes_z_(strlen(src)) T* dst, _In_z_
const T* src)
820 for (i = j = 0; src[j];) {
821 if (src[j] !=
'\r' || src[j + 1] !=
'\n')
838 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
839 inline void crlf2nl(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &dst, _In_z_
const _Elem* src)
842 _Assume_(src != dst.c_str());
844 dst.reserve(strlen(src));
845 for (
size_t j = 0; src[j];) {
846 if (src[j] !=
'\r' || src[j + 1] !=
'\n')
860 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
861 inline void crlf2nl(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str)
864 for (i = j = 0, n = str.size(); j < n;) {
865 if (str[j] !=
'\r' || str[j + 1] !=
'\n')
876 template <
class T,
class T_bin>
877 inline T_bin strtoint(
878 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
879 _Out_opt_
size_t* end,
881 _Out_ uint8_t& flags)
883 _Assume_(str || !count);
884 _Assume_(radix == 0 || 2 <= radix && radix <= 36);
887 T_bin value = 0, digit,
889 max_ui_pre1, max_ui_pre2;
895 if (i >= count || !str[i])
goto error;
896 if (!isspace(str[i]))
break;
903 if (i >= count || !str[i])
goto error;
905 else if (str[i] ==
'-') {
908 if (i >= count || !str[i])
goto error;
913 if (str[i] ==
'0' && i + 1 < count && (str[i + 1] ==
'x' || str[i + 1] ==
'X')) {
915 if (i >= count || !str[i])
goto error;
922 if (i >= count || !str[i])
goto error;
923 if (str[i] ==
'x' || str[i] ==
'X') {
926 if (i >= count || !str[i])
goto error;
936 max_ui_pre1 = max_ui / (T_bin)radix;
937 max_ui_pre2 = max_ui % (T_bin)radix;
939 if (
'0' <= str[i] && str[i] <=
'9')
940 digit = (T_bin)str[i] -
'0';
941 else if (
'A' <= str[i] && str[i] <=
'Z')
942 digit = (T_bin)str[i] -
'A' +
'\x0a';
943 else if (
'a' <= str[i] && str[i] <=
'z')
944 digit = (T_bin)str[i] -
'a' +
'\x0a';
947 if (digit >= (T_bin)radix)
950 if (value < max_ui_pre1 ||
951 (value == max_ui_pre1 && digit <= max_ui_pre2))
952 value = value * (T_bin)radix + digit;
959 if (i >= count || !str[i])
979 template <
class T,
class T_bin>
981 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
982 _Out_opt_
size_t* end,
988 switch (
sizeof(T_bin)) {
990 value = (T_bin)strtoint<T, uint8_t>(str, count, end, radix, flags);
991 if ((flags & 0x01) && (value & 0x80)) {
995 return (flags & 0x02) ?
996 (flags & 0x01) ? (T_bin)0x80 : (T_bin)0x7f :
997 (flags & 0x01) ? -value : value;
1000 value = (T_bin)strtoint<T, uint16_t>(str, count, end, radix, flags);
1001 if ((flags & 0x01) && (value & 0x8000)) {
1005 return (flags & 0x02) ?
1006 (flags & 0x01) ? (T_bin)0x8000 : (T_bin)0x7fff :
1007 (flags & 0x01) ? -value : value;
1010 value = (T_bin)strtoint<T, uint32_t>(str, count, end, radix, flags);
1011 if ((flags & 0x01) && (value & 0x80000000)) {
1015 return (flags & 0x02) ?
1016 (flags & 0x01) ? (T_bin)0x80000000 : (T_bin)0x7fffffff :
1017 (flags & 0x01) ? -value : value;
1020 value = (T_bin)strtoint<T, uint64_t>(str, count, end, radix, flags);
1021 if ((flags & 0x01) && (value & 0x8000000000000000)) {
1025 return (flags & 0x02) ?
1026 (flags & 0x01) ? (T_bin)0x8000000000000000 : (T_bin)0x7fffffffffffffff :
1027 (flags & 0x01) ? -value : value;
1030 throw std::invalid_argument(
"Unsupported bit length");
1044 template <
class T,
class T_bin>
1045 inline T_bin strtouint(
1046 _In_reads_or_z_opt_(count)
const T* str,
1048 _Out_opt_
size_t* end,
1054 switch (
sizeof(T_bin)) {
1055 case 1: value = (T_bin)strtoint<T, uint8_t>(str, count, end, radix, flags);
break;
1056 case 2: value = (T_bin)strtoint<T, uint16_t>(str, count, end, radix, flags);
break;
1057 case 4: value = (T_bin)strtoint<T, uint32_t>(str, count, end, radix, flags);
break;
1058 case 8: value = (T_bin)strtoint<T, uint64_t>(str, count, end, radix, flags);
break;
1059 default:
throw std::invalid_argument(
"Unsupported bit length");
1062 return (flags & 0x02) ?
1063 (flags & 0x01) ? (T_bin)0 : (T_bin)-1 :
1064 (flags & 0x01) ? ~value : value;
1078 inline int32_t strto32(
1079 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1080 _Out_opt_
size_t* end,
1083 return strtoint<T, int32_t>(str, count, end, radix);
1097 inline int64_t strto64(
1098 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1099 _Out_opt_
size_t* end,
1102 return strtoint<T, int64_t>(str, count, end, radix);
1117 inline intptr_t strtoi(
1118 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1119 _Out_opt_
size_t* end,
1122#if defined(_WIN64) || defined(__LP64__)
1123 return (intptr_t)strto64(str, count, end, radix);
1125 return (intptr_t)strto32(str, count, end, radix);
1140 inline uint32_t strtou32(
1141 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1142 _Out_opt_
size_t* end,
1145 return strtouint<T, uint32_t>(str, count, end, radix);
1159 inline uint64_t strtou64(
1160 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1161 _Out_opt_
size_t* end,
1164 return strtouint<T, uint64_t>(str, count, end, radix);
1179 inline size_t strtoui(
1180 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1181 _Out_opt_
size_t* end,
1184#if defined(_WIN64) || defined(__LP64__)
1185 return (
size_t)strtou64(str, count, end, radix);
1187 return (
size_t)strtou32(str, count, end, radix);
1192 inline int vsnprintf(_Out_z_cap_(capacity)
char *str, _In_
size_t capacity, _In_z_ _Printf_format_string_params_(2)
const char *format, _In_opt_ locale_t locale, _In_ va_list arg)
1197#pragma warning(suppress: 4996)
1198 r = _vsnprintf_l(str, capacity, format, locale, arg);
1200 r = ::vsnprintf(str, capacity, format, arg);
1202 if (r == -1 && strnlen(str, capacity) == capacity) {
1204 capacity += std::max<size_t>(capacity / 8, 0x80);
1205 if (capacity > INT_MAX)
1206 throw std::invalid_argument(
"string too big");
1207 return (
int)capacity;
1212 inline int vsnprintf(_Out_z_cap_(capacity)
wchar_t *str, _In_
size_t capacity, _In_z_ _Printf_format_string_params_(2)
const wchar_t *format, _In_opt_ locale_t locale, _In_ va_list arg)
1217#pragma warning(suppress: 4996)
1218 r = _vsnwprintf_l(str, capacity, format, locale, arg);
1220 r = vswprintf(str, capacity, format, arg);
1222 if (r == -1 && strnlen(str, capacity) == capacity) {
1224 capacity += std::max<size_t>(capacity / 8, 0x80);
1225 if (capacity > INT_MAX)
1226 throw std::invalid_argument(
"string too big");
1227 return (
int)capacity;
1243 template<
class _Elem,
class _Traits,
class _Ax>
1244 inline size_t vappendf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, _In_ va_list arg)
1246 _Elem buf[1024/
sizeof(_Elem)];
1249 int count = vsnprintf(buf, _countof(buf) - 1, format, locale, arg);
1252 str.append(buf, count);
1255 for (
size_t capacity = 2*1024/
sizeof(_Elem);; capacity *= 2) {
1257 auto buf_dyn = std::make_unique<_Elem[]>(capacity);
1258 count = vsnprintf(buf_dyn.get(), capacity - 1, format, locale, arg);
1260 str.append(buf_dyn.get(), count);
1275 template<
class _Elem,
class _Traits,
class _Ax>
1276 inline size_t appendf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, ...)
1279 va_start(arg, locale);
1280 size_t n = vappendf(str, format, locale, arg);
1293 template<
class _Elem,
class _Traits,
class _Ax>
1294 inline void vsprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, _In_ va_list arg)
1297 vappendf(str, format, locale, arg);
1307 template<
class _Elem,
class _Traits,
class _Ax>
1308 inline void sprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, ...)
1311 va_start(arg, locale);
1312 vsprintf(str, format, locale, arg);
1325 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1326 inline std::basic_string<_Elem, _Traits, _Ax> vsprintf(_In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, _In_ va_list arg)
1328 std::basic_string<_Elem, _Traits, _Ax> str;
1329 vappendf(str, format, locale, arg);
1341 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1342 inline std::basic_string<_Elem, _Traits, _Ax> sprintf(_In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, ...)
1345 va_start(arg, locale);
1346 auto str = vsprintf(format, locale, arg);
1352 inline size_t strftime(_Out_z_cap_(capacity)
char *str, _In_
size_t capacity, _In_z_ _Printf_format_string_
const char *format, _In_
const struct tm* time, _In_opt_ locale_t locale)
1355 return _strftime_l(str, capacity, format, time, locale);
1357 return strftime_l(str, capacity, format, time, locale);
1361 inline size_t strftime(_Out_z_cap_(capacity)
wchar_t *str, _In_
size_t capacity, _In_z_ _Printf_format_string_
const wchar_t *format, _In_
const struct tm* time, _In_opt_ locale_t locale)
1364 return _wcsftime_l(str, capacity, format, time, locale);
1366 return wcsftime_l(str, capacity, format, time, locale);
1379 template<
class _Elem,
class _Traits,
class _Ax>
1380 inline void strcatftime(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_
const _Elem *format, _In_
const struct tm* time, _In_opt_ locale_t locale)
1382 _Elem buf[1024/
sizeof(_Elem)];
1385 size_t count = strftime(buf, _countof(buf), format, time, locale);
1388 str.append(buf, count);
1390 for (
size_t capacity = 2*1024/
sizeof(_Elem);; capacity *= 2) {
1392 auto buf_dyn = std::make_unique<_Elem[]>(capacity);
1393 count = strftime(buf_dyn.get(), capacity, format, time, locale);
1395 str.append(buf_dyn.get(), count);
1410 template<
class _Elem,
class _Traits,
class _Ax>
1411 inline void strftime(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_
const _Elem *format, _In_
const struct tm* time, _In_opt_ locale_t locale)
1414 strcatftime(str, format, time, locale);
1427 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1428 inline std::basic_string<_Elem, _Traits, _Ax> strftime(_In_z_ _Printf_format_string_
const _Elem *format, _In_
const struct tm* time, _In_opt_ locale_t locale)
1430 std::basic_string<_Elem, _Traits, _Ax> str;
1431 strcatftime(str, format, time, locale);
1443 inline void strlwr(_Inout_z_ T* str, _In_
const std::locale& locale)
1446 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1447 for (
size_t i = 0; str[i]; ++i)
1448 str[i] = ctype.tolower(str[i]);
1460 inline void strlwr(_Inout_updates_z_(count) T* str, _In_
size_t count, _In_
const std::locale& locale)
1462 _Assume_(str || !count);
1463 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1464 for (
size_t i = 0; i < count && str[i]; ++i)
1465 str[i] = ctype.tolower(str[i]);
1476 inline void strupr(_Inout_z_ T* str, _In_
const std::locale& locale)
1479 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1480 for (
size_t i = 0; str[i]; ++i)
1481 str[i] = ctype.toupper(str[i]);
1493 inline void strupr(_Inout_updates_z_(count) T* str, _In_
size_t count, _In_
const std::locale& locale)
1495 _Assume_(str || !count);
1496 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1497 for (
size_t i = 0; i < count && str[i]; ++i)
1498 str[i] = ctype.toupper(str[i]);
1508 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1509 inline void strupr(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str, _In_
const std::locale& locale)
1511 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1512 for (
size_t i = 0; i < str.size(); ++i)
1513 str[i] = ctype.toupper(str[i]);
1525 inline size_t ltrim(
1526 _Inout_z_count_(count) T* str, _In_
size_t count,
1527 _In_
const std::locale& locale)
1529 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1530 for (
size_t i = 0;; ++i) {
1532 if (count) str[0] = 0;
1539 if (!ctype.is(ctype.space, str[i])) {
1541 return strnlen(str, count);
1542 size_t n = count != SIZE_MAX ? strncpy(str, str + i, count - i) : strcpy(str, str + i);
1554 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1555 inline void ltrim(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &s, _In_
const std::locale& locale)
1557 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1563 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }));
1575 inline size_t rtrim(
1576 _Inout_z_count_(count) T* str, _In_
size_t count,
1577 _In_
const std::locale& locale)
1579 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1580 for (
size_t i = 0, j = 0;;) {
1581 if (i >= count || !str[i]) {
1582 if (j < count) str[j] = 0;
1585 if (!ctype.is(ctype.space, str[i]))
1597 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1598 static inline void rtrim(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &s, _In_
const std::locale& locale)
1600 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1605 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }).base(),
1619 _Inout_z_count_(count) T* str, _In_
size_t count,
1620 _In_
const std::locale& locale)
1622 return ltrim(str, rtrim(str, count, locale), locale);
1630 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1631 static inline void trim(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &s, _In_
const std::locale& locale)
1633 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1639 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }));
1644 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }).base(),