#include <map>
#include "icushim.h"
+#include "locale.hpp"
+#include "errors.h"
const int32_t CompareOptionsIgnoreCase = 0x1;
const int32_t CompareOptionsIgnoreNonSpace = 0x2;
return UCOL_RUNTIME_VERSION << 16 | UCOL_BUILDER_VERSION;
}
-extern "C" SortHandle* GlobalizationNative_GetSortHandle(const char* lpLocaleName)
+extern "C" ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle)
{
- SortHandle* pSortHandle = new SortHandle();
+ assert(ppSortHandle != nullptr);
+
+ *ppSortHandle = new (std::nothrow) SortHandle();
+ if ((*ppSortHandle) == nullptr)
+ {
+ return GetResultCode(U_MEMORY_ALLOCATION_ERROR);
+ }
UErrorCode err = U_ZERO_ERROR;
- pSortHandle->regular = ucol_open(lpLocaleName, &err);
+ (*ppSortHandle)->regular = ucol_open(lpLocaleName, &err);
if (U_FAILURE(err))
{
- if (pSortHandle->regular != nullptr)
- ucol_close(pSortHandle->regular);
+ if ((*ppSortHandle)->regular != nullptr)
+ ucol_close((*ppSortHandle)->regular);
- delete pSortHandle;
- pSortHandle = nullptr;
+ delete (*ppSortHandle);
+ (*ppSortHandle) = nullptr;
}
- return pSortHandle;
+ return GetResultCode(err);
}
extern "C" void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle)
{
[SecurityCritical]
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortHandle")]
- internal unsafe static extern SafeSortHandle GetSortHandle(byte[] localeName);
+ internal unsafe static extern ResultCode GetSortHandle(byte[] localeName, out SafeSortHandle sortHandle);
[SecurityCritical]
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CloseSortHandle")]
get { return Environment.GetResourceString("Arg_ArrayZeroError"); }
}
+ public static string Arg_ExternalException
+ {
+ get { return Environment.GetResourceString("Arg_ExternalException"); }
+ }
+
public static string Arg_HexStyleNotSupported
{
get { return Environment.GetResourceString("Arg_HexStyleNotSupported"); }
private void InitSort(CultureInfo culture)
{
_sortName = culture.SortName;
- _sortHandle = Interop.GlobalizationInterop.GetSortHandle(GetNullTerminatedUtf8String(_sortName));
+ Interop.GlobalizationInterop.ResultCode resultCode = Interop.GlobalizationInterop.GetSortHandle(GetNullTerminatedUtf8String(_sortName), out _sortHandle);
+ if (resultCode != Interop.GlobalizationInterop.ResultCode.Success)
+ {
+ _sortHandle.Dispose();
+
+ if (resultCode == Interop.GlobalizationInterop.ResultCode.OutOfMemory)
+ throw new OutOfMemoryException();
+
+ throw new ExternalException(SR.Arg_ExternalException);
+ }
_isAsciiEqualityOrdinal = (_sortName == "en-US" || _sortName == "");
}