25 WCHAR localeBuffer[4];
28 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, localeBuffer, 4) &&
29 (localeBuffer[0] != 0 && localeBuffer[1] == 0)
32 PhpFormatDecimalSeparator = localeBuffer[0];
36 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, localeBuffer, 4) &&
37 (localeBuffer[0] != 0 && localeBuffer[1] == 0)
40 PhpFormatThousandSeparator = localeBuffer[0];
43 if (PhpFormatDecimalSeparator !=
'.')
44 PhpFormatUserLocale = _create_locale(LC_ALL,
"");
62 partLength = usedLength;
74 *buffer = format->
u.
Char;
90 memcpy(buffer, format->
u.
StringZ, count *
sizeof(WCHAR));
97 ULONG bytesInUnicodeString;
99 SIZE_T multiByteLength;
109 multiByteLength = strlen(multiByteBuffer);
113 &bytesInUnicodeString,
115 (ULONG)multiByteLength
122 bytesInUnicodeString,
125 (ULONG)multiByteLength
136 #define PROCESS_DIGIT(Input) \
138 r = (ULONG)(Input % radix); \
140 *temp-- = integerToChar[r]; \
144 #define COMMON_INTEGER_FORMAT(Input, Format) \
147 PCHAR integerToChar; \
155 if (((Format)->Type & FormatUseRadix) && (Format)->Radix >= 2 && (Format)->Radix <= 69) \
156 radix = (Format)->Radix; \
157 integerToChar = PhIntegerToChar; \
158 if ((Format)->Type & FormatUpperCase) \
159 integerToChar = PhIntegerToCharUpper; \
160 temp = tempBuffer + BUFFER_SIZE - 1; \
165 if ((Format)->Type & FormatGroupDigits) \
167 ULONG needsSep = 0; \
171 PROCESS_DIGIT(Input); \
173 if (++needsSep == 3 && Input != 0) \
175 *temp-- = PhpFormatThousandSeparator; \
179 } while (Input != 0); \
185 PROCESS_DIGIT(Input); \
186 } while (Input != 0); \
197 if (flags & PHP_FORMAT_NEGATIVE) \
199 else if ((Format)->Type & FormatPrefixSign) \
202 if (((Format)->Type & FormatPadZeros) && !((Format)->Type & FormatGroupDigits)) \
204 if (preCount + tempCount < (Format)->Width) \
206 flags |= PHP_FORMAT_PAD; \
207 padCount = (Format)->Width - (preCount + tempCount); \
208 preCount += padCount; \
213 ENSURE_BUFFER((preCount + tempCount) * sizeof(WCHAR)); \
216 if (flags & PHP_FORMAT_NEGATIVE) \
218 else if ((Format)->Type & FormatPrefixSign) \
221 if (flags & PHP_FORMAT_PAD) \
223 wmemset(buffer, '0', padCount); \
224 buffer += padCount; \
227 memcpy(buffer, temp, tempCount * sizeof(WCHAR)); \
228 buffer += tempCount; \
230 usedLength += (preCount + tempCount) * sizeof(WCHAR); \
236 goto CommonMaybeNegativeInt32Format;
242 CommonMaybeNegativeInt32Format:
246 int32 = -(
LONG)int32;
250 goto CommonInt32Format;
254 goto CommonInt32Format;
264 goto CommonMaybeNegativeInt64Format;
270 CommonMaybeNegativeInt64Format:
272 if ((LONG64)int64 < 0)
274 int64 = -(LONG64)int64;
278 goto CommonInt64Format;
282 goto CommonInt64Format;
292 #define COMMON_DOUBLE_FORMAT(Format) \
300 if ((Format)->Type & FormatUsePrecision) \
302 precision = (Format)->Precision; \
304 if (precision > BUFFER_SIZE - 1 - _CVTBUFSIZE) \
305 precision = BUFFER_SIZE - 1 - _CVTBUFSIZE; \
314 if ((Format)->Type & FormatStandardForm) \
316 else if ((Format)->Type & FormatHexadecimalForm) \
319 if ((Format)->Type & FormatUpperCase) \
324 value = (Format)->u.Double; \
325 temp = (PSTR)tempBuffer + 1; \
329 sizeof(tempBuffer) - 1, \
332 !!((Format)->Type & FormatUpperCase), \
333 PhpFormatUserLocale \
338 if ((Format)->Type & FormatCropZeros) \
339 _cropzeros_l(temp, PhpFormatUserLocale); \
341 length = (ULONG)strlen(temp); \
343 if (temp[0] == '-') \
345 flags |= PHP_FORMAT_NEGATIVE; \
349 else if ((Format)->Type & FormatPrefixSign) \
351 flags |= PHP_FORMAT_POSITIVE; \
354 if (((Format)->Type & FormatGroupDigits) && !((Format)->Type & (FormatStandardForm | FormatHexadecimalForm))) \
360 ULONG ensureLength; \
368 decimalPoint = temp; \
370 while ((UCHAR)(*decimalPoint - '0') < 10) \
376 wholeCount = (ULONG)(decimalPoint - temp); \
378 if (wholeCount != 0) \
379 sepsCount = (wholeCount + 2) / 3 - 1; \
383 ensureLength = (length + sepsCount) * sizeof(WCHAR); \
384 if (flags & (PHP_FORMAT_NEGATIVE | PHP_FORMAT_POSITIVE)) \
385 ensureLength += sizeof(WCHAR); \
386 ENSURE_BUFFER(ensureLength); \
388 copyCount = wholeCount; \
389 needsSep = (wholeCount + 2) % 3; \
393 if (flags & PHP_FORMAT_NEGATIVE) \
395 else if (flags & PHP_FORMAT_POSITIVE) \
398 while (copyCount--) \
400 *buffer++ = *whole++; \
402 if (needsSep-- == 0 && copyCount != 0) \
404 *buffer++ = PhpFormatThousandSeparator; \
410 if (flags & (PHP_FORMAT_NEGATIVE | PHP_FORMAT_POSITIVE)) \
411 usedLength += sizeof(WCHAR); \
412 usedLength += (wholeCount + sepsCount) * sizeof(WCHAR); \
416 copyCount = length - wholeCount; \
420 PhZeroExtendToUtf16Buffer(decimalPoint, copyCount, buffer); \
421 ADVANCE_BUFFER(copyCount * sizeof(WCHAR)); \
432 if (flags & (PHP_FORMAT_NEGATIVE | PHP_FORMAT_POSITIVE)) \
435 if ((Format)->Type & FormatPadZeros) \
437 if (preLength + length < (Format)->Width) \
439 flags |= PHP_FORMAT_PAD; \
440 padLength = (Format)->Width - (preLength + length); \
441 preLength += padLength; \
447 ENSURE_BUFFER((preLength + length) * sizeof(WCHAR)); \
451 if (flags & PHP_FORMAT_NEGATIVE) \
453 else if (flags & PHP_FORMAT_POSITIVE) \
456 if (flags & PHP_FORMAT_PAD) \
458 wmemset(buffer, '0', padLength); \
459 buffer += padLength; \
463 usedLength += preLength * sizeof(WCHAR); \
467 PhZeroExtendToUtf16Buffer((PSTR)temp, length, buffer); \
468 ADVANCE_BUFFER(length * sizeof(WCHAR)); \
487 s = (DOUBLE)format->
u.
Size;
489 if (format->
u.
Size == 0)
499 maxSizeUnit = format->
Radix;
505 i <
sizeof(PhpSizeUnitNamesCounted) /
sizeof(
PH_STRINGREF) &&
517 doubleFormat.
Width = 0;
522 ENSURE_BUFFER(
sizeof(WCHAR) + PhpSizeUnitNamesCounted[i].Length);
526 memcpy(buffer + 1, PhpSizeUnitNamesCounted[i].Buffer, PhpSizeUnitNamesCounted[i].Length);
528 ADVANCE_BUFFER(
sizeof(WCHAR) + PhpSizeUnitNamesCounted[i].Length);
534 partLength = usedLength - partLength;
541 newLength = format->
Width *
sizeof(WCHAR);
544 if (partLength < newLength)
546 addLength = newLength - partLength;
562 wmemset(buffer, pad, addLength /
sizeof(WCHAR));
570 start = buffer - partLength /
sizeof(WCHAR);
571 memmove(start + addLength /
sizeof(WCHAR), start, partLength);
572 wmemset(start, pad, addLength /
sizeof(WCHAR));