本文整理汇总了C#中NormalizationForm类的典型用法代码示例。如果您正苦于以下问题:C# NormalizationForm类的具体用法?C# NormalizationForm怎么用?C# NormalizationForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NormalizationForm类属于命名空间,在下文中一共展示了NormalizationForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsNormalized
public static bool IsNormalized(this string value, NormalizationForm normalizationForm)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
Contract.EndContractBlock();
// The only way to know if IsNormalizedString failed is through checking the Win32 last error
Interop.mincore.SetLastError(Interop.ERROR_SUCCESS);
bool result = Interop.mincore.IsNormalizedString((int)normalizationForm, value, value.Length);
int lastError = Marshal.GetLastWin32Error();
switch (lastError)
{
case Interop.ERROR_SUCCESS:
case Interop.LAST_ERROR_TRASH_VALUE:
break;
case Interop.ERROR_INVALID_PARAMETER:
case Interop.ERROR_NO_UNICODE_TRANSLATION:
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(value));
case Interop.ERROR_NOT_ENOUGH_MEMORY:
throw new OutOfMemoryException(SR.Arg_OutOfMemoryException);
default:
throw new InvalidOperationException(SR.Format(SR.UnknownError_Num, lastError));
}
return result;
}
示例2: InitializeForm
[System.Security.SecurityCritical] // auto-generated
static private unsafe void InitializeForm(NormalizationForm form, String strDataFile)
{
#if FEATURE_COREFX_GLOBALIZATION
//TODO: Implement this fully. We might need a PAL here.
throw new NotImplementedException();
#else
byte* pTables = null;
// Normalization uses OS on Win8
if (!Environment.IsWindows8OrAbove)
{
if (strDataFile == null)
{
// They were supposed to have a form that we know about!
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidNormalizationForm"));
}
// Tell the DLL where to find our data
pTables = GlobalizationAssembly.GetGlobalizationResourceBytePtr(
typeof(Normalization).Assembly, strDataFile);
if (pTables == null)
{
// Unable to load the specified normalizationForm,
// tables not loaded from file
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidNormalizationForm"));
}
}
nativeNormalizationInitNormalization(form, pTables);
#endif
}
示例3: IsAlwaysNormalized
public override bool IsAlwaysNormalized (NormalizationForm form)
{
if (form != NormalizationForm.FormC)
return false;
if (isNormalized == null)
isNormalized = new byte [0x10000 / 8];
if (isNormalizedComputed == null)
isNormalizedComputed = new byte [0x10000 / 8];
if (normalization_bytes == null) {
normalization_bytes = new byte [0x100];
lock (normalization_bytes) {
for (int i = 0; i < 0x100; i++)
normalization_bytes [i] = (byte) i;
}
}
byte offset = (byte) (1 << (CodePage % 8));
if ((isNormalizedComputed [CodePage / 8] & offset) == 0) {
Encoding e = Clone () as Encoding;
e.DecoderFallback = new DecoderReplacementFallback ("");
string s = e.GetString (normalization_bytes);
// note that the flag only stores FormC information.
if (s != s.Normalize (form))
isNormalized [CodePage / 8] |= offset;
isNormalizedComputed [CodePage / 8] |= offset;
}
return (isNormalized [CodePage / 8] & offset) == 0;
}
示例4: InitializeForm
static private unsafe void InitializeForm(NormalizationForm form, String strDataFile)
{
byte* pTables = null;
// Normalization uses OS on Win8
if (!Environment.IsWindows8OrAbove)
{
if (strDataFile == null)
{
// They were supposed to have a form that we know about!
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidNormalizationForm"));
}
// Tell the DLL where to find our data
pTables = GlobalizationAssembly.GetGlobalizationResourceBytePtr(
typeof(Normalization).Assembly, strDataFile);
if (pTables == null)
{
// Unable to load the specified normalizationForm,
// tables not loaded from file
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidNormalizationForm"));
}
}
nativeNormalizationInitNormalization(form, pTables);
}
示例5: Normalize
public static String Normalize(this string value, NormalizationForm normalizationForm)
{
if (value == null)
throw new ArgumentNullException (nameof (value));
return value.Normalize (normalizationForm);
}
示例6: Normalize
public static string Normalize(this string strInput, NormalizationForm normalizationForm)
{
ValidateArguments(strInput, normalizationForm);
char[] buf = new char[strInput.Length];
for (int attempts = 2; attempts > 0; attempts--)
{
int realLen = Interop.GlobalizationNative.NormalizeString(normalizationForm, strInput, strInput.Length, buf, buf.Length);
if (realLen == -1)
{
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
}
if (realLen <= buf.Length)
{
return new string(buf, 0, realLen);
}
buf = new char[realLen];
}
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
}
示例7: ClearForNormalize
public static string ClearForNormalize(this string value, NormalizationForm form)
{
if (!string.IsNullOrEmpty(value))
{
value = value.Replace(":", ""); // removed for solr
value = value.Replace("ø", "o");
var sb = new StringBuilder();
foreach (var c in value.Normalize(form))
switch (CharUnicodeInfo.GetUnicodeCategory(c))
{
case UnicodeCategory.NonSpacingMark:
case UnicodeCategory.SpacingCombiningMark:
case UnicodeCategory.EnclosingMark:
break;
default:
sb.Append(c);
break;
}
return sb.ToString().ToLower();
}
return string.Empty;
}
示例8: Normalization
internal unsafe Normalization(NormalizationForm form, String strDataFile)
{
// Remember which form we are
this.normalizationForm = form;
// Load the DLL
if (!nativeLoadNormalizationDLL())
{
// Unable to load the normalization DLL!
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidNormalizationForm"));
}
// Tell the DLL where to find our data
byte* pTables = GlobalizationAssembly.GetGlobalizationResourceBytePtr(
typeof(Normalization).Assembly, strDataFile);
if (pTables == null)
{
// Unable to load the specified normalizationForm,
// tables not loaded from file
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidNormalizationForm"));
}
// All we have to do is let the .dll know how to load it, then
// we can ignore the returned pointer.
byte* objNorm = nativeNormalizationInitNormalization(form, pTables);
if (objNorm == null)
{
// Unable to load the specified normalizationForm
// native library class not initialized correctly
throw new OutOfMemoryException(
Environment.GetResourceString("Arg_OutOfMemoryException"));
}
}
示例9: Normalize
public void Normalize(string value, NormalizationForm normalizationForm, string expected)
{
if (normalizationForm == NormalizationForm.FormC)
{
Assert.Equal(expected, value.Normalize());
}
Assert.Equal(expected, value.Normalize(normalizationForm));
}
示例10: IsNormalized
public void IsNormalized(string value, NormalizationForm normalizationForm, bool expected)
{
if (normalizationForm == NormalizationForm.FormC)
{
Assert.Equal(expected, value.IsNormalized());
}
Assert.Equal(expected, value.IsNormalized(normalizationForm));
}
示例11: Normalize
public static string Normalize(this string value, NormalizationForm normalizationForm)
{
if (IsNormalized(value, normalizationForm))
{
return value;
}
throw NotImplemented.ByDesign;
}
示例12: Normalize
public static string Normalize(this string strInput, NormalizationForm normalizationForm)
{
if (strInput == null)
{
throw new ArgumentNullException(nameof(strInput));
}
return strInput.Normalize(normalizationForm);
}
示例13: IsNormalized
public static bool IsNormalized(this string value, NormalizationForm normalizationForm)
{
for (int i = 0; i < value.Length; i++)
{
if (value[i] > 0x7F)
{
throw NotImplemented.ByDesign;
}
}
return true;
}
示例14: IsNormalized
public static bool IsNormalized(this string value, NormalizationForm normalizationForm)
{
ValidateArguments(value, normalizationForm);
int ret = Interop.GlobalizationNative.IsNormalized(normalizationForm, value, value.Length);
if (ret == -1)
{
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, "value");
}
return ret == 1;
}
示例15: IsNormalized
public static bool IsNormalized(this string strInput, NormalizationForm normalizationForm)
{
ValidateArguments(strInput, normalizationForm);
int ret = Interop.GlobalizationInterop.IsNormalized(normalizationForm, strInput, strInput.Length);
if (ret == -1)
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"), nameof(strInput));
}
return ret == 1;
}