@@ -36,15 +36,16 @@ namespace CodexTest
3636 //
3737 TEST_CASE (" CodexTest_EncodeTrueUtf8_SingleSurrogates" , " [CodexTest]" )
3838 {
39- const charcount_t charCount = 1 ;
40- utf8char_t encodedBuffer[(charCount + 1 ) * 3 ]; // +1 since the buffer will be null-terminated
39+ const size_t charCount = 1 ;
40+ constexpr size_t cbEncodedBuffer = charCount * 3 + 1 ; // +1 since the buffer will be null-terminated
41+ utf8char_t encodedBuffer[cbEncodedBuffer];
4142
4243 char16 testValues[] = { 0xD800 , 0xDB7F , 0xDB80 , 0xDBFF , 0xDC00 , 0xDF80 , 0xDFFF };
4344 const int numTestCases = _countof (testValues);
4445
4546 for (int i = 0 ; i < numTestCases; i++)
4647 {
47- size_t numEncodedBytes = utf8::EncodeTrueUtf8IntoAndNullTerminate (encodedBuffer, &testValues[i], charCount);
48+ size_t numEncodedBytes = utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> (encodedBuffer, cbEncodedBuffer , &testValues[i], charCount);
4849 CHECK (numEncodedBytes == 3 );
4950 CheckIsUnicodeReplacementChar (encodedBuffer);
5051 }
@@ -62,11 +63,12 @@ namespace CodexTest
6263 const int numTestCases = _countof (testCases);
6364 const charcount_t charCount = _countof (testCases[0 ].surrogatePair );
6465 const charcount_t maxEncodedByteCount = _countof (testCases[0 ].utf8Encoding );
65- utf8char_t encodedBuffer[maxEncodedByteCount + 1 ]; // +1 in case a null-terminating func is passed in
66+ const size_t encodedBufferSize = maxEncodedByteCount + 1 ; // +1 in case a null-terminating func is passed in
67+ utf8char_t encodedBuffer[encodedBufferSize];
6668
6769 for (int i = 0 ; i < numTestCases; i++)
6870 {
69- size_t numEncodedBytes = func (encodedBuffer, testCases[i].surrogatePair , charCount);
71+ size_t numEncodedBytes = func (encodedBuffer, encodedBufferSize, testCases[i].surrogatePair , charCount);
7072 CHECK (numEncodedBytes <= maxEncodedByteCount);
7173 for (size_t j = 0 ; j < numEncodedBytes; j++)
7274 {
@@ -106,7 +108,7 @@ namespace CodexTest
106108 { { 0xDBFF , 0xDFFF }, { 0xED , 0xAF , 0xBF , 0xED , 0xBF , 0xBF } } // U+10FFFF
107109 };
108110
109- RunUtf8EncodingTestCase (testCases, static_cast <size_t (*)(utf8char_t *, const char16*, charcount_t )>(utf8::EncodeInto));
111+ RunUtf8EncodingTestCase (testCases, static_cast <size_t (*)(utf8char_t *, size_t , const char16*, charcount_t )>(utf8::EncodeInto<utf8::Utf8EncodingKind::Cesu8> ));
110112 }
111113
112114 TEST_CASE (" CodexTest_EncodeUtf8_PairedSurrogates" , " [CodexTest]" )
@@ -132,7 +134,7 @@ namespace CodexTest
132134 { { 0xDBFF , 0xDFFF }, { 0xF4 , 0x8F , 0xBF , 0xBF } } // U+10FFFF
133135 };
134136
135- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
137+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
136138 }
137139
138140 TEST_CASE (" CodexTest_EncodeUtf8_NonCharacters" , " [CodexTest]" )
@@ -151,7 +153,7 @@ namespace CodexTest
151153 { { 0xFFFF }, { 0xEF , 0xBF , 0xBF } } // U+FFFF
152154 };
153155
154- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
156+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
155157 }
156158
157159 TEST_CASE (" CodexTest_EncodeUtf8_BoundaryChars" , " [CodexTest]" )
@@ -180,8 +182,8 @@ namespace CodexTest
180182 { { 0xDBFF , 0xDFFF }, { 0xF4 , 0x8F , 0xBF , 0xBF } } // U+10FFFF
181183 };
182184
183- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
184- RunUtf8EncodingTestCase (testCases2, utf8::EncodeTrueUtf8IntoAndNullTerminate );
185+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
186+ RunUtf8EncodingTestCase (testCases2, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
185187 }
186188
187189 TEST_CASE (" CodexTest_EncodeUtf8_SimpleCharacters" , " [CodexTest]" )
@@ -201,15 +203,16 @@ namespace CodexTest
201203 { { 0x20AC }, { 0xE2 , 0x82 , 0xAC } } // U+20AC - Euro symbol
202204 };
203205
204- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
206+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
205207 }
206208
207209 TEST_CASE (" CodexTest_EncodeTrueUtf8_SimpleString" , " [CodexTest]" )
208210 {
209211 const charcount_t charCount = 3 ;
210- utf8char_t encodedBuffer[(charCount + 1 ) * 3 ]; // +1 since the buffer will be null terminated
212+ constexpr size_t cbEncodedBuffer = charCount * 3 + 1 ; // +1 since the buffer will be null terminated
213+ utf8char_t encodedBuffer[cbEncodedBuffer];
211214 const char16* sourceBuffer = L" abc" ;
212- size_t numEncodedBytes = utf8::EncodeTrueUtf8IntoAndNullTerminate (encodedBuffer, sourceBuffer, charCount);
215+ size_t numEncodedBytes = utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> (encodedBuffer, cbEncodedBuffer , sourceBuffer, charCount);
213216 CHECK (numEncodedBytes == charCount);
214217 for (int i = 0 ; i < charCount; i++)
215218 {
0 commit comments