V10: Fix build warnings in core (#12438)
* Run code cleanup * Start manual cleanup after dotnet format * Finish up manual pass * Fix up missed warnings * Fix after merge * Update src/Umbraco.Core/Cache/ContentTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DataTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DeepCloneAppCache.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DomainCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MacroCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MediaCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberGroupCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/OrderedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/SetCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/WeightedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Dashboards/DashboardCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DataTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentUnpublishingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DomainCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/LanguageCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MacroCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptiedRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptyingRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/ShadowWrapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Logging/DisposableTimer.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Install/InstallSteps/UpgradeStep.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Mapping/MapDefinitionCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StatefulNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/DeepCloneHelper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/File.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review * Fix after merge Signed-off-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Extensions;
|
||||
@@ -143,9 +140,11 @@ namespace Umbraco.Cms.Core.Strings
|
||||
public virtual string CleanStringForSafeFileName(string text, string culture)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
culture = culture ?? "";
|
||||
culture = culture ?? string.Empty;
|
||||
text = text.ReplaceMany(Path.GetInvalidFileNameChars(), '-');
|
||||
|
||||
var name = Path.GetFileNameWithoutExtension(text);
|
||||
@@ -153,12 +152,17 @@ namespace Umbraco.Cms.Core.Strings
|
||||
|
||||
Debug.Assert(name != null, "name != null");
|
||||
if (name.Length > 0)
|
||||
{
|
||||
name = CleanString(name, CleanStringType.FileName, culture);
|
||||
}
|
||||
|
||||
Debug.Assert(ext != null, "ext != null");
|
||||
if (ext.Length > 0)
|
||||
{
|
||||
ext = CleanString(ext.Substring(1), CleanStringType.FileName, culture);
|
||||
}
|
||||
|
||||
return ext.Length > 0 ? (name + "." + ext) : name;
|
||||
return ext.Length > 0 ? name + "." + ext : name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -190,10 +194,7 @@ namespace Umbraco.Cms.Core.Strings
|
||||
/// strings are cleaned up to camelCase and Ascii.</param>
|
||||
/// <returns>The clean string.</returns>
|
||||
/// <remarks>The string is cleaned in the context of the default culture.</remarks>
|
||||
public string CleanString(string text, CleanStringType stringType)
|
||||
{
|
||||
return CleanString(text, stringType, _config.DefaultCulture, null);
|
||||
}
|
||||
public string CleanString(string text, CleanStringType stringType) => CleanString(text, stringType, _config.DefaultCulture, null);
|
||||
|
||||
/// <summary>
|
||||
/// Cleans a string, using a specified separator.
|
||||
@@ -204,10 +205,7 @@ namespace Umbraco.Cms.Core.Strings
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <returns>The clean string.</returns>
|
||||
/// <remarks>The string is cleaned in the context of the default culture.</remarks>
|
||||
public string CleanString(string text, CleanStringType stringType, char separator)
|
||||
{
|
||||
return CleanString(text, stringType, _config.DefaultCulture, separator);
|
||||
}
|
||||
public string CleanString(string text, CleanStringType stringType, char separator) => CleanString(text, stringType, _config.DefaultCulture, separator);
|
||||
|
||||
/// <summary>
|
||||
/// Cleans a string in the context of a specified culture.
|
||||
@@ -239,32 +237,43 @@ namespace Umbraco.Cms.Core.Strings
|
||||
protected virtual string CleanString(string text, CleanStringType stringType, string? culture, char? separator)
|
||||
{
|
||||
// be safe
|
||||
if (text == null) throw new ArgumentNullException(nameof(text));
|
||||
culture = culture ?? "";
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
culture = culture ?? string.Empty;
|
||||
|
||||
// get config
|
||||
var config = _config.For(stringType, culture);
|
||||
DefaultShortStringHelperConfig.Config config = _config.For(stringType, culture);
|
||||
stringType = config.StringTypeExtend(stringType);
|
||||
|
||||
// apply defaults
|
||||
if ((stringType & CleanStringType.CaseMask) == CleanStringType.None)
|
||||
{
|
||||
stringType |= CleanStringType.CamelCase;
|
||||
}
|
||||
|
||||
if ((stringType & CleanStringType.CodeMask) == CleanStringType.None)
|
||||
{
|
||||
stringType |= CleanStringType.Ascii;
|
||||
}
|
||||
|
||||
// use configured unless specified
|
||||
separator = separator ?? config.Separator;
|
||||
|
||||
// apply pre-filter
|
||||
if (config.PreFilter != null)
|
||||
{
|
||||
text = config.PreFilter(text);
|
||||
}
|
||||
|
||||
// apply replacements
|
||||
//if (config.Replacements != null)
|
||||
// text = ReplaceMany(text, config.Replacements);
|
||||
|
||||
// recode
|
||||
var codeType = stringType & CleanStringType.CodeMask;
|
||||
CleanStringType codeType = stringType & CleanStringType.CodeMask;
|
||||
switch (codeType)
|
||||
{
|
||||
case CleanStringType.Ascii:
|
||||
@@ -273,7 +282,11 @@ namespace Umbraco.Cms.Core.Strings
|
||||
case CleanStringType.TryAscii:
|
||||
const char ESC = (char) 27;
|
||||
var ctext = Utf8ToAsciiConverter.ToAsciiString(text, ESC);
|
||||
if (ctext.Contains(ESC) == false) text = ctext;
|
||||
if (ctext.Contains(ESC) == false)
|
||||
{
|
||||
text = ctext;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
text = RemoveSurrogatePairs(text);
|
||||
@@ -285,7 +298,9 @@ namespace Umbraco.Cms.Core.Strings
|
||||
|
||||
// apply post-filter
|
||||
if (config.PostFilter != null)
|
||||
{
|
||||
text = config.PostFilter(text);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
@@ -323,7 +338,7 @@ namespace Umbraco.Cms.Core.Strings
|
||||
int opos = 0, ipos = 0;
|
||||
var state = StateBreak;
|
||||
|
||||
culture = culture ?? "";
|
||||
culture = culture ?? string.Empty;
|
||||
caseType &= CleanStringType.CaseMask;
|
||||
|
||||
// if we apply global ToUpper or ToLower to text here
|
||||
@@ -364,9 +379,13 @@ namespace Umbraco.Cms.Core.Strings
|
||||
{
|
||||
ipos = i;
|
||||
if (opos > 0 && separator != char.MinValue)
|
||||
{
|
||||
output[opos++] = separator;
|
||||
}
|
||||
|
||||
state = isUpper ? StateUp : StateWord;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// within a term / word
|
||||
@@ -379,8 +398,11 @@ namespace Umbraco.Cms.Core.Strings
|
||||
ipos = i;
|
||||
state = isTerm ? StateUp : StateBreak;
|
||||
if (state != StateBreak && separator != char.MinValue)
|
||||
{
|
||||
output[opos++] = separator;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// within a term / acronym
|
||||
@@ -391,14 +413,19 @@ namespace Umbraco.Cms.Core.Strings
|
||||
{
|
||||
// whether it's part of the acronym depends on whether we're greedy
|
||||
if (isTerm && config.GreedyAcronyms == false)
|
||||
{
|
||||
i -= 1; // handle that char again, in another state - not part of the acronym
|
||||
}
|
||||
|
||||
if (i - ipos > 1) // single-char can't be an acronym
|
||||
{
|
||||
CopyTerm(input, ipos, output, ref opos, i - ipos, caseType, culture, true);
|
||||
ipos = i;
|
||||
state = isTerm ? StateWord : StateBreak;
|
||||
if (state != StateBreak && separator != char.MinValue)
|
||||
{
|
||||
output[opos++] = separator;
|
||||
}
|
||||
}
|
||||
else if (isTerm)
|
||||
{
|
||||
@@ -411,6 +438,7 @@ namespace Umbraco.Cms.Core.Strings
|
||||
// keep moving forward as a word
|
||||
state = StateWord;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// within a term / uppercase = could be a word or an acronym
|
||||
@@ -455,18 +483,19 @@ namespace Umbraco.Cms.Core.Strings
|
||||
}
|
||||
|
||||
// note: supports surrogate pairs in input string
|
||||
internal void CopyTerm(string input, int ipos, char[] output, ref int opos, int len,
|
||||
CleanStringType caseType, string culture, bool isAcronym)
|
||||
internal void CopyTerm(string input, int ipos, char[] output, ref int opos, int len, CleanStringType caseType, string culture, bool isAcronym)
|
||||
{
|
||||
var term = input.Substring(ipos, len);
|
||||
var cultureInfo = string.IsNullOrEmpty(culture) ? CultureInfo.InvariantCulture : CultureInfo.GetCultureInfo(culture);
|
||||
CultureInfo cultureInfo = string.IsNullOrEmpty(culture) ? CultureInfo.InvariantCulture : CultureInfo.GetCultureInfo(culture);
|
||||
|
||||
if (isAcronym)
|
||||
{
|
||||
if ((caseType == CleanStringType.CamelCase && len <= 2 && opos > 0) ||
|
||||
(caseType == CleanStringType.PascalCase && len <= 2) ||
|
||||
(caseType == CleanStringType.UmbracoCase))
|
||||
caseType == CleanStringType.UmbracoCase)
|
||||
{
|
||||
caseType = CleanStringType.Unchanged;
|
||||
}
|
||||
}
|
||||
|
||||
// note: MSDN seems to imply that ToUpper or ToLower preserve the length
|
||||
@@ -586,7 +615,9 @@ namespace Umbraco.Cms.Core.Strings
|
||||
{
|
||||
// be safe
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
var input = text.ToCharArray();
|
||||
var output = new char[input.Length * 2];
|
||||
@@ -603,7 +634,10 @@ namespace Umbraco.Cms.Core.Strings
|
||||
if (upos == 0)
|
||||
{
|
||||
if (opos > 0)
|
||||
{
|
||||
output[opos++] = separator;
|
||||
}
|
||||
|
||||
upos = i + 1;
|
||||
}
|
||||
}
|
||||
@@ -612,15 +646,24 @@ namespace Umbraco.Cms.Core.Strings
|
||||
if (upos > 0)
|
||||
{
|
||||
if (upos < i && opos > 0)
|
||||
{
|
||||
output[opos++] = separator;
|
||||
}
|
||||
|
||||
upos = 0;
|
||||
}
|
||||
|
||||
output[opos++] = a;
|
||||
}
|
||||
|
||||
a = c;
|
||||
}
|
||||
|
||||
if (a != char.MinValue)
|
||||
{
|
||||
output[opos++] = a;
|
||||
}
|
||||
|
||||
return new string(output, 0, opos);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user