diff options
Diffstat (limited to 'modules/mono/glue')
13 files changed, 48 insertions, 38 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 772209064c..c29a0f2bd8 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Runtime.InteropServices; using Godot.NativeInterop; @@ -776,11 +777,11 @@ namespace Godot private static bool FindNamedColor(string name, out Color color) { - name = name.Replace(" ", string.Empty); - name = name.Replace("-", string.Empty); - name = name.Replace("_", string.Empty); - name = name.Replace("'", string.Empty); - name = name.Replace(".", string.Empty); + name = name.Replace(" ", string.Empty, StringComparison.Ordinal); + name = name.Replace("-", string.Empty, StringComparison.Ordinal); + name = name.Replace("_", string.Empty, StringComparison.Ordinal); + name = name.Replace("'", string.Empty, StringComparison.Ordinal); + name = name.Replace(".", string.Empty, StringComparison.Ordinal); name = name.ToUpperInvariant(); return Colors.namedColors.TryGetValue(name, out color); @@ -1329,7 +1330,9 @@ namespace Godot /// <returns>A string representation of this color.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({R.ToString(format)}, {G.ToString(format)}, {B.ToString(format)}, {A.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs index ab2e0a78b9..fc6e7a3ebe 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; @@ -698,7 +699,7 @@ namespace Godot case GodotObject godotObject: return VariantUtils.CreateFrom(godotObject); case Enum @enum: - return VariantUtils.CreateFrom(Convert.ToInt64(@enum)); + return VariantUtils.CreateFrom(Convert.ToInt64(@enum, CultureInfo.InvariantCulture)); case Collections.IGenericGodotDictionary godotDictionary: return VariantUtils.CreateFrom(godotDictionary.UnderlyingDictionary); case Collections.IGenericGodotArray godotArray: @@ -777,7 +778,7 @@ namespace Godot return func(variant); if (typeof(GodotObject).IsAssignableFrom(type)) - return Convert.ChangeType(VariantUtils.ConvertTo<GodotObject>(variant), type); + return Convert.ChangeType(VariantUtils.ConvertTo<GodotObject>(variant), type, CultureInfo.InvariantCulture); if (typeof(GodotObject[]).IsAssignableFrom(type)) { @@ -796,7 +797,7 @@ namespace Godot } using var godotArray = NativeFuncs.godotsharp_variant_as_array(variant); - return Convert.ChangeType(ConvertToSystemArrayOfGodotObject(godotArray, type), type); + return Convert.ChangeType(ConvertToSystemArrayOfGodotObject(godotArray, type), type, CultureInfo.InvariantCulture); } if (type.IsEnum) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.exceptions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.exceptions.cs index a7640043ce..8195828de9 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.exceptions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.exceptions.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Text; #nullable enable @@ -73,7 +74,7 @@ namespace Godot if (!string.IsNullOrEmpty(_nativeClassName)) { - sb.Append($" (Method '{_nativeClassName}')"); + sb.Append(CultureInfo.InvariantCulture, $" (Method '{_nativeClassName}')"); } return sb.ToString(); @@ -131,7 +132,7 @@ namespace Godot if (!string.IsNullOrEmpty(_nativeMethodName)) { - sb.Append($" (Method '{_nativeMethodName}')"); + sb.Append(CultureInfo.InvariantCulture, $" (Method '{_nativeMethodName}')"); } return sb.ToString(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs index f5dc34d824..c5998eca5c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs @@ -435,7 +435,9 @@ namespace Godot /// <returns>A string representation of this plane.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"{_normal.ToString(format)}, {_d.ToString(format)}"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs index a646caad3e..2aac23d799 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs @@ -1023,10 +1023,12 @@ namespace Godot /// <returns>A string representation of this projection.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"{X.X.ToString(format)}, {X.Y.ToString(format)}, {X.Z.ToString(format)}, {X.W.ToString(format)}\n" + $"{Y.X.ToString(format)}, {Y.Y.ToString(format)}, {Y.Z.ToString(format)}, {Y.W.ToString(format)}\n" + $"{Z.X.ToString(format)}, {Z.Y.ToString(format)}, {Z.Z.ToString(format)}, {Z.W.ToString(format)}\n" + $"{W.X.ToString(format)}, {W.Y.ToString(format)}, {W.Z.ToString(format)}, {W.W.ToString(format)}\n"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index 2344e8c510..6a8cb1ba04 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -822,7 +822,9 @@ namespace Godot /// <returns>A string representation of this quaternion.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index 9de6aafc8a..f249bac69c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -314,7 +314,7 @@ namespace Godot /// <returns>The capitalized string.</returns> public static string Capitalize(this string instance) { - string aux = instance.CamelcaseToUnderscore(true).Replace("_", " ").Trim(); + string aux = instance.CamelcaseToUnderscore(true).Replace("_", " ", StringComparison.Ordinal).Trim(); string cap = string.Empty; for (int i = 0; i < aux.GetSliceCount(" "); i++) @@ -742,7 +742,7 @@ namespace Godot byte[] ret = new byte[len]; for (int i = 0; i < len; i++) { - ret[i] = (byte)int.Parse(instance.AsSpan(i * 2, 2), NumberStyles.AllowHexSpecifier); + ret[i] = (byte)int.Parse(instance.AsSpan(i * 2, 2), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); } return ret; } @@ -821,7 +821,7 @@ namespace Godot instance = instance.Substring(2); } - return sign * int.Parse(instance, NumberStyles.HexNumber); + return sign * int.Parse(instance, NumberStyles.HexNumber, CultureInfo.InvariantCulture); } /// <summary> @@ -878,7 +878,7 @@ namespace Godot if (string.IsNullOrEmpty(instance)) return false; else if (instance.Length > 1) - return instance[0] == '/' || instance[0] == '\\' || instance.Contains(":/") || instance.Contains(":\\"); + return instance[0] == '/' || instance[0] == '\\' || instance.Contains(":/", StringComparison.Ordinal) || instance.Contains(":\\", StringComparison.Ordinal); else return instance[0] == '/' || instance[0] == '\\'; } @@ -1120,7 +1120,7 @@ namespace Godot /// <returns>If the string contains a valid IP address.</returns> public static bool IsValidIPAddress(this string instance) { - if (instance.Contains(':')) + if (instance.Contains(':', StringComparison.Ordinal)) { string[] ip = instance.Split(':'); @@ -1405,22 +1405,9 @@ namespace Godot } /// <summary> - /// Replace occurrences of a substring for different ones inside the string. - /// </summary> - /// <seealso cref="ReplaceN(string, string, string)"/> - /// <param name="instance">The string to modify.</param> - /// <param name="what">The substring to be replaced in the string.</param> - /// <param name="forwhat">The substring that replaces <paramref name="what"/>.</param> - /// <returns>The string with the substring occurrences replaced.</returns> - public static string Replace(this string instance, string what, string forwhat) - { - return instance.Replace(what, forwhat); - } - - /// <summary> /// Replace occurrences of a substring for different ones inside the string, but search case-insensitive. /// </summary> - /// <seealso cref="Replace(string, string, string)"/> + /// <seealso cref="string.Replace(string, string, StringComparison)"/> /// <param name="instance">The string to modify.</param> /// <param name="what">The substring to be replaced in the string.</param> /// <param name="forwhat">The substring that replaces <paramref name="what"/>.</param> @@ -1634,7 +1621,7 @@ namespace Godot if (end < 0) end = len; if (allowEmpty || end > from) - ret.Add(float.Parse(instance.Substring(from))); + ret.Add(float.Parse(instance.Substring(from), CultureInfo.InvariantCulture)); if (end == len) break; @@ -1738,7 +1725,7 @@ namespace Godot /// <returns>The number representation of the string.</returns> public static float ToFloat(this string instance) { - return float.Parse(instance); + return float.Parse(instance, CultureInfo.InvariantCulture); } /// <summary> @@ -1749,7 +1736,7 @@ namespace Godot /// <returns>The number representation of the string.</returns> public static int ToInt(this string instance) { - return int.Parse(instance); + return int.Parse(instance, CultureInfo.InvariantCulture); } /// <summary> @@ -1802,7 +1789,7 @@ namespace Godot /// <returns>A copy of the string with the prefix string removed from the start.</returns> public static string TrimPrefix(this string instance, string prefix) { - if (instance.StartsWith(prefix)) + if (instance.StartsWith(prefix, StringComparison.Ordinal)) return instance.Substring(prefix.Length); return instance; @@ -1816,7 +1803,7 @@ namespace Godot /// <returns>A copy of the string with the suffix string removed from the end.</returns> public static string TrimSuffix(this string instance, string suffix) { - if (instance.EndsWith(suffix)) + if (instance.EndsWith(suffix, StringComparison.Ordinal)) return instance.Substring(0, instance.Length - suffix.Length); return instance; @@ -1833,7 +1820,7 @@ namespace Godot /// <returns>The unescaped string.</returns> public static string URIDecode(this string instance) { - return Uri.UnescapeDataString(instance.Replace("+", "%20")); + return Uri.UnescapeDataString(instance.Replace("+", "%20", StringComparison.Ordinal)); } /// <summary> @@ -1860,10 +1847,10 @@ namespace Godot /// <returns>The string sanitized as a valid node name.</returns> public static string ValidateNodeName(this string instance) { - string name = instance.Replace(_invalidNodeNameCharacters[0], ""); + string name = instance.Replace(_invalidNodeNameCharacters[0], "", StringComparison.Ordinal); for (int i = 1; i < _invalidNodeNameCharacters.Length; i++) { - name = name.Replace(_invalidNodeNameCharacters[i], ""); + name = name.Replace(_invalidNodeNameCharacters[i], "", StringComparison.Ordinal); } return name; } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index a27a1ab1cf..bd92e48bce 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -1021,7 +1021,9 @@ namespace Godot /// <returns>A string representation of this vector.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({X.ToString(format)}, {Y.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs index 8960323754..1a386d9da1 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs @@ -600,7 +600,9 @@ namespace Godot /// <returns>A string representation of this vector.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({X.ToString(format)}, {Y.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index 54d698345f..6e77512fc8 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -1123,7 +1123,9 @@ namespace Godot /// <returns>A string representation of this vector.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs index 2d7bbc926d..d0ad1922f6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3I.cs @@ -655,7 +655,9 @@ namespace Godot /// <returns>A string representation of this vector.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs index 87c01ad5ea..115e65bbdb 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4.cs @@ -905,7 +905,9 @@ namespace Godot /// <returns>A string representation of this vector.</returns> public readonly string ToString(string? format) { +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})"; +#pragma warning restore CA1305 } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs index 9a85f359d7..527c8e5022 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector4I.cs @@ -676,7 +676,9 @@ namespace Godot /// <returns>A string representation of this vector.</returns> public readonly string ToString(string? format) { - return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}), {W.ToString(format)})"; +#pragma warning disable CA1305 // Disable warning: "Specify IFormatProvider" + return $"({X.ToString(format)}, {Y.ToString(format)}, {Z.ToString(format)}, {W.ToString(format)})"; +#pragma warning restore CA1305 } } } |