99#endif
1010
1111#include " precomp.h"
12+ // #include <sal.h>
13+ // #include <string>
14+ // #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
15+ // #define NOMINMAX
16+ // #define NOSERVICE
17+ // #define NOMCX
18+ // #define NOIME
19+ // #include <windows.h> // TODO: Remove. Only needed for MultiByteToWideChar.
1220
1321#if USE_CPP_MODULES
14- import Common.ArrayRef;
1522 export module Common.String;
23+ import Common.ArrayRef;
1624 export
1725 {
1826 #include " Common.String.h"
@@ -79,15 +87,15 @@ void RemoveTrailingZeroes(std::u16string& text) noexcept
7987}
8088
8189
82- array_ref<wchar_t > ToWString (int32_t value, OUT array_ref<wchar_t > s)
90+ array_ref<wchar_t > ToWString (int32_t value, /* out */ array_ref<wchar_t > s)
8391{
8492 auto charactersWritten = swprintf_s (s.data (), s.size (), L" %d" , value);
8593 return make_array_ref (s.data (), std::max (charactersWritten, 0 ));
8694}
8795
8896
8997// Fills the entire buffer up to fixed size, including leading zeroes.
90- void WriteZeroPaddedHexNum (uint32_t value, OUT array_ref<char16_t > text)
98+ void WriteZeroPaddedHexNum (uint32_t value, /* out */ array_ref<char16_t > text)
9199{
92100 // Convert character to digits.
93101 while (!text.empty ())
@@ -173,7 +181,7 @@ void GetFormattedString(_Out_ std::u16string& returnString, _In_z_ const char16_
173181{
174182 va_list vargs = nullptr ;
175183 va_start (vargs, formatString); // initialize variable arguments
176- GetFormattedString (OUT returnString, /* shouldConcatenate*/ false , formatString, vargs);
184+ GetFormattedString (/* out */ returnString, /* shouldConcatenate*/ false , formatString, vargs);
177185 va_end (vargs); // Reset variable arguments
178186}
179187
@@ -182,7 +190,7 @@ void AppendFormattedString(_Inout_ std::u16string& returnString, _In_z_ const ch
182190{
183191 va_list vargs = nullptr ;
184192 va_start (vargs, formatString); // initialize variable arguments
185- GetFormattedString (OUT returnString, /* shouldConcatenate*/ true , formatString, vargs);
193+ GetFormattedString (/* out */ returnString, /* shouldConcatenate*/ true , formatString, vargs);
186194 va_end (vargs); // Reset variable arguments
187195}
188196
@@ -245,7 +253,7 @@ void ToUpperCase(_Inout_ array_ref<char16_t> s)
245253
246254void UnescapeCppUniversalCharacterNames (
247255 array_ref<char16_t const > escapedText,
248- OUT std::u16string& expandedText
256+ /* out */ std::u16string& expandedText
249257 )
250258{
251259 expandedText.clear ();
@@ -287,7 +295,7 @@ void UnescapeCppUniversalCharacterNames(
287295 // Parse the number.
288296 if (digitSpan.size () >= expectedHexSequenceLength)
289297 {
290- char32_t hexValue = ReadUnsignedNumericValue (IN OUT digitSpan, 16 );
298+ char32_t hexValue = ReadUnsignedNumericValue (IN /* out */ digitSpan, 16 );
291299 if (digitSpan.empty ()) // Completely read the sequence.
292300 {
293301 replacement = hexValue;
@@ -320,7 +328,7 @@ void UnescapeCppUniversalCharacterNames(
320328}
321329
322330
323- void UnescapeHtmlNamedCharacterReferences (array_ref<char16_t const > escapedText, OUT std::u16string& expandedText)
331+ void UnescapeHtmlNamedCharacterReferences (array_ref<char16_t const > escapedText, /* out */ std::u16string& expandedText)
324332{
325333 expandedText.clear ();
326334 expandedText.reserve (escapedText.size ());
@@ -351,7 +359,7 @@ void UnescapeHtmlNamedCharacterReferences(array_ref<char16_t const> escapedText,
351359
352360 // Parse the number, and replacing on error with just a '\' to preserve original text.
353361 array_ref<char16_t const > digitSpan = {escapeStart, escapedText.end ()};
354- replacement = ReadUnsignedNumericValue (IN OUT digitSpan, radix);
362+ replacement = ReadUnsignedNumericValue (/* inout */ digitSpan, radix);
355363
356364 // Successful if the digits were not empty and a semicolon was present.
357365 if (digitSpan.begin () > escapedText.begin () && !digitSpan.empty () && digitSpan.front () == ' ;' )
@@ -384,7 +392,7 @@ void UnescapeHtmlNamedCharacterReferences(array_ref<char16_t const> escapedText,
384392
385393void EscapeCppUniversalCharacterNames (
386394 array_ref<char16_t const > text,
387- OUT std::u16string& escapedText
395+ /* out */ std::u16string& escapedText
388396 )
389397{
390398 constexpr size_t escapePrefixLength = 2 ; // \u or \U
@@ -405,12 +413,12 @@ void EscapeCppUniversalCharacterNames(
405413 if (IsCharacterBeyondBmp (ch))
406414 {
407415 // Write surrogate pair.
408- WriteZeroPaddedHexNum (ch, OUT longDigitRange);
416+ WriteZeroPaddedHexNum (ch, /* out */ longDigitRange);
409417 escapedText.insert (escapedText.size (), longEscapedSequence, std::size (longEscapedSequence));
410418 }
411419 else // Single UTF-16 code unit.
412420 {
413- WriteZeroPaddedHexNum (ch, OUT shortDigitRange);
421+ WriteZeroPaddedHexNum (ch, /* out */ shortDigitRange);
414422 escapedText.insert (escapedText.size (), shortEscapedSequence, std::size (shortEscapedSequence));
415423 }
416424 }
@@ -419,7 +427,7 @@ void EscapeCppUniversalCharacterNames(
419427
420428void EscapeHtmlNamedCharacterReferences (
421429 array_ref<char16_t const > text,
422- OUT std::u16string& escapedText
430+ /* out */ std::u16string& escapedText
423431 )
424432{
425433 constexpr size_t escapePrefixLength = 3 ; // &#x
@@ -441,12 +449,12 @@ void EscapeHtmlNamedCharacterReferences(
441449 if (IsCharacterBeyondBmp (ch))
442450 {
443451 // Write surrogate pair.
444- WriteZeroPaddedHexNum (ch, OUT longDigitRange);
452+ WriteZeroPaddedHexNum (ch, /* out */ longDigitRange);
445453 escapedText.insert (escapedText.size (), longEscapedSequence, std::size (longEscapedSequence));
446454 }
447455 else // Single UTF-16 code unit.
448456 {
449- WriteZeroPaddedHexNum (ch, OUT shortDigitRange);
457+ WriteZeroPaddedHexNum (ch, /* out */ shortDigitRange);
450458 escapedText.insert (escapedText.size (), shortEscapedSequence, std::size (shortEscapedSequence));
451459 }
452460 }
@@ -456,7 +464,7 @@ void EscapeHtmlNamedCharacterReferences(
456464_Out_range_ (0 , utf32text.end_ - utf32text.begin_)
457465size_t ConvertTextUtf16ToUtf32(
458466 array_ref<char16_t const > utf16text,
459- OUT array_ref<char32_t > utf32text,
467+ /* out */ array_ref<char32_t > utf32text,
460468 _Out_opt_ size_t * sourceCount
461469 ) noexcept
462470{
@@ -491,7 +499,7 @@ size_t ConvertTextUtf16ToUtf32(
491499_Out_range_ (0 , utf32text.end_ - utf32text.begin_)
492500size_t ConvertTextUtf16ToUtf32NoReplacement(
493501 array_ref<char16_t const > utf16text,
494- OUT array_ref<char32_t > utf32text,
502+ /* out */ array_ref<char32_t > utf32text,
495503 _Out_opt_ size_t * sourceCount
496504 ) noexcept
497505{
@@ -517,7 +525,7 @@ size_t ConvertTextUtf16ToUtf32NoReplacement(
517525_Out_range_ (0 , destMax)
518526size_t ConvertUtf32ToUtf16(
519527 array_ref<char32_t const > utf32text,
520- OUT array_ref<char16_t > utf16text
528+ /* out */ array_ref<char16_t > utf16text
521529 ) noexcept
522530{
523531 size_t si = 0 , di = 0 ;
@@ -561,7 +569,7 @@ namespace
561569
562570void ConvertTextUtf8ToUtf16 (
563571 array_ref<char const > utf8text,
564- OUT std::u16string& utf16text
572+ /* out */ std::u16string& utf16text
565573 )
566574{
567575 // This function can only throw if out-of-memory when resizing utf16text.
@@ -584,7 +592,7 @@ void ConvertTextUtf8ToUtf16(
584592 0 , // no flags for UTF8 (we allow invalid characters for testing)
585593 (LPCSTR)&utf8text[startingOffset],
586594 int32_t (utf8text.size () - startingOffset),
587- OUT ToWChar (const_cast <char16_t *>(utf16text.data ())), // workaround issue http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2391
595+ /* out */ ToWChar (const_cast <char16_t *>(utf16text.data ())), // workaround issue http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2391
588596 int32_t (utf16text.size ())
589597 );
590598
@@ -595,7 +603,7 @@ void ConvertTextUtf8ToUtf16(
595603
596604void ConvertTextUtf16ToUtf8 (
597605 array_ref<char16_t const > utf16text,
598- OUT std::string& utf8text
606+ /* out */ std::string& utf8text
599607 )
600608{
601609 utf8text.clear ();
@@ -616,7 +624,7 @@ void ConvertTextUtf16ToUtf8(
616624 // If no characters were converted (or if overflow), return empty string.
617625 if (charsConverted <= 0 )
618626 return ;
619- auto const bomCount = countof (utf8bom);
627+ auto const bomCount = sizeof (utf8bom);
620628 auto totalLength = charsConverted + bomCount;
621629 if (uint32_t (charsConverted) <= bomCount)
622630 return ;
@@ -631,7 +639,7 @@ void ConvertTextUtf16ToUtf8(
631639 0 , // no flags for UTF8 (we allow invalid characters for testing)
632640 ToWChar (utf16text.data ()),
633641 int32_t (utf16text.size ()),
634- OUT &utf8text[bomCount],
642+ /* out */ &utf8text[bomCount],
635643 int32_t (utf8text.size () - bomCount),
636644 nullptr , // defaultChar
637645 nullptr // usedDefaultChar
0 commit comments