@@ -13,8 +13,8 @@ namespace utf8
13
13
// / using Allocator.
14
14
// / The returned string is null terminated.
15
15
// /
16
- template <class Allocator >
17
- HRESULT WideStringToNarrow (_In_ LPCWSTR sourceString, size_t sourceCount, _Out_ LPSTR* destStringPtr, _Out_ size_t * destCount)
16
+ template <typename AllocatorFunction >
17
+ HRESULT WideStringToNarrow (_In_ AllocatorFunction allocator, _In_ LPCWSTR sourceString, size_t sourceCount, _Out_ LPSTR* destStringPtr, _Out_ size_t * destCount)
18
18
{
19
19
size_t cchSourceString = sourceCount;
20
20
@@ -31,7 +31,7 @@ namespace utf8
31
31
return E_OUTOFMEMORY;
32
32
}
33
33
34
- utf8char_t * destString = (utf8char_t *)Allocator::allocate (cbDestString);
34
+ utf8char_t * destString = (utf8char_t *)allocator (cbDestString);
35
35
if (destString == nullptr )
36
36
{
37
37
return E_OUTOFMEMORY;
@@ -45,14 +45,20 @@ namespace utf8
45
45
return S_OK;
46
46
}
47
47
48
+ template <class Allocator >
49
+ HRESULT WideStringToNarrow (_In_ LPCWSTR sourceString, size_t sourceCount, _Out_ LPSTR* destStringPtr, _Out_ size_t * destCount)
50
+ {
51
+ return WideStringToNarrow (Allocator::allocate, sourceString, sourceCount, destStringPtr, destCount);
52
+ }
53
+
48
54
// /
49
55
// / Use the codex library to encode a UTF8 string to UTF16.
50
56
// / The caller is responsible for freeing the memory, which is allocated
51
57
// / using Allocator.
52
58
// / The returned string is null terminated.
53
59
// /
54
- template <class Allocator >
55
- HRESULT NarrowStringToWide (_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t * destCount)
60
+ template <typename AllocatorFunction >
61
+ HRESULT NarrowStringToWide (_In_ AllocatorFunction allocator,_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t * destCount)
56
62
{
57
63
size_t cbSourceString = sourceCount;
58
64
charcount_t cchDestString = utf8::ByteIndexIntoCharacterIndex ((LPCUTF8) sourceString, cbSourceString);
@@ -64,14 +70,14 @@ namespace utf8
64
70
return E_OUTOFMEMORY;
65
71
}
66
72
67
- WCHAR* destString = (WCHAR*)Allocator::allocate (cbDestString);
73
+ WCHAR* destString = (WCHAR*)allocator (cbDestString);
68
74
if (destString == nullptr )
69
75
{
70
76
return E_OUTOFMEMORY;
71
77
}
72
78
73
79
// Some node tests depend on the utf8 decoder not swallowing invalid unicode characters
74
- // instead of replacing them with the "replacement" chracter . Pass a flag to our
80
+ // instead of replacing them with the "replacement" character . Pass a flag to our
75
81
// decoder to require such behavior
76
82
utf8::DecodeUnitsIntoAndNullTerminateNoAdvance (destString, (LPCUTF8) sourceString, (LPCUTF8) sourceString + cbSourceString, DecodeOptions::doAllowInvalidWCHARs);
77
83
Assert (destString[cchDestString] == 0 );
@@ -81,6 +87,12 @@ namespace utf8
81
87
return S_OK;
82
88
}
83
89
90
+ template <class Allocator >
91
+ HRESULT NarrowStringToWide (_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t * destCount)
92
+ {
93
+ return NarrowStringToWide (Allocator::allocate, sourceString, sourceCount, destStringPtr, destCount);
94
+ }
95
+
84
96
class malloc_allocator
85
97
{
86
98
public:
0 commit comments