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;
260 inline size_t strnichr(
261 _In_reads_or_z_opt_(count)
const T* str,
264 _In_
const std::locale& locale)
266 _Assume_(str || !count);
267 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
268 chr = ctype.tolower(chr);
269 for (
size_t i = 0; i < count && str[i]; ++i)
270 if (ctype.tolower(str[i]) == chr)
return i;
284 inline size_t strrnichr(
285 _In_reads_or_z_opt_(count)
const T* str,
288 _In_
const std::locale& locale)
290 _Assume_(str || !count);
291 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
292 chr = ctype.tolower(chr);
294 for (
size_t i = 0; i < count && str[i]; ++i)
295 if (ctype.tolower(str[i]) == chr) z = i;
307 template <
class T1,
class T2>
308 inline int strcmp(
const T1* str1,
const T2* str2)
310 _Assume_(str1 && str2);
312 for (
size_t i = 0; (a = str1[i]) | (b = str2[i]); ++i) {
313 if (a > b)
return +1;
314 if (a < b)
return -1;
329 template <
class T1,
class T2>
331 _In_reads_or_z_opt_(count1)
const T1* str1, _In_
size_t count1,
332 _In_reads_or_z_opt_(count2)
const T2* str2, _In_
size_t count2)
334 _Assume_(str1 || !count1);
335 _Assume_(str2 || !count2);
336 size_t i; T1 a; T2 b;
337 for (i = 0; i < count1 && i < count2 && ((a = str1[i]) | (b = str2[i])); ++i) {
338 if (a > b)
return +1;
339 if (a < b)
return -1;
341 if (i < count1 && str1[i])
return +1;
342 if (i < count2 && str2[i])
return -1;
355 template <
class T1,
class T2>
356 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)
358 _Assume_((str1 && str2) || !count);
359 size_t i; T1 a; T2 b;
360 for (i = 0; i < count && ((a = str1[i]) | (b = str2[i])); ++i) {
361 if (a > b)
return +1;
362 if (a < b)
return -1;
364 if (i < count && str1[i])
return +1;
365 if (i < count && str2[i])
return -1;
381 _In_reads_or_z_opt_(count1)
const T* str1, _In_
size_t count1,
382 _In_reads_or_z_opt_(count2)
const T* str2, _In_
size_t count2,
383 _In_
const std::locale& locale)
385 _Assume_(str1 || !count1);
386 _Assume_(str2 || !count2);
387 auto& collate = std::use_facet<std::collate<T>>(locale);
388 return collate.compare(str1, str1 + count1, str2, str2 + count2);
399 template <
class T1,
class T2>
400 inline int stricmp(_In_z_
const T1* str1, _In_z_
const T2* str2, _In_
const std::locale& locale)
404 size_t i; T1 a; T2 b;
405 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
406 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
407 for (i = 0; (a = ctype1.tolower(str1[i])) | (b = ctype2.tolower(str2[i])); i++) {
408 if (a > b)
return +1;
409 if (a < b)
return -1;
411 if (str1[i])
return +1;
412 if (str2[i])
return -1;
425 template <
class T1,
class T2>
426 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)
428 _Assume_(str1 || !count);
429 _Assume_(str2 || !count);
430 size_t i; T1 a; T2 b;
431 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
432 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
433 for (i = 0; i < count && ((a = ctype1.tolower(str1[i])) | (b = ctype2.tolower(str2[i]))); i++) {
434 if (a > b)
return +1;
435 if (a < b)
return -1;
437 if (i < count && str1[i])
return +1;
438 if (i < count && str2[i])
return -1;
452 template <
class T1,
class T2>
454 _In_reads_or_z_opt_(count1)
const T1* str1, _In_
size_t count1,
455 _In_reads_or_z_opt_(count2)
const T2* str2, _In_
size_t count2,
456 _In_
const std::locale& locale)
458 _Assume_(str1 || !count1);
459 _Assume_(str2 || !count2);
460 size_t i; T1 a; T2 b;
461 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
462 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
463 for (i = 0; i < count1 && i < count2 && ((a = ctype1.tolower(str1[i])) | (b = ctype2.tolower(str2[i]))); i++) {
464 if (a > b)
return +1;
465 if (a < b)
return -1;
467 if (i < count1 && str1[i])
return +1;
468 if (i < count2 && str2[i])
return -1;
480 template <
class T1,
class T2>
481 inline size_t strstr(
482 _In_z_
const T1* str,
483 _In_z_
const T2* sample)
487 for (
size_t offset = 0;; ++offset) {
488 for (
size_t i = offset, j = 0;; ++i, ++j) {
493 if (str[i] != sample[j])
508 template <
class T1,
class T2>
509 inline size_t strnstr(
510 _In_reads_or_z_opt_(count)
const T1* str,
512 _In_z_
const T2* sample)
514 _Assume_(str || !count);
516 for (
size_t offset = 0;; ++offset) {
517 for (
size_t i = offset, j = 0;; ++i, ++j) {
520 if (i >= count || !str[i])
522 if (str[i] != sample[j])
536 template <
class T1,
class T2>
537 inline size_t stristr(
538 _In_z_
const T1* str,
539 _In_z_
const T2* sample,
540 _In_
const std::locale& locale)
544 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
545 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
546 for (
size_t offset = 0;; ++offset) {
547 for (
size_t i = offset, j = 0;; ++i, ++j) {
552 if (ctype1.tolower(str[i]) != ctype2.tolower(sample[j]))
567 template <
class T1,
class T2>
568 inline size_t strnistr(
569 _In_reads_or_z_opt_(count)
const T1* str,
571 _In_z_
const T2* sample,
572 _In_
const std::locale& locale)
574 _Assume_(str || !count);
576 const auto& ctype1 = std::use_facet<std::ctype<T1>>(locale);
577 const auto& ctype2 = std::use_facet<std::ctype<T2>>(locale);
578 for (
size_t offset = 0;; ++offset) {
579 for (
size_t i = offset, j = 0;; ++i, ++j) {
582 if (i >= count || !str[i])
584 if (ctype1.tolower(str[i]) != ctype2.tolower(sample[j]))
598 template <
class T1,
class T2>
599 inline size_t strcpy(
600 _Out_writes_z_(_String_length_(src) + 1) T1* dst,
601 _In_z_
const T2* src)
603 _Assume_(dst && src);
604 for (
size_t i = 0; ; ++i) {
605 if ((dst[i] = src[i]) == 0)
619 template <
class T1,
class T2>
620 inline size_t strncpy(
621 _Out_writes_(count) _Post_maybez_ T1* dst,
622 _In_reads_or_z_opt_(count)
const T2* src, _In_
size_t count)
624 _Assume_(dst && src || !count);
625 for (
size_t i = 0; ; ++i) {
628 if ((dst[i] = src[i]) == 0)
643 template <
class T1,
class T2>
644 inline size_t strncpy(
645 _Out_writes_(count_dst) _Post_maybez_ T1* dst, _In_
size_t count_dst,
646 _In_reads_or_z_opt_(count_src)
const T2* src, _In_
size_t count_src)
648 _Assume_(dst || !count_dst);
649 _Assume_(src || !count_src);
650 for (
size_t i = 0; ; ++i)
654 if (i >= count_src) {
658 if ((dst[i] = src[i]) == 0)
671 template <
class T1,
class T2>
672 inline size_t strcat(
673 _In_z_ _Out_writes_z_(_String_length_(dst) + _String_length_(src) + 1) T1* dst,
674 _In_z_
const T2* src)
676 _Assume_(dst && src);
677 for (
size_t i = 0, j = stdex::strlen<T1>(dst); ; ++i, ++j) {
678 if ((dst[j] = src[i]) == 0)
692 template <
class T1,
class T2>
693 inline size_t strncat(
695 _In_reads_or_z_opt_(count)
const T2* src, _In_
size_t count)
697 _Assume_(dst && src || !count);
698 for (
size_t i = 0, j = stdex::strlen<T1>(dst); ; ++i, ++j) {
701 if ((dst[j] = src[i]) == 0)
716 template <
class T1,
class T2>
717 inline size_t strncat(
718 _Out_writes_(count_dst) _Post_maybez_ T1* dst, _In_
size_t count_dst,
719 _In_reads_or_z_opt_(count_src)
const T2* src, _In_
size_t count_src)
721 _Assume_(dst || !count_dst);
722 _Assume_(src || !count_src);
723 for (
size_t i = 0, j = stdex::strnlen<T1>(dst, count_dst); ; ++i, ++j)
727 if (i >= count_src) {
731 if ((dst[j] = src[i]) == 0)
747 inline _Check_return_ _Ret_maybenull_z_ T* strdup(_In_opt_z_
const T* str)
751 size_t count = strlen(str) + 1;
752 T* dst =
new T[count];
753 strncpy(dst, count, str, SIZE_MAX);
769 inline _Ret_z_ T* strndup(
770 _In_reads_or_z_opt_(count)
const T* str,
773 T* dst =
new T[count];
774 strncpy(dst, count, str, SIZE_MAX);
788 inline size_t crlf2nl(_Out_writes_z_(strlen(src)) T* dst, _In_z_
const T* src)
793 for (i = j = 0; src[j];) {
794 if (src[j] !=
'\r' || src[j + 1] !=
'\n')
811 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
812 inline void crlf2nl(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &dst, _In_z_
const _Elem* src)
815 _Assume_(src != dst.c_str());
817 dst.reserve(strlen(src));
818 for (
size_t j = 0; src[j];) {
819 if (src[j] !=
'\r' || src[j + 1] !=
'\n')
833 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
834 inline void crlf2nl(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str)
837 for (i = j = 0, n = str.size(); j < n;) {
838 if (str[j] !=
'\r' || str[j + 1] !=
'\n')
849 template <
class T,
class T_bin>
850 inline T_bin strtoint(
851 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
852 _Out_opt_
size_t* end,
854 _Out_ uint8_t& flags)
856 _Assume_(str || !count);
857 _Assume_(radix == 0 || 2 <= radix && radix <= 36);
860 T_bin value = 0, digit,
862 max_ui_pre1, max_ui_pre2;
868 if (i >= count || !str[i])
goto error;
869 if (!isspace(str[i]))
break;
876 if (i >= count || !str[i])
goto error;
878 else if (str[i] ==
'-') {
881 if (i >= count || !str[i])
goto error;
886 if (str[i] ==
'0' && i + 1 < count && (str[i + 1] ==
'x' || str[i + 1] ==
'X')) {
888 if (i >= count || !str[i])
goto error;
895 if (i >= count || !str[i])
goto error;
896 if (str[i] ==
'x' || str[i] ==
'X') {
899 if (i >= count || !str[i])
goto error;
909 max_ui_pre1 = max_ui / (T_bin)radix;
910 max_ui_pre2 = max_ui % (T_bin)radix;
912 if (
'0' <= str[i] && str[i] <=
'9')
913 digit = (T_bin)str[i] -
'0';
914 else if (
'A' <= str[i] && str[i] <=
'Z')
915 digit = (T_bin)str[i] -
'A' +
'\x0a';
916 else if (
'a' <= str[i] && str[i] <=
'z')
917 digit = (T_bin)str[i] -
'a' +
'\x0a';
920 if (digit >= (T_bin)radix)
923 if (value < max_ui_pre1 ||
924 (value == max_ui_pre1 && digit <= max_ui_pre2))
925 value = value * (T_bin)radix + digit;
932 if (i >= count || !str[i])
952 template <
class T,
class T_bin>
954 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
955 _Out_opt_
size_t* end,
961 switch (
sizeof(T_bin)) {
963 value = (T_bin)strtoint<T, uint8_t>(str, count, end, radix, flags);
964 if ((flags & 0x01) && (value & 0x80)) {
968 return (flags & 0x02) ?
969 (flags & 0x01) ? (T_bin)0x80 : (T_bin)0x7f :
970 (flags & 0x01) ? -value : value;
973 value = (T_bin)strtoint<T, uint16_t>(str, count, end, radix, flags);
974 if ((flags & 0x01) && (value & 0x8000)) {
978 return (flags & 0x02) ?
979 (flags & 0x01) ? (T_bin)0x8000 : (T_bin)0x7fff :
980 (flags & 0x01) ? -value : value;
983 value = (T_bin)strtoint<T, uint32_t>(str, count, end, radix, flags);
984 if ((flags & 0x01) && (value & 0x80000000)) {
988 return (flags & 0x02) ?
989 (flags & 0x01) ? (T_bin)0x80000000 : (T_bin)0x7fffffff :
990 (flags & 0x01) ? -value : value;
993 value = (T_bin)strtoint<T, uint64_t>(str, count, end, radix, flags);
994 if ((flags & 0x01) && (value & 0x8000000000000000)) {
998 return (flags & 0x02) ?
999 (flags & 0x01) ? (T_bin)0x8000000000000000 : (T_bin)0x7fffffffffffffff :
1000 (flags & 0x01) ? -value : value;
1003 throw std::invalid_argument(
"Unsupported bit length");
1017 template <
class T,
class T_bin>
1018 inline T_bin strtouint(
1019 _In_reads_or_z_opt_(count)
const T* str,
1021 _Out_opt_
size_t* end,
1027 switch (
sizeof(T_bin)) {
1028 case 1: value = (T_bin)strtoint<T, uint8_t>(str, count, end, radix, flags);
break;
1029 case 2: value = (T_bin)strtoint<T, uint16_t>(str, count, end, radix, flags);
break;
1030 case 4: value = (T_bin)strtoint<T, uint32_t>(str, count, end, radix, flags);
break;
1031 case 8: value = (T_bin)strtoint<T, uint64_t>(str, count, end, radix, flags);
break;
1032 default:
throw std::invalid_argument(
"Unsupported bit length");
1035 return (flags & 0x02) ?
1036 (flags & 0x01) ? (T_bin)0 : (T_bin)-1 :
1037 (flags & 0x01) ? ~value : value;
1051 inline int32_t strto32(
1052 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1053 _Out_opt_
size_t* end,
1056 return strtoint<T, int32_t>(str, count, end, radix);
1070 inline int64_t strto64(
1071 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1072 _Out_opt_
size_t* end,
1075 return strtoint<T, int64_t>(str, count, end, radix);
1090 inline intptr_t strtoi(
1091 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1092 _Out_opt_
size_t* end,
1095#if defined(_WIN64) || defined(__LP64__)
1096 return (intptr_t)strto64(str, count, end, radix);
1098 return (intptr_t)strto32(str, count, end, radix);
1113 inline uint32_t strtou32(
1114 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1115 _Out_opt_
size_t* end,
1118 return strtouint<T, uint32_t>(str, count, end, radix);
1132 inline uint64_t strtou64(
1133 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1134 _Out_opt_
size_t* end,
1137 return strtouint<T, uint64_t>(str, count, end, radix);
1152 inline size_t strtoui(
1153 _In_reads_or_z_opt_(count)
const T* str, _In_
size_t count,
1154 _Out_opt_
size_t* end,
1157#if defined(_WIN64) || defined(__LP64__)
1158 return (
size_t)strtou64(str, count, end, radix);
1160 return (
size_t)strtou32(str, count, end, radix);
1165 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)
1170#pragma warning(suppress: 4996)
1171 r = _vsnprintf_l(str, capacity, format, locale, arg);
1173 r = ::vsnprintf(str, capacity, format, arg);
1175 if (r == -1 && strnlen(str, capacity) == capacity) {
1177 capacity += std::max<size_t>(capacity / 8, 0x80);
1178 if (capacity > INT_MAX)
1179 throw std::invalid_argument(
"string too big");
1180 return (
int)capacity;
1185 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)
1190#pragma warning(suppress: 4996)
1191 r = _vsnwprintf_l(str, capacity, format, locale, arg);
1193 r = vswprintf(str, capacity, format, arg);
1195 if (r == -1 && strnlen(str, capacity) == capacity) {
1197 capacity += std::max<size_t>(capacity / 8, 0x80);
1198 if (capacity > INT_MAX)
1199 throw std::invalid_argument(
"string too big");
1200 return (
int)capacity;
1214 template<
class _Elem,
class _Traits,
class _Ax>
1215 inline void 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)
1217 _Elem buf[1024/
sizeof(_Elem)];
1220 int count = vsnprintf(buf, _countof(buf) - 1, format, locale, arg);
1223 str.append(buf, count);
1225 for (
size_t capacity = 2*1024/
sizeof(_Elem);; capacity *= 2) {
1227 auto buf_dyn = std::make_unique<_Elem[]>(capacity);
1228 count = vsnprintf(buf_dyn.get(), capacity - 1, format, locale, arg);
1230 str.append(buf_dyn.get(), count);
1244 template<
class _Elem,
class _Traits,
class _Ax>
1245 inline void appendf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, ...)
1248 va_start(arg, locale);
1249 vappendf(str, format, locale, arg);
1261 template<
class _Elem,
class _Traits,
class _Ax>
1262 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)
1265 vappendf(str, format, locale, arg);
1275 template<
class _Elem,
class _Traits,
class _Ax>
1276 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, ...)
1279 va_start(arg, locale);
1280 vsprintf(str, format, locale, arg);
1293 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1294 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)
1296 std::basic_string<_Elem, _Traits, _Ax> str;
1297 vappendf(str, format, locale, arg);
1309 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1310 inline std::basic_string<_Elem, _Traits, _Ax> sprintf(_In_z_ _Printf_format_string_params_(2)
const _Elem *format, _In_opt_ locale_t locale, ...)
1313 va_start(arg, locale);
1314 auto str = vsprintf(format, locale, arg);
1320 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)
1323 return _strftime_l(str, capacity, format, time, locale);
1325 return strftime_l(str, capacity, format, time, locale);
1329 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)
1332 return _wcsftime_l(str, capacity, format, time, locale);
1334 return wcsftime_l(str, capacity, format, time, locale);
1347 template<
class _Elem,
class _Traits,
class _Ax>
1348 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)
1350 _Elem buf[1024/
sizeof(_Elem)];
1353 size_t count = strftime(buf, _countof(buf), format, time, locale);
1356 str.append(buf, count);
1358 for (
size_t capacity = 2*1024/
sizeof(_Elem);; capacity *= 2) {
1360 auto buf_dyn = std::make_unique<_Elem[]>(capacity);
1361 count = strftime(buf_dyn.get(), capacity, format, time, locale);
1363 str.append(buf_dyn.get(), count);
1378 template<
class _Elem,
class _Traits,
class _Ax>
1379 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)
1382 strcatftime(str, format, time, locale);
1395 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1396 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)
1398 std::basic_string<_Elem, _Traits, _Ax> str;
1399 strcatftime(str, format, time, locale);
1411 inline void strlwr(_Inout_z_ T* str, _In_
const std::locale& locale)
1414 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1415 for (
size_t i = 0; str[i]; ++i)
1416 str[i] = ctype.tolower(str[i]);
1428 inline void strlwr(_Inout_updates_z_(count) T* str, _In_
size_t count, _In_
const std::locale& locale)
1430 _Assume_(str || !count);
1431 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1432 for (
size_t i = 0; i < count && str[i]; ++i)
1433 str[i] = ctype.tolower(str[i]);
1444 inline void strupr(_Inout_z_ T* str, _In_
const std::locale& locale)
1447 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1448 for (
size_t i = 0; str[i]; ++i)
1449 str[i] = ctype.toupper(str[i]);
1461 inline void strupr(_Inout_updates_z_(count) T* str, _In_
size_t count, _In_
const std::locale& locale)
1463 _Assume_(str || !count);
1464 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1465 for (
size_t i = 0; i < count && str[i]; ++i)
1466 str[i] = ctype.toupper(str[i]);
1476 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1477 inline void strupr(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str, _In_
const std::locale& locale)
1479 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1480 for (
size_t i = 0; i < str.size(); ++i)
1481 str[i] = ctype.toupper(str[i]);
1493 inline size_t ltrim(
1494 _Inout_z_count_(count) T* str, _In_
size_t count,
1495 _In_
const std::locale& locale)
1497 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1498 for (
size_t i = 0;; ++i) {
1500 if (count) str[0] = 0;
1507 if (!ctype.is(ctype.space, str[i])) {
1509 return strnlen(str, count);
1510 size_t n = count != SIZE_MAX ? strncpy(str, str + i, count - i) : strcpy(str, str + i);
1522 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1523 inline void ltrim(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &s, _In_
const std::locale& locale)
1525 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1531 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }));
1543 inline size_t rtrim(
1544 _Inout_z_count_(count) T* str, _In_
size_t count,
1545 _In_
const std::locale& locale)
1547 const auto& ctype = std::use_facet<std::ctype<T>>(locale);
1548 for (
size_t i = 0, j = 0;;) {
1549 if (i >= count || !str[i]) {
1550 if (j < count) str[j] = 0;
1553 if (!ctype.is(ctype.space, str[i]))
1565 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1566 static inline void rtrim(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &s, _In_
const std::locale& locale)
1568 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1573 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }).base(),
1587 _Inout_z_count_(count) T* str, _In_
size_t count,
1588 _In_
const std::locale& locale)
1590 return ltrim(str, rtrim(str, count, locale), locale);
1598 template<
class _Elem,
class _Traits = std::
char_traits<_Elem>,
class _Ax = std::allocator<_Elem>>
1599 static inline void trim(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &s, _In_
const std::locale& locale)
1601 const auto& ctype = std::use_facet<std::ctype<_Elem>>(locale);
1607 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }));
1612 [&](_Elem ch) { return !ctype.is(ctype.space, ch); }).base(),