internal class Normalization
{
- internal static bool IsNormalized(String strInput, NormalizationForm normForm)
+ internal static bool IsNormalized(String strInput, NormalizationForm normalizationForm)
{
if (GlobalizationMode.Invariant)
{
// The only way to know if IsNormalizedString failed is through checking the Win32 last error
// IsNormalizedString pinvoke has SetLastError attribute property which will set the last error
// to 0 (ERROR_SUCCESS) before executing the calls.
- bool result = Interop.Normaliz.IsNormalizedString((int)normForm, strInput, strInput.Length);
+ bool result = Interop.Normaliz.IsNormalizedString((int)normalizationForm, strInput, strInput.Length);
int lastError = Marshal.GetLastWin32Error();
switch (lastError)
case Interop.Errors.ERROR_INVALID_PARAMETER:
case Interop.Errors.ERROR_NO_UNICODE_TRANSLATION:
+ if (!Enum.IsDefined(typeof(NormalizationForm), normalizationForm))
+ {
+ throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
+ }
+
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
case Interop.Errors.ERROR_NOT_ENOUGH_MEMORY:
return result;
}
- internal static String Normalize(String strInput, NormalizationForm normForm)
+ internal static String Normalize(String strInput, NormalizationForm normalizationForm)
{
if (GlobalizationMode.Invariant)
{
// to 0 (ERROR_SUCCESS) before executing the calls.
// Guess our buffer size first
- int iLength = Interop.Normaliz.NormalizeString((int)normForm, strInput, strInput.Length, null, 0);
+ int iLength = Interop.Normaliz.NormalizeString((int)normalizationForm, strInput, strInput.Length, null, 0);
int lastError = Marshal.GetLastWin32Error();
// Could have an error (actually it'd be quite hard to have an error here)
if ((lastError != Interop.Errors.ERROR_SUCCESS) || iLength < 0)
{
if (lastError == Interop.Errors.ERROR_INVALID_PARAMETER)
+ {
+ if (!Enum.IsDefined(typeof(NormalizationForm), normalizationForm))
+ {
+ throw new ArgumentException(SR.Argument_InvalidNormalizationForm, nameof(normalizationForm));
+ }
+
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
+ }
// We shouldn't really be able to get here..., guessing length is
// a trivial math function...
// NormalizeString pinvoke has SetLastError attribute property which will set the last error
// to 0 (ERROR_SUCCESS) before executing the calls.
- iLength = Interop.Normaliz.NormalizeString((int)normForm, strInput, strInput.Length, cBuffer, cBuffer.Length);
+ iLength = Interop.Normaliz.NormalizeString((int)normalizationForm, strInput, strInput.Length, cBuffer, cBuffer.Length);
lastError = Marshal.GetLastWin32Error();
if (lastError == Interop.Errors.ERROR_SUCCESS)