@@ -87,7 +87,7 @@ namespace utf8
87
87
}
88
88
89
89
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)
91
91
{
92
92
size_t sourceStart = 0 ;
93
93
size_t cbSourceString = sourceCount;
@@ -123,7 +123,7 @@ namespace utf8
123
123
124
124
if (sourceStart == sourceCount)
125
125
{
126
- *destCount = sourceCount;
126
+ *destCount = static_cast < charcount_t >( sourceCount) ;
127
127
destString[sourceCount] = WCHAR (0 );
128
128
}
129
129
else
@@ -160,7 +160,7 @@ namespace utf8
160
160
// /
161
161
template <typename AllocatorFunction>
162
162
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 )
164
164
{
165
165
size_t cbDestString = (sourceCount + 1 ) * sizeof (WCHAR);
166
166
if (cbDestString < sourceCount) // overflow ?
@@ -184,7 +184,7 @@ namespace utf8
184
184
}
185
185
186
186
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 )
188
188
{
189
189
return NarrowStringToWide (Allocator::allocate, sourceString, sourceCount, destStringPtr, destCount, allocateCount);
190
190
}
@@ -205,30 +205,30 @@ namespace utf8
205
205
206
206
inline HRESULT NarrowStringToWideDynamic (_In_ LPCSTR sourceString, _Out_ LPWSTR* destStringPtr)
207
207
{
208
- size_t unused;
208
+ charcount_t unused;
209
209
return NarrowStringToWide<malloc_allocator>(
210
210
sourceString, strlen (sourceString), destStringPtr, &unused);
211
211
}
212
212
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)
214
214
{
215
215
return NarrowStringToWide<malloc_allocator>(
216
216
sourceString, strlen (sourceString), destStringPtr, destLength);
217
217
}
218
218
219
- template <class Allocator , class SrcType , class DstType >
219
+ template <class Allocator , class SrcType , class DstType , class CountType >
220
220
class NarrowWideStringConverter
221
221
{
222
222
public:
223
223
static size_t Length (const SrcType& src);
224
224
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 );
226
226
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);
228
228
};
229
229
230
230
template <class Allocator >
231
- class NarrowWideStringConverter <Allocator, LPCSTR, LPWSTR>
231
+ class NarrowWideStringConverter <Allocator, LPCSTR, LPWSTR, charcount_t >
232
232
{
233
233
public:
234
234
// Note: Typically caller should pass in Utf8 string length. Following
@@ -240,23 +240,23 @@ namespace utf8
240
240
241
241
static HRESULT Convert (
242
242
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 )
244
244
{
245
245
return NarrowStringToWide<Allocator>(
246
246
sourceString, sourceCount, destStringPtr, destCount, allocateCount);
247
247
}
248
248
249
249
static HRESULT ConvertNoAlloc (
250
250
LPCSTR sourceString, size_t sourceCount,
251
- LPWSTR destStringPtr, size_t destCount, size_t * written)
251
+ LPWSTR destStringPtr, charcount_t destCount, charcount_t * written)
252
252
{
253
253
return NarrowStringToWideNoAlloc (
254
254
sourceString, sourceCount, destStringPtr, destCount, written);
255
255
}
256
256
};
257
257
258
258
template <class Allocator >
259
- class NarrowWideStringConverter <Allocator, LPCWSTR, LPSTR>
259
+ class NarrowWideStringConverter <Allocator, LPCWSTR, LPSTR, size_t >
260
260
{
261
261
public:
262
262
// Note: Typically caller should pass in WCHAR string length. Following
@@ -283,14 +283,14 @@ namespace utf8
283
283
}
284
284
};
285
285
286
- template <class Allocator , class SrcType , class DstType >
286
+ template <class Allocator , class SrcType , class DstType , class CountType >
287
287
class NarrowWideConverter
288
288
{
289
- typedef NarrowWideStringConverter<Allocator, SrcType, DstType>
289
+ typedef NarrowWideStringConverter<Allocator, SrcType, DstType, CountType >
290
290
StringConverter;
291
291
private:
292
292
DstType dst;
293
- size_t dstCount;
293
+ CountType dstCount;
294
294
size_t allocateCount;
295
295
bool freeDst;
296
296
@@ -347,6 +347,6 @@ namespace utf8
347
347
}
348
348
};
349
349
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;
352
352
}
0 commit comments