From d9ed44a12fb63f9639cb3e87c6910b815c416101 Mon Sep 17 00:00:00 2001 From: Kaoticz <1812311+Kaoticz@users.noreply.github.com> Date: Thu, 23 May 2024 20:59:19 -0300 Subject: [PATCH] Added char extension methods. --- Kotz.Extensions/CharExt.cs | 362 +++++++++++++++++++++++++++++++ Kotz.Extensions/KotzUtilities.cs | 6 - Kotz.Extensions/README.md | 2 + 3 files changed, 364 insertions(+), 6 deletions(-) create mode 100644 Kotz.Extensions/CharExt.cs diff --git a/Kotz.Extensions/CharExt.cs b/Kotz.Extensions/CharExt.cs new file mode 100644 index 0000000..95e1ef8 --- /dev/null +++ b/Kotz.Extensions/CharExt.cs @@ -0,0 +1,362 @@ +using System.Globalization; + +namespace Kotz.Extensions; + +/// +/// Provides extension methods for static methods. +/// +public static class CharExt +{ + /// + /// Converts the current Unicode code point into a UTF-16 encoded string. + /// + /// This character. + /// + /// A string consisting of one char object or a surrogate pair of char + /// objects equivalent to the code point specified by the UTF-32 parameter. + /// + /// + public static string ConvertFromUtf32(this char character) + => char.ConvertFromUtf32(character); + + /// + /// Converts the current numeric Unicode character to a double-precision floating point + /// number. + /// + /// This character. + /// The numeric value if this character represents a number; otherwise, "-1.0". + public static double GetNumericValue(this char character) + => char.GetNumericValue(character); + + /// + /// Categorizes the current Unicode character into a group identified by one of the + /// UnicodeCategory values. + /// + /// This character. + /// A UnicodeCategory value that identifies the group of this character. + public static UnicodeCategory GetUnicodeCategory(this char character) + => char.GetUnicodeCategory(character); + + /// + /// Returns true if this character is an ASCII character ([ U+0000..U+007F ]). + /// + /// This character. + /// + /// if this character is an ASCII character, + /// otherwise. + /// + public static bool IsAscii(this char character) + => char.IsAscii(character); + + /// + /// Indicates whether this character is categorized as an ASCII digit. + /// + /// This character. + /// + /// if this character is an ASCII digit, + /// otherwise. + /// + public static bool IsAsciiDigit(this char character) + => char.IsAsciiDigit(character); + + /// + /// Indicates whether this character is categorized as an ASCII hexadecimal digit. + /// + /// This character. + /// + /// if this character is an ASCII hexadecimal digit, + /// otherwise. + /// + public static bool IsAsciiHexDigit(this char character) + => char.IsAsciiHexDigit(character); + + /// + /// Indicates whether this character is categorized as an ASCII lower-case hexadecimal digit. + /// + /// This character. + /// + /// if this character is a lower-case hexadecimal digit, + /// otherwise. + /// + public static bool IsAsciiHexDigitLower(this char character) + => char.IsAsciiHexDigitLower(character); + + /// + /// Indicates whether this character is categorized as an ASCII upper-case hexadecimal digit. + /// + /// This character. + /// + /// if this character is a hexadecimal digit, + /// otherwise. + /// + public static bool IsAsciiHexDigitUpper(this char character) + => char.IsAsciiHexDigitUpper(character); + + /// + /// Indicates whether this character is categorized as an ASCII letter. + /// + /// This character. + /// + /// if this character is an ASCII letter, + /// otherwise. + /// + public static bool IsAsciiLetter(this char character) + => char.IsAsciiLetter(character); + + /// + /// Indicates whether this character is categorized as a lowercase ASCII letter. + /// + /// This character. + /// + /// if this character is a lowercase ASCII letter, + /// otherwise. + /// + public static bool IsAsciiLetterLower(this char character) + => char.IsAsciiLetterLower(character); + + /// + /// Indicates whether this character is categorized as an ASCII letter or digit. + /// + /// This character. + /// + /// if this character is an ASCII letter or digit, + /// otherwise. + /// + public static bool IsAsciiLetterOrDigit(this char character) + => char.IsAsciiLetterOrDigit(character); + + /// + /// Indicates whether this character is categorized as an uppercase ASCII letter. + /// + /// This character. + /// + /// if this character is an uppercase ASCII letter, + /// otherwise. + /// + public static bool IsAsciiLetterUpper(this char character) + => char.IsAsciiLetterUpper(character); + + /// + /// Indicates whether this character is within the specified inclusive range. + /// + /// This character. + /// The lower bound, inclusive. + /// The upper bound, inclusive. + /// + /// if this character is within the specified range, + /// otherwise. + /// + public static bool IsBetween(this char character, char minInclusive, char maxInclusive) + => char.IsBetween(character, minInclusive, maxInclusive); + + /// + /// Indicates whether this character is categorized as a control character. + /// + /// This character. + /// + /// if this character is a control character, + /// otherwise. + /// + public static bool IsControl(this char character) + => char.IsControl(character); + + /// + /// Indicates whether this character is categorized as a decimal digit. + /// + /// This character. + /// + /// if this character is a decimal digit, + /// otherwise. + /// + public static bool IsDigit(this char character) + => char.IsDigit(character); + + /// + /// Indicates whether this character is a high surrogate. + /// + /// This character. + /// + /// if the numeric value of this character parameter ranges from + /// U+D800 through U+DBFF, otherwise. + /// + public static bool IsHighSurrogate(this char character) + => char.IsHighSurrogate(character); + + /// + /// Indicates whether this character is categorized as a letter. + /// + /// This character. + /// if this character is a letter, otherwise. + public static bool IsLetter(this char character) + => char.IsLetter(character); + + /// + /// Indicates whether this character is categorized as a letter or a decimal digit. + /// + /// This character. + /// + /// if this character is a letter or a decimal digit, + /// otherwise. + /// + public static bool IsLetterOrDigit(this char character) + => char.IsLetterOrDigit(character); + + /// + /// Indicates whether this character is categorized as a lowercase letter. + /// + /// This character. + /// if this character is a lowercase letter, otherwise. + public static bool IsLower(this char character) + => char.IsLower(character); + + /// + /// Indicates whether this character is a low surrogate. + /// + /// This character. + /// + /// if the numeric value of this character ranges from + /// U+DC00 through U+DFFF, otherwise. + /// + public static bool IsLowSurrogate(this char character) + => char.IsLowSurrogate(character); + + /// + /// Indicates whether this character is categorized as a number. + /// + /// This character. + /// if this character is a number, otherwise. + public static bool IsNumber(this char character) + => char.IsNumber(character); + + /// + /// Indicates whether this character is categorized as a punctuation mark. + /// + /// This character. + /// + /// if this character is a punctuation mark, + /// otherwise. + /// + public static bool IsPunctuation(this char character) + => char.IsPunctuation(character); + + /// + /// Indicates whether this character is categorized as a separator character. + /// + /// This character. + /// + /// if this character is a separator character, + /// otherwise. + /// + public static bool IsSeparator(this char character) + => char.IsSeparator(character); + + /// + /// Indicates whether this character has a surrogate code unit. + /// + /// This character. + /// + /// if this character is either a high surrogate + /// or a low surrogate, otherwise. + /// + public static bool IsSurrogate(this char character) + => char.IsSurrogate(character); + + /// + /// Indicates whether this character is categorized as a symbol character. + /// + /// This character. + /// if this character is a symbol character, otherwise. + public static bool IsSymbol(this char character) + => char.IsSymbol(character); + + /// + /// Indicates whether this character is categorized as an uppercase letter. + /// + /// This character. + /// if this character is an uppercase letter, otherwise. + public static bool IsUpper(this char character) + => char.IsUpper(character); + + /// + /// Indicates whether this character is categorized as white space. + /// + /// This character. + /// if this character is white space, otherwise. + public static bool IsWhiteSpace(this char character) + => char.IsWhiteSpace(character); + + /// + /// Converts the value of this character to its lowercase equivalent. + /// + /// This character. + /// + /// The lowercase equivalent of this character, or the same character unchanged, + /// if the character is already lowercase or not alphabetic. + /// + public static char ToLower(this char character) + => char.ToLower(character); + + /// + /// Converts the value of this character to its lowercase equivalent using the specified + /// culture-specific formatting information. + /// + /// This character. + /// The culture-specific casing rules. + /// + /// The lowercase equivalent of this character, modified according to culture, or the + /// unchanged value of the character if it's already lowercase or not alphabetic. + /// + /// + public static char ToLower(this char character, CultureInfo culture) + => char.ToLower(character, culture); + + /// + /// Converts the value of this character to its lowercase equivalent using the casing + /// rules of the invariant culture. + /// + /// This character. + /// + /// The lowercase equivalent of this character, or the unchanged value of the character + /// if it's already lowercase or not alphabetic. + /// + public static char ToLowerInvariant(this char character) + => char.ToLowerInvariant(character); + + /// + /// Converts the value of this character to its uppercase equivalent. + /// + /// This character. + /// + /// The uppercase equivalent of this character, or the unchanged value of the character + /// if it's already uppercase, has no uppercase equivalent, or is not alphabetic. + /// + public static char ToUpper(this char character) + => char.ToUpper(character); + + /// + /// Converts the value of this character to its uppercase equivalent using the specified + /// culture-specific formatting information. + /// + /// This character. + /// The culture-specific casing rules. + /// + /// The uppercase equivalent of this character, modified according to culture, or the + /// unchanged value of the character if it's already uppercase, has no uppercase + /// equivalent, or is not alphabetic. + /// + /// + public static char ToUpper(this char character, CultureInfo culture) + => char.ToUpper(character, culture); + + /// + /// Converts the value of this character to its uppercase equivalent using the casing + /// rules of the invariant culture. + /// + /// This character. + /// + /// The uppercase equivalent of this character, or the unchanged value of the character + /// if it's already uppercase or not alphabetic. + /// + public static char ToUpperInvariant(this char character) + => char.ToUpperInvariant(character); +} \ No newline at end of file diff --git a/Kotz.Extensions/KotzUtilities.cs b/Kotz.Extensions/KotzUtilities.cs index a0c4613..1e36b05 100644 --- a/Kotz.Extensions/KotzUtilities.cs +++ b/Kotz.Extensions/KotzUtilities.cs @@ -95,7 +95,6 @@ public static bool ProgramExists(string programName) return process.ExitCode is 0; } - /// /// Starts the specified program in the background. /// @@ -218,11 +217,6 @@ public static bool TryCreate(Func factory, [MaybeNullWhen(false)] out T re /// if the File System Object was deleted, otherwise. /// /// - /// - /// - /// - /// - /// public static bool TryDeleteFSO(string fsoUri, bool isRecursive = true) => TryDeleteFile(fsoUri) || TryDeleteDirectory(fsoUri, isRecursive); diff --git a/Kotz.Extensions/README.md b/Kotz.Extensions/README.md index c397ec7..db2cd53 100644 --- a/Kotz.Extensions/README.md +++ b/Kotz.Extensions/README.md @@ -9,6 +9,8 @@ Defines the following extension methods: - GetAbstractTypes: Gets all abstract types from the current assembly. - GetConcreteTypesOf: Gets the concrete types from the current assembly that derive from another type. - GetAbstractTypesOf: Gets the abstract types from the current assembly that derive from another type. +- **Char Extensions** + - Several wrappers for `System.Char` static methods. - **DateTimeOffset Extensions** - StartOfDay: Gets the beginning of the day for the current DateTimeOffset object. - **Enum Extensions**