Merge pull request #50820 from raulsntos/fix-csharp-documentation

Fix documentation in StringExtensions
This commit is contained in:
Rémi Verschelde 2021-07-25 00:23:31 +02:00 committed by GitHub
commit cf8e9fd80c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,9 +61,9 @@ namespace Godot
return string.Empty; return string.Empty;
} }
// <summary> /// <summary>
// If the string is a path to a file, return the path to the file without the extension. /// If the string is a path to a file, return the path to the file without the extension.
// </summary> /// </summary>
public static string BaseName(this string instance) public static string BaseName(this string instance)
{ {
int index = instance.LastIndexOf('.'); int index = instance.LastIndexOf('.');
@ -74,17 +74,17 @@ namespace Godot
return instance; return instance;
} }
// <summary> /// <summary>
// Return true if the strings begins with the given string. /// Return <see langword="true"/> if the strings begins with the given string.
// </summary> /// </summary>
public static bool BeginsWith(this string instance, string text) public static bool BeginsWith(this string instance, string text)
{ {
return instance.StartsWith(text); return instance.StartsWith(text);
} }
// <summary> /// <summary>
// Return the bigrams (pairs of consecutive letters) of this string. /// Return the bigrams (pairs of consecutive letters) of this string.
// </summary> /// </summary>
public static string[] Bigrams(this string instance) public static string[] Bigrams(this string instance)
{ {
var b = new string[instance.Length - 1]; var b = new string[instance.Length - 1];
@ -127,9 +127,9 @@ namespace Godot
return sign * Convert.ToInt32(instance, 2); return sign * Convert.ToInt32(instance, 2);
} }
// <summary> /// <summary>
// Return the amount of substrings in string. /// Return the amount of substrings in string.
// </summary> /// </summary>
public static int Count(this string instance, string what, bool caseSensitive = true, int from = 0, int to = 0) public static int Count(this string instance, string what, bool caseSensitive = true, int from = 0, int to = 0)
{ {
if (what.Length == 0) if (what.Length == 0)
@ -187,9 +187,9 @@ namespace Godot
return c; return c;
} }
// <summary> /// <summary>
// Return a copy of the string with special characters escaped using the C language standard. /// Return a copy of the string with special characters escaped using the C language standard.
// </summary> /// </summary>
public static string CEscape(this string instance) public static string CEscape(this string instance)
{ {
var sb = new StringBuilder(string.Copy(instance)); var sb = new StringBuilder(string.Copy(instance));
@ -209,9 +209,10 @@ namespace Godot
return sb.ToString(); return sb.ToString();
} }
// <summary> /// <summary>
// Return a copy of the string with escaped characters replaced by their meanings according to the C language standard. /// Return a copy of the string with escaped characters replaced by their meanings
// </summary> /// according to the C language standard.
/// </summary>
public static string CUnescape(this string instance) public static string CUnescape(this string instance)
{ {
var sb = new StringBuilder(string.Copy(instance)); var sb = new StringBuilder(string.Copy(instance));
@ -231,9 +232,12 @@ namespace Godot
return sb.ToString(); return sb.ToString();
} }
// <summary> /// <summary>
// Change the case of some letters. Replace underscores with spaces, convert all letters to lowercase then capitalize first and every letter following the space character. For [code]capitalize camelCase mixed_with_underscores[/code] it will return [code]Capitalize Camelcase Mixed With Underscores[/code]. /// Change the case of some letters. Replace underscores with spaces, convert all letters
// </summary> /// to lowercase then capitalize first and every letter following the space character.
/// For <c>capitalize camelCase mixed_with_underscores</c> it will return
/// <c>Capitalize Camelcase Mixed With Underscores</c>.
/// </summary>
public static string Capitalize(this string instance) public static string Capitalize(this string instance)
{ {
string aux = instance.Replace("_", " ").ToLower(); string aux = instance.Replace("_", " ").ToLower();
@ -254,17 +258,17 @@ namespace Godot
return cap; return cap;
} }
// <summary> /// <summary>
// Perform a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. /// Perform a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater.
// </summary> /// </summary>
public static int CasecmpTo(this string instance, string to) public static int CasecmpTo(this string instance, string to)
{ {
return instance.CompareTo(to, caseSensitive: true); return instance.CompareTo(to, caseSensitive: true);
} }
// <summary> /// <summary>
// Perform a comparison to another string, return -1 if less, 0 if equal and +1 if greater. /// Perform a comparison to another string, return -1 if less, 0 if equal and +1 if greater.
// </summary> /// </summary>
public static int CompareTo(this string instance, string to, bool caseSensitive = true) public static int CompareTo(this string instance, string to, bool caseSensitive = true)
{ {
if (string.IsNullOrEmpty(instance)) if (string.IsNullOrEmpty(instance))
@ -316,25 +320,25 @@ namespace Godot
} }
} }
// <summary> /// <summary>
// Return true if the strings ends with the given string. /// Return <see langword="true"/> if the strings ends with the given string.
// </summary> /// </summary>
public static bool EndsWith(this string instance, string text) public static bool EndsWith(this string instance, string text)
{ {
return instance.EndsWith(text); return instance.EndsWith(text);
} }
// <summary> /// <summary>
// Erase [code]chars[/code] characters from the string starting from [code]pos[/code]. /// Erase <paramref name="chars"/> characters from the string starting from <paramref name="pos"/>.
// </summary> /// </summary>
public static void Erase(this StringBuilder instance, int pos, int chars) public static void Erase(this StringBuilder instance, int pos, int chars)
{ {
instance.Remove(pos, chars); instance.Remove(pos, chars);
} }
// <summary> /// <summary>
// If the string is a path to a file, return the extension. /// If the string is a path to a file, return the extension.
// </summary> /// </summary>
public static string Extension(this string instance) public static string Extension(this string instance)
{ {
int pos = instance.FindLast("."); int pos = instance.FindLast(".");
@ -345,14 +349,18 @@ namespace Godot
return instance.Substring(pos + 1); return instance.Substring(pos + 1);
} }
/// <summary>Find the first occurrence of a substring. Optionally, the search starting position can be passed.</summary> /// <summary>
/// Find the first occurrence of a substring. Optionally, the search starting position can be passed.
/// </summary>
/// <returns>The starting position of the substring, or -1 if not found.</returns> /// <returns>The starting position of the substring, or -1 if not found.</returns>
public static int Find(this string instance, string what, int from = 0, bool caseSensitive = true) public static int Find(this string instance, string what, int from = 0, bool caseSensitive = true)
{ {
return instance.IndexOf(what, from, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); return instance.IndexOf(what, from, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
} }
/// <summary>Find the first occurrence of a char. Optionally, the search starting position can be passed.</summary> /// <summary>
/// Find the first occurrence of a char. Optionally, the search starting position can be passed.
/// </summary>
/// <returns>The first instance of the char, or -1 if not found.</returns> /// <returns>The first instance of the char, or -1 if not found.</returns>
public static int Find(this string instance, char what, int from = 0, bool caseSensitive = true) public static int Find(this string instance, char what, int from = 0, bool caseSensitive = true)
{ {
@ -375,16 +383,19 @@ namespace Godot
return instance.LastIndexOf(what, from, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); return instance.LastIndexOf(what, from, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);
} }
/// <summary>Find the first occurrence of a substring but search as case-insensitive. Optionally, the search starting position can be passed.</summary> /// <summary>
/// Find the first occurrence of a substring but search as case-insensitive.
/// Optionally, the search starting position can be passed.
/// </summary>
/// <returns>The starting position of the substring, or -1 if not found.</returns> /// <returns>The starting position of the substring, or -1 if not found.</returns>
public static int FindN(this string instance, string what, int from = 0) public static int FindN(this string instance, string what, int from = 0)
{ {
return instance.IndexOf(what, from, StringComparison.OrdinalIgnoreCase); return instance.IndexOf(what, from, StringComparison.OrdinalIgnoreCase);
} }
// <summary> /// <summary>
// If the string is a path to a file, return the base directory. /// If the string is a path to a file, return the base directory.
// </summary> /// </summary>
public static string GetBaseDir(this string instance) public static string GetBaseDir(this string instance)
{ {
int basepos = instance.Find("://"); int basepos = instance.Find("://");
@ -419,9 +430,9 @@ namespace Godot
return @base + rs.Substr(0, sep); return @base + rs.Substr(0, sep);
} }
// <summary> /// <summary>
// If the string is a path to a file, return the file and ignore the base directory. /// If the string is a path to a file, return the file and ignore the base directory.
// </summary> /// </summary>
public static string GetFile(this string instance) public static string GetFile(this string instance)
{ {
int sep = Mathf.Max(instance.FindLast("/"), instance.FindLast("\\")); int sep = Mathf.Max(instance.FindLast("/"), instance.FindLast("\\"));
@ -461,9 +472,9 @@ namespace Godot
return Encoding.UTF8.GetString(bytes); return Encoding.UTF8.GetString(bytes);
} }
// <summary> /// <summary>
// Hash the string and return a 32 bits unsigned integer. /// Hash the string and return a 32 bits unsigned integer.
// </summary> /// </summary>
public static uint Hash(this string instance) public static uint Hash(this string instance)
{ {
uint hash = 5381; uint hash = 5381;
@ -553,17 +564,17 @@ namespace Godot
return sign * int.Parse(instance, NumberStyles.HexNumber); return sign * int.Parse(instance, NumberStyles.HexNumber);
} }
// <summary> /// <summary>
// Insert a substring at a given position. /// Insert a substring at a given position.
// </summary> /// </summary>
public static string Insert(this string instance, int pos, string what) public static string Insert(this string instance, int pos, string what)
{ {
return instance.Insert(pos, what); return instance.Insert(pos, what);
} }
// <summary> /// <summary>
// If the string is a path to a file or directory, return true if the path is absolute. /// If the string is a path to a file or directory, return <see langword="true"/> if the path is absolute.
// </summary> /// </summary>
public static bool IsAbsPath(this string instance) public static bool IsAbsPath(this string instance)
{ {
if (string.IsNullOrEmpty(instance)) if (string.IsNullOrEmpty(instance))
@ -574,17 +585,17 @@ namespace Godot
return instance[0] == '/' || instance[0] == '\\'; return instance[0] == '/' || instance[0] == '\\';
} }
// <summary> /// <summary>
// If the string is a path to a file or directory, return true if the path is relative. /// If the string is a path to a file or directory, return <see langword="true"/> if the path is relative.
// </summary> /// </summary>
public static bool IsRelPath(this string instance) public static bool IsRelPath(this string instance)
{ {
return !IsAbsPath(instance); return !IsAbsPath(instance);
} }
// <summary> /// <summary>
// Check whether this string is a subsequence of the given string. /// Check whether this string is a subsequence of the given string.
// </summary> /// </summary>
public static bool IsSubsequenceOf(this string instance, string text, bool caseSensitive = true) public static bool IsSubsequenceOf(this string instance, string text, bool caseSensitive = true)
{ {
int len = instance.Length; int len = instance.Length;
@ -625,34 +636,36 @@ namespace Godot
return false; return false;
} }
// <summary> /// <summary>
// Check whether this string is a subsequence of the given string, ignoring case differences. /// Check whether this string is a subsequence of the given string, ignoring case differences.
// </summary> /// </summary>
public static bool IsSubsequenceOfI(this string instance, string text) public static bool IsSubsequenceOfI(this string instance, string text)
{ {
return instance.IsSubsequenceOf(text, caseSensitive: false); return instance.IsSubsequenceOf(text, caseSensitive: false);
} }
// <summary> /// <summary>
// Check whether the string contains a valid float. /// Check whether the string contains a valid <see langword="float"/>.
// </summary> /// </summary>
public static bool IsValidFloat(this string instance) public static bool IsValidFloat(this string instance)
{ {
float f; float f;
return float.TryParse(instance, out f); return float.TryParse(instance, out f);
} }
// <summary> /// <summary>
// Check whether the string contains a valid color in HTML notation. /// Check whether the string contains a valid color in HTML notation.
// </summary> /// </summary>
public static bool IsValidHtmlColor(this string instance) public static bool IsValidHtmlColor(this string instance)
{ {
return Color.HtmlIsValid(instance); return Color.HtmlIsValid(instance);
} }
// <summary> /// <summary>
// Check whether the string is a valid identifier. As is common in programming languages, a valid identifier may contain only letters, digits and underscores (_) and the first character may not be a digit. /// Check whether the string is a valid identifier. As is common in
// </summary> /// programming languages, a valid identifier may contain only letters,
/// digits and underscores (_) and the first character may not be a digit.
/// </summary>
public static bool IsValidIdentifier(this string instance) public static bool IsValidIdentifier(this string instance)
{ {
int len = instance.Length; int len = instance.Length;
@ -680,18 +693,18 @@ namespace Godot
return true; return true;
} }
// <summary> /// <summary>
// Check whether the string contains a valid integer. /// Check whether the string contains a valid integer.
// </summary> /// </summary>
public static bool IsValidInteger(this string instance) public static bool IsValidInteger(this string instance)
{ {
int f; int f;
return int.TryParse(instance, out f); return int.TryParse(instance, out f);
} }
// <summary> /// <summary>
// Check whether the string contains a valid IP address. /// Check whether the string contains a valid IP address.
// </summary> /// </summary>
public static bool IsValidIPAddress(this string instance) public static bool IsValidIPAddress(this string instance)
{ {
// TODO: Support IPv6 addresses // TODO: Support IPv6 addresses
@ -714,9 +727,9 @@ namespace Godot
return true; return true;
} }
// <summary> /// <summary>
// Return a copy of the string with special characters escaped using the JSON standard. /// Return a copy of the string with special characters escaped using the JSON standard.
// </summary> /// </summary>
public static string JSONEscape(this string instance) public static string JSONEscape(this string instance)
{ {
var sb = new StringBuilder(string.Copy(instance)); var sb = new StringBuilder(string.Copy(instance));
@ -733,9 +746,9 @@ namespace Godot
return sb.ToString(); return sb.ToString();
} }
// <summary> /// <summary>
// Return an amount of characters from the left of the string. /// Return an amount of characters from the left of the string.
// </summary> /// </summary>
public static string Left(this string instance, int pos) public static string Left(this string instance, int pos)
{ {
if (pos <= 0) if (pos <= 0)
@ -783,7 +796,8 @@ namespace Godot
} }
/// <summary> /// <summary>
/// Do a simple expression match, where '*' matches zero or more arbitrary characters and '?' matches any single character except '.'. /// Do a simple expression match, where '*' matches zero or more
/// arbitrary characters and '?' matches any single character except '.'.
/// </summary> /// </summary>
private static bool ExprMatch(this string instance, string expr, bool caseSensitive) private static bool ExprMatch(this string instance, string expr, bool caseSensitive)
{ {
@ -807,7 +821,8 @@ namespace Godot
} }
/// <summary> /// <summary>
/// Do a simple case sensitive expression match, using ? and * wildcards (see [method expr_match]). /// Do a simple case sensitive expression match, using ? and * wildcards
/// (see <see cref="ExprMatch(string, string, bool)"/>).
/// </summary> /// </summary>
public static bool Match(this string instance, string expr, bool caseSensitive = true) public static bool Match(this string instance, string expr, bool caseSensitive = true)
{ {
@ -818,7 +833,8 @@ namespace Godot
} }
/// <summary> /// <summary>
/// Do a simple case insensitive expression match, using ? and * wildcards (see [method expr_match]). /// Do a simple case insensitive expression match, using ? and * wildcards
/// (see <see cref="ExprMatch(string, string, bool)"/>).
/// </summary> /// </summary>
public static bool MatchN(this string instance, string expr) public static bool MatchN(this string instance, string expr)
{ {
@ -828,9 +844,9 @@ namespace Godot
return instance.ExprMatch(expr, caseSensitive: false); return instance.ExprMatch(expr, caseSensitive: false);
} }
// <summary> /// <summary>
// Return the MD5 hash of the string as an array of bytes. /// Return the MD5 hash of the string as an array of bytes.
// </summary> /// </summary>
public static byte[] MD5Buffer(this string instance) public static byte[] MD5Buffer(this string instance)
{ {
return godot_icall_String_md5_buffer(instance); return godot_icall_String_md5_buffer(instance);
@ -839,9 +855,9 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static byte[] godot_icall_String_md5_buffer(string str); internal extern static byte[] godot_icall_String_md5_buffer(string str);
// <summary> /// <summary>
// Return the MD5 hash of the string as a string. /// Return the MD5 hash of the string as a string.
// </summary> /// </summary>
public static string MD5Text(this string instance) public static string MD5Text(this string instance)
{ {
return godot_icall_String_md5_text(instance); return godot_icall_String_md5_text(instance);
@ -850,25 +866,25 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static string godot_icall_String_md5_text(string str); internal extern static string godot_icall_String_md5_text(string str);
// <summary> /// <summary>
// Perform a case-insensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. /// Perform a case-insensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater.
// </summary> /// </summary>
public static int NocasecmpTo(this string instance, string to) public static int NocasecmpTo(this string instance, string to)
{ {
return instance.CompareTo(to, caseSensitive: false); return instance.CompareTo(to, caseSensitive: false);
} }
// <summary> /// <summary>
// Return the character code at position [code]at[/code]. /// Return the character code at position <paramref name="at"/>.
// </summary> /// </summary>
public static int OrdAt(this string instance, int at) public static int OrdAt(this string instance, int at)
{ {
return instance[at]; return instance[at];
} }
// <summary> /// <summary>
// Format a number to have an exact number of [code]digits[/code] after the decimal point. /// Format a number to have an exact number of <paramref name="digits"/> after the decimal point.
// </summary> /// </summary>
public static string PadDecimals(this string instance, int digits) public static string PadDecimals(this string instance, int digits)
{ {
int c = instance.Find("."); int c = instance.Find(".");
@ -902,9 +918,9 @@ namespace Godot
return instance; return instance;
} }
// <summary> /// <summary>
// Format a number to have an exact number of [code]digits[/code] before the decimal point. /// Format a number to have an exact number of <paramref name="digits"/> before the decimal point.
// </summary> /// </summary>
public static string PadZeros(this string instance, int digits) public static string PadZeros(this string instance, int digits)
{ {
string s = instance; string s = instance;
@ -935,9 +951,10 @@ namespace Godot
return s; return s;
} }
// <summary> /// <summary>
// If the string is a path, this concatenates [code]file[/code] at the end of the string as a subpath. E.g. [code]"this/is".plus_file("path") == "this/is/path"[/code]. /// If the string is a path, this concatenates <paramref name="file"/> at the end of the string as a subpath.
// </summary> /// E.g. <c>"this/is".PlusFile("path") == "this/is/path"</c>.
/// </summary>
public static string PlusFile(this string instance, string file) public static string PlusFile(this string instance, string file)
{ {
if (instance.Length > 0 && instance[instance.Length - 1] == '/') if (instance.Length > 0 && instance[instance.Length - 1] == '/')
@ -945,25 +962,25 @@ namespace Godot
return instance + "/" + file; return instance + "/" + file;
} }
// <summary> /// <summary>
// Replace occurrences of a substring for different ones inside the string. /// Replace occurrences of a substring for different ones inside the string.
// </summary> /// </summary>
public static string Replace(this string instance, string what, string forwhat) public static string Replace(this string instance, string what, string forwhat)
{ {
return instance.Replace(what, forwhat); return instance.Replace(what, forwhat);
} }
// <summary> /// <summary>
// Replace occurrences of a substring for different ones inside the string, but search case-insensitive. /// Replace occurrences of a substring for different ones inside the string, but search case-insensitive.
// </summary> /// </summary>
public static string ReplaceN(this string instance, string what, string forwhat) public static string ReplaceN(this string instance, string what, string forwhat)
{ {
return Regex.Replace(instance, what, forwhat, RegexOptions.IgnoreCase); return Regex.Replace(instance, what, forwhat, RegexOptions.IgnoreCase);
} }
// <summary> /// <summary>
// Perform a search for a substring, but start from the end of the string instead of the beginning. /// Perform a search for a substring, but start from the end of the string instead of the beginning.
// </summary> /// </summary>
public static int RFind(this string instance, string what, int from = -1) public static int RFind(this string instance, string what, int from = -1)
{ {
return godot_icall_String_rfind(instance, what, from); return godot_icall_String_rfind(instance, what, from);
@ -972,9 +989,10 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static int godot_icall_String_rfind(string str, string what, int from); internal extern static int godot_icall_String_rfind(string str, string what, int from);
// <summary> /// <summary>
// Perform a search for a substring, but start from the end of the string instead of the beginning. Also search case-insensitive. /// Perform a search for a substring, but start from the end of the string instead of the beginning.
// </summary> /// Also search case-insensitive.
/// </summary>
public static int RFindN(this string instance, string what, int from = -1) public static int RFindN(this string instance, string what, int from = -1)
{ {
return godot_icall_String_rfindn(instance, what, from); return godot_icall_String_rfindn(instance, what, from);
@ -983,9 +1001,9 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static int godot_icall_String_rfindn(string str, string what, int from); internal extern static int godot_icall_String_rfindn(string str, string what, int from);
// <summary> /// <summary>
// Return the right side of the string from a given position. /// Return the right side of the string from a given position.
// </summary> /// </summary>
public static string Right(this string instance, int pos) public static string Right(this string instance, int pos)
{ {
if (pos >= instance.Length) if (pos >= instance.Length)
@ -1032,9 +1050,9 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static byte[] godot_icall_String_sha256_buffer(string str); internal extern static byte[] godot_icall_String_sha256_buffer(string str);
// <summary> /// <summary>
// Return the SHA-256 hash of the string as a string. /// Return the SHA-256 hash of the string as a string.
// </summary> /// </summary>
public static string SHA256Text(this string instance) public static string SHA256Text(this string instance)
{ {
return godot_icall_String_sha256_text(instance); return godot_icall_String_sha256_text(instance);
@ -1043,9 +1061,10 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)] [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static string godot_icall_String_sha256_text(string str); internal extern static string godot_icall_String_sha256_text(string str);
// <summary> /// <summary>
// Return the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar. /// Return the similarity index of the text compared to this string.
// </summary> /// 1 means totally similar and 0 means totally dissimilar.
/// </summary>
public static float Similarity(this string instance, string text) public static float Similarity(this string instance, string text)
{ {
if (instance == text) if (instance == text)
@ -1083,17 +1102,19 @@ namespace Godot
return 2.0f * inter / sum; return 2.0f * inter / sum;
} }
// <summary> /// <summary>
// Split the string by a divisor string, return an array of the substrings. Example "One,Two,Three" will return ["One","Two","Three"] if split by ",". /// Split the string by a divisor string, return an array of the substrings.
// </summary> /// Example "One,Two,Three" will return ["One","Two","Three"] if split by ",".
/// </summary>
public static string[] Split(this string instance, string divisor, bool allowEmpty = true) public static string[] Split(this string instance, string divisor, bool allowEmpty = true)
{ {
return instance.Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries); return instance.Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
} }
// <summary> /// <summary>
// Split the string in floats by using a divisor string, return an array of the substrings. Example "1,2.5,3" will return [1,2.5,3] if split by ",". /// Split the string in floats by using a divisor string, return an array of the substrings.
// </summary> /// Example "1,2.5,3" will return [1,2.5,3] if split by ",".
/// </summary>
public static float[] SplitFloats(this string instance, string divisor, bool allowEmpty = true) public static float[] SplitFloats(this string instance, string divisor, bool allowEmpty = true)
{ {
var ret = new List<float>(); var ret = new List<float>();
@ -1125,9 +1146,10 @@ namespace Godot
(char)30, (char)31, (char)32 (char)30, (char)31, (char)32
}; };
// <summary> /// <summary>
// Return a copy of the string stripped of any non-printable character at the beginning and the end. The optional arguments are used to toggle stripping on the left and right edges respectively. /// Return a copy of the string stripped of any non-printable character at the beginning and the end.
// </summary> /// The optional arguments are used to toggle stripping on the left and right edges respectively.
/// </summary>
public static string StripEdges(this string instance, bool left = true, bool right = true) public static string StripEdges(this string instance, bool left = true, bool right = true)
{ {
if (left) if (left)
@ -1140,58 +1162,62 @@ namespace Godot
return instance.TrimEnd(_nonPrintable); return instance.TrimEnd(_nonPrintable);
} }
// <summary> /// <summary>
// Return part of the string from the position [code]from[/code], with length [code]len[/code]. /// Return part of the string from the position <paramref name="from"/>, with length <paramref name="len"/>.
// </summary> /// </summary>
public static string Substr(this string instance, int from, int len) public static string Substr(this string instance, int from, int len)
{ {
int max = instance.Length - from; int max = instance.Length - from;
return instance.Substring(from, len > max ? max : len); return instance.Substring(from, len > max ? max : len);
} }
// <summary> /// <summary>
// Convert the String (which is a character array) to PackedByteArray (which is an array of bytes). The conversion is speeded up in comparison to to_utf8() with the assumption that all the characters the String contains are only ASCII characters. /// Convert the String (which is a character array) to PackedByteArray (which is an array of bytes).
// </summary> /// The conversion is speeded up in comparison to <see cref="ToUTF8(string)"/> with the assumption
/// that all the characters the String contains are only ASCII characters.
/// </summary>
public static byte[] ToAscii(this string instance) public static byte[] ToAscii(this string instance)
{ {
return Encoding.ASCII.GetBytes(instance); return Encoding.ASCII.GetBytes(instance);
} }
// <summary> /// <summary>
// Convert a string, containing a decimal number, into a [code]float[/code]. /// Convert a string, containing a decimal number, into a <see langword="float" />.
// </summary> /// </summary>
public static float ToFloat(this string instance) public static float ToFloat(this string instance)
{ {
return float.Parse(instance); return float.Parse(instance);
} }
// <summary> /// <summary>
// Convert a string, containing an integer number, into an [code]int[/code]. /// Convert a string, containing an integer number, into an <see langword="int" />.
// </summary> /// </summary>
public static int ToInt(this string instance) public static int ToInt(this string instance)
{ {
return int.Parse(instance); return int.Parse(instance);
} }
// <summary> /// <summary>
// Return the string converted to lowercase. /// Return the string converted to lowercase.
// </summary> /// </summary>
public static string ToLower(this string instance) public static string ToLower(this string instance)
{ {
return instance.ToLower(); return instance.ToLower();
} }
// <summary> /// <summary>
// Return the string converted to uppercase. /// Return the string converted to uppercase.
// </summary> /// </summary>
public static string ToUpper(this string instance) public static string ToUpper(this string instance)
{ {
return instance.ToUpper(); return instance.ToUpper();
} }
// <summary> /// <summary>
// Convert the String (which is an array of characters) to PackedByteArray (which is an array of bytes). The conversion is a bit slower than to_ascii(), but supports all UTF-8 characters. Therefore, you should prefer this function over to_ascii(). /// Convert the String (which is an array of characters) to PackedByteArray (which is an array of bytes).
// </summary> /// The conversion is a bit slower than <see cref="ToAscii(string)"/>, but supports all UTF-8 characters.
/// Therefore, you should prefer this function over <see cref="ToAscii(string)"/>.
/// </summary>
public static byte[] ToUTF8(this string instance) public static byte[] ToUTF8(this string instance)
{ {
return Encoding.UTF8.GetBytes(instance); return Encoding.UTF8.GetBytes(instance);
@ -1224,17 +1250,18 @@ namespace Godot
return Uri.EscapeDataString(instance); return Uri.EscapeDataString(instance);
} }
// <summary> /// <summary>
// Return a copy of the string with special characters escaped using the XML standard. /// Return a copy of the string with special characters escaped using the XML standard.
// </summary> /// </summary>
public static string XMLEscape(this string instance) public static string XMLEscape(this string instance)
{ {
return SecurityElement.Escape(instance); return SecurityElement.Escape(instance);
} }
// <summary> /// <summary>
// Return a copy of the string with escaped characters replaced by their meanings according to the XML standard. /// Return a copy of the string with escaped characters replaced by their meanings
// </summary> /// according to the XML standard.
/// </summary>
public static string XMLUnescape(this string instance) public static string XMLUnescape(this string instance)
{ {
return SecurityElement.FromString(instance).Text; return SecurityElement.FromString(instance).Text;