From 93d7d0961310d746ccf9137c218a0d25eaa3dbab Mon Sep 17 00:00:00 2001 From: tombogle Date: Wed, 6 Dec 2023 15:37:37 -0500 Subject: [PATCH] Update changelog to prepare for v13.0.0 release Minor refactoring/cleanup in StringExtensions.cs and slight performance tweak to GetLongestUsefulCommonSubstring --- CHANGELOG.md | 5 ++++- SIL.Core/Extensions/StringExtensions.cs | 21 ++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 325b1d569..9d56a6151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [13.0.0] - 2023-12-07 + ### Added - [SIL.Core] `RobustFile.Open`, `RobustFile.AppendAllText`, `RobustFile.WriteAllLines`, `RobustFile.GetAccessControl`, `RobustIO.EnumerateFilesInDirectory`, `RobustIO.EnumerateDirectoriesInDirectory`, `RobustIO.EnumerateEntriesInDirectory`, `RobustIO.RequireThatDirectoryExists`, `RobustIO.GetFileStream`, `RobustIO.ReadAllTextFromFileWhichMightGetWrittenTo`, and `RobustIO.IsFileLocked` methods @@ -360,7 +362,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [SIL.NUnit3Compatibility] new project/package that allows to use NUnit3 syntax with NUnit2 projects -[Unreleased]: https://github.com/sillsdev/libpalaso/compare/v12.0.1...master +[Unreleased]: https://github.com/sillsdev/libpalaso/compare/v13.0.0...master +[13.0.0]: https://github.com/sillsdev/libpalaso/compare/v12.0.1...v13.0.0 [12.0.1]: https://github.com/sillsdev/libpalaso/compare/v12.0.0...v12.0.1 [12.0.0]: https://github.com/sillsdev/libpalaso/compare/v11.0.1...v12.0.0 [11.0.1]: https://github.com/sillsdev/libpalaso/compare/v11.0.0...v11.0.1 diff --git a/SIL.Core/Extensions/StringExtensions.cs b/SIL.Core/Extensions/StringExtensions.cs index e02575000..e1bae56ef 100644 --- a/SIL.Core/Extensions/StringExtensions.cs +++ b/SIL.Core/Extensions/StringExtensions.cs @@ -56,8 +56,7 @@ public static int[] ToIntArray(this string str) string[] pieces = str.Split(','); foreach (string piece in pieces) { - int i; - if (int.TryParse(piece, out i)) + if (int.TryParse(piece, out var i)) array.Add(i); } } @@ -84,7 +83,7 @@ public static string FormatWithErrorStringInsteadOfException(this string format, argList = argList + arg + ","; } - argList = argList.Trim(new char[] { ',' }); + argList = argList.Trim(','); return "FormatWithErrorStringInsteadOfException(" + format + "," + argList + ") Exception: " + e.Message; } @@ -112,7 +111,7 @@ public static string EscapeAnyUnicodeCharactersIllegalInXml(this string text) return text.Normalize(NormalizationForm.FormC); } - private static object _lockUsedForEscaping = new object(); + private static readonly object _lockUsedForEscaping = new object(); private static StringBuilder _bldrUsedForEscaping; private static XmlWriterSettings _settingsUsedForEscaping; private static XmlWriter _writerUsedForEscaping; @@ -458,19 +457,15 @@ public static string GetLongestUsefulCommonSubstring(this string s1, string s2, cchMatch += IsSurrogate(s1[ich + cchMatch]) ? 2: 1; } while (s1.IsLikelyWordForming(ich + cchMatch)); - //if (cchMatch > maxLength) - //{ - // ich += cchMatch; - // continue; - //} - string candidate = s1.Substring(ich, cchMatch); - int ichOrc = candidate.IndexOf(kszObject, StringComparison.Ordinal); + int ichOrc = s1.IndexOf(kszObject, ich, cchMatch, StringComparison.Ordinal); if (ichOrc >= 0) { ich += ichOrc; continue; } + string candidate = s1.Substring(ich, cchMatch); + int ichMatch = 0; do { @@ -489,8 +484,6 @@ public static string GetLongestUsefulCommonSubstring(this string s1, string s2, else if (!IsWhiteSpace(ch)) candidate = s1.Substring(ich, cchMatch + 1); // include punctuation cchMatch += incr; - //if (cchMatch > maxLength) - // break; } else { @@ -499,8 +492,6 @@ public static string GetLongestUsefulCommonSubstring(this string s1, string s2, cchMatch += IsSurrogate(s1[ich + cchMatch]) ? 2: 1; } while (s1.IsLikelyWordForming(ich + cchMatch)); - //if (cchMatch > maxLength) - // break; candidate = s1.Substring(ich, cchMatch); } } while (true);