/// <summary> /// RuleBasedCollator constructor. /// This takes the table rules and builds a collation table out of them. /// </summary> /// <param name="rules">the collation rules to build the collation table from</param> /// <param name="normalizationMode">the normalization mode to use</param> /// <param name="collationStrength">the collation strength to use</param> public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; var parseError = new ParseError(); _collatorHandle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref parseError, out status); try { ExceptionFromErrorCode.ThrowIfError(status, parseError.ToString(rules)); } catch { if (_collatorHandle != default(SafeRuleBasedCollatorHandle)) { _collatorHandle.Dispose(); } _collatorHandle = default(SafeRuleBasedCollatorHandle); throw; } }
/// <summary> /// RuleBasedCollator constructor. /// This takes the table rules and builds a collation table out of them. /// </summary> /// <param name="rules">the collation rules to build the collation table from</param> /// <param name="normalizationMode">the normalization mode to use</param> /// <param name="collationStrength">the collation strength to use</param> public RuleBasedCollator(string rules, NormalizationMode normalizationMode, CollationStrength collationStrength) { ErrorCode status; collatorHandle = NativeMethods.ucol_openRules(rules, rules.Length, normalizationMode, collationStrength, ref parseError, out status); ExceptionFromErrorCode.ThrowIfError(status, parseError.ToString(rules)); }
/// <summary> /// Implementing IDisposable pattern to properly release unmanaged resources. /// </summary> protected override void Dispose(bool disposing) { if (!_disposingValue) { if (disposing) { // Dispose managed state (managed objects), if any. // although SafeRuleBasedCollatorHandle deals with an unmanaged resource // it itself is a managed object, so we shouldn't try to dispose it // if !disposing because that could lead to a corrupt stack (as observed // in https://jenkins.lsdev.sil.org:45192/view/Icu/view/All/job/GitHub-IcuDotNet-Win-any-master-release/59) if (_collatorHandle != default(SafeRuleBasedCollatorHandle)) { _collatorHandle.Dispose(); } } _collatorHandle = default(SafeRuleBasedCollatorHandle); _disposingValue = true; } }