Class DefaultShortStringHelper
New default implementation of string functions for short strings such as aliases or URL segments.
Inheritance
Namespace: Umbraco.Cms.Core.Strings
Assembly: Umbraco.Core.dll
Syntax
public class DefaultShortStringHelper : IShortStringHelper
Remarks
Not optimized to work on large bodies of text.
Meant to replace LegacyShortStringHelper where/when backward compatibility is not an issue.
NOTE: pre-filters run _before_ the string is re-encoded.
Constructors
View SourceDefaultShortStringHelper(IOptions<RequestHandlerSettings>)
Initializes a new instance of the DefaultShortStringHelper class using request handler settings.
Declaration
public DefaultShortStringHelper(IOptions<RequestHandlerSettings> settings)
Parameters
| Type | Name | Description |
|---|---|---|
| IOptions<RequestHandlerSettings> | settings | The request handler settings containing character replacement rules. |
DefaultShortStringHelper(DefaultShortStringHelperConfig)
Initializes a new instance of the DefaultShortStringHelper class using a custom configuration.
Declaration
public DefaultShortStringHelper(DefaultShortStringHelperConfig config)
Parameters
| Type | Name | Description |
|---|---|---|
| DefaultShortStringHelperConfig | config | The configuration to use. The configuration is cloned to prevent runtime modification. |
Methods
View SourceCleanString(string, CleanStringType)
Cleans a string.
Declaration
public string CleanString(string text, CleanStringType stringType)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to clean. |
| CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
Returns
| Type | Description |
|---|---|
| string | The clean string. |
Remarks
The string is cleaned in the context of the default culture.
CleanString(string, CleanStringType, char)
Cleans a string, using a specified separator.
Declaration
public string CleanString(string text, CleanStringType stringType, char separator)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to clean. |
| CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
| char | separator | The separator. |
Returns
| Type | Description |
|---|---|
| string | The clean string. |
Remarks
The string is cleaned in the context of the default culture.
CleanString(string, CleanStringType, char, string)
Cleans a string in the context of a specified culture, using a specified separator.
Declaration
public string CleanString(string text, CleanStringType stringType, char separator, string culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to clean. |
| CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
| char | separator | The separator. |
| string | culture | The culture. |
Returns
| Type | Description |
|---|---|
| string | The clean string. |
CleanString(string, CleanStringType, string?)
Cleans a string in the context of a specified culture.
Declaration
public string CleanString(string text, CleanStringType stringType, string? culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to clean. |
| CleanStringType | stringType | A flag indicating the target casing and encoding of the string. By default, strings are cleaned up to camelCase and Ascii. |
| string | culture | The culture. |
Returns
| Type | Description |
|---|---|
| string | The clean string. |
CleanString(string, CleanStringType, string?, char?)
Cleans a string according to the specified string type, culture, and separator.
Declaration
protected virtual string CleanString(string text, CleanStringType stringType, string? culture, char? separator)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to clean. |
| CleanStringType | stringType | The type of cleaning to perform. |
| string | culture | The culture to use for casing. |
| char? | separator | The separator character to use between terms. |
Returns
| Type | Description |
|---|---|
| string | The cleaned string. |
CleanStringForSafeAlias(string)
Cleans a string to produce a string that can safely be used in an alias.
Declaration
public virtual string CleanStringForSafeAlias(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to filter. |
Returns
| Type | Description |
|---|---|
| string | The safe alias. |
Remarks
The string will be cleaned in the context of the default culture.
Safe aliases are Ascii only.
CleanStringForSafeAlias(string, string)
Cleans a string, in the context of a specified culture, to produce a string that can safely be used in an alias.
Declaration
public virtual string CleanStringForSafeAlias(string text, string culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to filter. |
| string | culture | The culture. |
Returns
| Type | Description |
|---|---|
| string | The safe alias. |
Remarks
Safe aliases are Ascii only.
CleanStringForSafeFileName(string)
Cleans a string, in the context of the default culture, to produce a string that can safely be used as a filename, both internally (on disk) and externally (as a URL).
Declaration
public virtual string CleanStringForSafeFileName(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to filter. |
Returns
| Type | Description |
|---|---|
| string | The safe filename. |
Remarks
Legacy says this was used to "overcome an issue when Umbraco is used in IE in an intranet environment" but that issue is not documented.
CleanStringForSafeFileName(string, string)
Cleans a string to produce a string that can safely be used as a filename, both internally (on disk) and externally (as a URL).
Declaration
public virtual string CleanStringForSafeFileName(string text, string culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to filter. |
| string | culture | The culture. |
Returns
| Type | Description |
|---|---|
| string | The safe filename. |
CleanStringForUrlSegment(string)
Cleans a string to produce a string that can safely be used in an URL segment.
Declaration
public virtual string CleanStringForUrlSegment(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to filter. |
Returns
| Type | Description |
|---|---|
| string | The safe URL segment. |
Remarks
The string will be cleaned in the context of the default culture.
Url segments are Ascii only (no accents...).
CleanStringForUrlSegment(string, string?)
Cleans a string, in the context of a specified culture, to produce a string that can safely be used in an URL segment.
Declaration
public virtual string CleanStringForUrlSegment(string text, string? culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to filter. |
| string | culture | The culture. |
Returns
| Type | Description |
|---|---|
| string | The safe URL segment. |
Remarks
Url segments are Ascii only (no accents...).
IsValidFileNameChar(char)
Determines whether a character is valid for use in a file name.
Declaration
public static bool IsValidFileNameChar(char c)
Parameters
| Type | Name | Description |
|---|---|---|
| char | c | The character to test. |
Returns
| Type | Description |
|---|---|
| bool |
|
SplitPascalCasing(string, char)
Splits a Pascal-cased string into a phrase separated by a separator.
Declaration
public virtual string SplitPascalCasing(string text, char separator)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to split. |
| char | separator | The separator, which defaults to a whitespace. |
Returns
| Type | Description |
|---|---|
| string | The split text. |
Remarks
Supports Utf8 and Ascii strings, not Unicode strings.