@@ -87,7 +87,7 @@ namespace utf8
8787 }
8888
8989 inline HRESULT NarrowStringToWideNoAlloc (_In_ LPCSTR sourceString, size_t sourceCount,
90- __out_ecount (destBufferCount) LPWSTR destString, size_t destBufferCount, _Out_ size_t * destCount)
90+ __out_ecount (destBufferCount) LPWSTR destString, size_t destBufferCount, _Out_ charcount_t * destCount)
9191 {
9292 size_t sourceStart = 0 ;
9393 size_t cbSourceString = sourceCount;
@@ -123,7 +123,7 @@ namespace utf8
123123
124124 if (sourceStart == sourceCount)
125125 {
126- *destCount = sourceCount;
126+ *destCount = static_cast < charcount_t >( sourceCount) ;
127127 destString[sourceCount] = WCHAR (0 );
128128 }
129129 else
@@ -160,7 +160,7 @@ namespace utf8
160160 // /
161161 template <typename AllocatorFunction>
162162 HRESULT NarrowStringToWide (_In_ AllocatorFunction allocator,_In_ LPCSTR sourceString,
163- size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t * destCount, size_t * allocateCount = nullptr )
163+ size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ charcount_t * destCount, size_t * allocateCount = nullptr )
164164 {
165165 size_t cbDestString = (sourceCount + 1 ) * sizeof (WCHAR);
166166 if (cbDestString < sourceCount) // overflow ?
@@ -184,7 +184,7 @@ namespace utf8
184184 }
185185
186186 template <class Allocator >
187- HRESULT NarrowStringToWide (_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t * destCount, size_t * allocateCount = nullptr )
187+ HRESULT NarrowStringToWide (_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ charcount_t * destCount, size_t * allocateCount = nullptr )
188188 {
189189 return NarrowStringToWide (Allocator::allocate, sourceString, sourceCount, destStringPtr, destCount, allocateCount);
190190 }
@@ -205,30 +205,30 @@ namespace utf8
205205
206206 inline HRESULT NarrowStringToWideDynamic (_In_ LPCSTR sourceString, _Out_ LPWSTR* destStringPtr)
207207 {
208- size_t unused;
208+ charcount_t unused;
209209 return NarrowStringToWide<malloc_allocator>(
210210 sourceString, strlen (sourceString), destStringPtr, &unused);
211211 }
212212
213- inline HRESULT NarrowStringToWideDynamicGetLength (_In_ LPCSTR sourceString, _Out_ LPWSTR* destStringPtr, _Out_ size_t * destLength)
213+ inline HRESULT NarrowStringToWideDynamicGetLength (_In_ LPCSTR sourceString, _Out_ LPWSTR* destStringPtr, _Out_ charcount_t * destLength)
214214 {
215215 return NarrowStringToWide<malloc_allocator>(
216216 sourceString, strlen (sourceString), destStringPtr, destLength);
217217 }
218218
219- template <class Allocator , class SrcType , class DstType >
219+ template <class Allocator , class SrcType , class DstType , class CountType >
220220 class NarrowWideStringConverter
221221 {
222222 public:
223223 static size_t Length (const SrcType& src);
224224 static HRESULT Convert (
225- SrcType src, size_t srcCount, DstType* dst, size_t * dstCount, size_t * allocateCount = nullptr );
225+ SrcType src, size_t srcCount, DstType* dst, CountType * dstCount, size_t * allocateCount = nullptr );
226226 static HRESULT ConvertNoAlloc (
227- SrcType src, size_t srcCount, DstType dst, size_t dstCount, size_t * written);
227+ SrcType src, size_t srcCount, DstType dst, CountType dstCount, CountType * written);
228228 };
229229
230230 template <class Allocator >
231- class NarrowWideStringConverter <Allocator, LPCSTR, LPWSTR>
231+ class NarrowWideStringConverter <Allocator, LPCSTR, LPWSTR, charcount_t >
232232 {
233233 public:
234234 // Note: Typically caller should pass in Utf8 string length. Following
@@ -240,23 +240,23 @@ namespace utf8
240240
241241 static HRESULT Convert (
242242 LPCSTR sourceString, size_t sourceCount,
243- LPWSTR* destStringPtr, size_t * destCount, size_t * allocateCount = nullptr )
243+ LPWSTR* destStringPtr, charcount_t * destCount, size_t * allocateCount = nullptr )
244244 {
245245 return NarrowStringToWide<Allocator>(
246246 sourceString, sourceCount, destStringPtr, destCount, allocateCount);
247247 }
248248
249249 static HRESULT ConvertNoAlloc (
250250 LPCSTR sourceString, size_t sourceCount,
251- LPWSTR destStringPtr, size_t destCount, size_t * written)
251+ LPWSTR destStringPtr, charcount_t destCount, charcount_t * written)
252252 {
253253 return NarrowStringToWideNoAlloc (
254254 sourceString, sourceCount, destStringPtr, destCount, written);
255255 }
256256 };
257257
258258 template <class Allocator >
259- class NarrowWideStringConverter <Allocator, LPCWSTR, LPSTR>
259+ class NarrowWideStringConverter <Allocator, LPCWSTR, LPSTR, size_t >
260260 {
261261 public:
262262 // Note: Typically caller should pass in WCHAR string length. Following
@@ -283,14 +283,14 @@ namespace utf8
283283 }
284284 };
285285
286- template <class Allocator , class SrcType , class DstType >
286+ template <class Allocator , class SrcType , class DstType , class CountType >
287287 class NarrowWideConverter
288288 {
289- typedef NarrowWideStringConverter<Allocator, SrcType, DstType>
289+ typedef NarrowWideStringConverter<Allocator, SrcType, DstType, CountType >
290290 StringConverter;
291291 private:
292292 DstType dst;
293- size_t dstCount;
293+ CountType dstCount;
294294 size_t allocateCount;
295295 bool freeDst;
296296
@@ -347,6 +347,6 @@ namespace utf8
347347 }
348348 };
349349
350- typedef NarrowWideConverter<malloc_allocator, LPCSTR, LPWSTR> NarrowToWide;
351- typedef NarrowWideConverter<malloc_allocator, LPCWSTR, LPSTR> WideToNarrow;
350+ typedef NarrowWideConverter<malloc_allocator, LPCSTR, LPWSTR, charcount_t > NarrowToWide;
351+ typedef NarrowWideConverter<malloc_allocator, LPCWSTR, LPSTR, size_t > WideToNarrow;
352352}
0 commit comments