From 0ef3e0577b4c3889d19e6f301e06fba39e8187d5 Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Sun, 8 Apr 2018 12:28:24 +0900 Subject: #18051: Remove redundant casts and 'using', 'else', 'this' statements --- modules/mono/glue/cs_files/StringExtensions.cs | 41 +++++++++++--------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index cbc337ab19..a18c04b274 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -1,4 +1,5 @@ //using System; + using System; using System.Collections.Generic; using System.Globalization; @@ -43,11 +44,9 @@ namespace Godot { return instance.Substring(prev, i - prev); } - else - { - count++; - prev = i + 1; - } + + count++; + prev = i + 1; } i++; @@ -178,13 +177,13 @@ namespace Godot { if (to[to_idx] == 0 && instance[instance_idx] == 0) return 0; // We're equal - else if (instance[instance_idx] == 0) + if (instance[instance_idx] == 0) return -1; // If this is empty, and the other one is not, then we're less... I think? - else if (to[to_idx] == 0) + if (to[to_idx] == 0) return 1; // Otherwise the other one is smaller... - else if (instance[instance_idx] < to[to_idx]) // More than + if (instance[instance_idx] < to[to_idx]) // More than return -1; - else if (instance[instance_idx] > to[to_idx]) // Less than + if (instance[instance_idx] > to[to_idx]) // Less than return 1; instance_idx++; @@ -312,7 +311,7 @@ namespace Godot int hashv = 5381; int c; - while ((c = (int)instance[index++]) != 0) + while ((c = instance[index++]) != 0) hashv = ((hashv << 5) + hashv) + c; // hash * 33 + c return hashv; @@ -610,13 +609,13 @@ namespace Godot { if (to[to_idx] == 0 && instance[instance_idx] == 0) return 0; // We're equal - else if (instance[instance_idx] == 0) + if (instance[instance_idx] == 0) return -1; // If this is empty, and the other one is not, then we're less... I think? - else if (to[to_idx] == 0) + if (to[to_idx] == 0) return 1; // Otherwise the other one is smaller.. - else if (char.ToUpper(instance[instance_idx]) < char.ToUpper(to[to_idx])) // More than + if (char.ToUpper(instance[instance_idx]) < char.ToUpper(to[to_idx])) // More than return -1; - else if (char.ToUpper(instance[instance_idx]) > char.ToUpper(to[to_idx])) // Less than + if (char.ToUpper(instance[instance_idx]) > char.ToUpper(to[to_idx])) // Less than return 1; instance_idx++; @@ -724,8 +723,7 @@ namespace Godot { if (instance.Length > 0 && instance[instance.Length - 1] == '/') return instance + file; - else - return instance + "/" + file; + return instance + "/" + file; } // @@ -832,7 +830,7 @@ namespace Godot // public static string[] Split(this string instance, string divisor, bool allow_empty = true) { - return instance.Split(new string[] { divisor }, StringSplitOptions.RemoveEmptyEntries); + return instance.Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries); } // @@ -878,13 +876,10 @@ namespace Godot { if (right) return instance.Trim(non_printable); - else - return instance.TrimStart(non_printable); - } - else - { - return instance.TrimEnd(non_printable); + return instance.TrimStart(non_printable); } + + return instance.TrimEnd(non_printable); } // -- cgit v1.2.3 From fdfc478c888db89c44c748f273ef7fe4466d5c89 Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Sun, 8 Apr 2018 12:30:43 +0900 Subject: #18051: Use 'var' when applicable --- modules/mono/glue/cs_files/StringExtensions.cs | 40 +++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index a18c04b274..030d1282f3 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -82,9 +82,9 @@ namespace Godot // public static string[] Bigrams(this string instance) { - string[] b = new string[instance.Length - 1]; + var b = new string[instance.Length - 1]; - for (int i = 0; i < b.Length; i++) + for (var i = 0; i < b.Length; i++) { b[i] = instance.Substring(i, 2); } @@ -97,7 +97,7 @@ namespace Godot // public static string CEscape(this string instance) { - StringBuilder sb = new StringBuilder(string.Copy(instance)); + var sb = new StringBuilder(string.Copy(instance)); sb.Replace("\\", "\\\\"); sb.Replace("\a", "\\a"); @@ -119,7 +119,7 @@ namespace Godot // public static string CUnescape(this string instance) { - StringBuilder sb = new StringBuilder(string.Copy(instance)); + var sb = new StringBuilder(string.Copy(instance)); sb.Replace("\\a", "\a"); sb.Replace("\\b", "\b"); @@ -141,12 +141,12 @@ namespace Godot // public static string Capitalize(this string instance) { - string aux = instance.Replace("_", " ").ToLower(); - string cap = string.Empty; + string aux = instance.Replace("_", " ").ToLower(); + var cap = string.Empty; - for (int i = 0; i < aux.GetSliceCount(" "); i++) + for (var i = 0; i < aux.GetSliceCount(" "); i++) { - string slice = aux.GetSlicec(' ', i); + string slice = aux.GetSlicec(' ', i); if (slice.Length > 0) { slice = char.ToUpper(slice[0]) + slice.Substring(1); @@ -259,12 +259,12 @@ namespace Godot { int basepos = instance.Find("://"); - string rs = string.Empty; - string @base = string.Empty; + var rs = string.Empty; + var @base = string.Empty; if (basepos != -1) { - int end = basepos + 3; + var end = basepos + 3; rs = instance.Substring(end, instance.Length); @base = instance.Substring(0, end); } @@ -378,7 +378,7 @@ namespace Godot while (instance[src] != 0 && text[tgt] != 0) { - bool match = false; + var match = false; if (case_insensitive) { @@ -446,7 +446,7 @@ namespace Godot if (len == 0) return false; - for (int i = 0; i < len; i++) + for (var i = 0; i < len; i++) { if (i == 0) { @@ -482,7 +482,7 @@ namespace Godot if (ip.Length != 4) return false; - for (int i = 0; i < ip.Length; i++) + for (var i = 0; i < ip.Length; i++) { string n = ip[i]; if (!n.IsValidInteger()) @@ -501,7 +501,7 @@ namespace Godot // public static string JsonEscape(this string instance) { - StringBuilder sb = new StringBuilder(string.Copy(instance)); + var sb = new StringBuilder(string.Copy(instance)); sb.Replace("\\", "\\\\"); sb.Replace("\b", "\\b"); @@ -810,9 +810,9 @@ namespace Godot float sum = src_size + tgt_size; float inter = 0; - for (int i = 0; i < src_size; i++) + for (var i = 0; i < src_size; i++) { - for (int j = 0; j < tgt_size; j++) + for (var j = 0; j < tgt_size; j++) { if (srcBigrams[i] == tgtBigrams[j]) { @@ -838,9 +838,9 @@ namespace Godot // public static float[] SplitFloats(this string instance, string divisor, bool allow_empty = true) { - List ret = new List(); - int from = 0; - int len = instance.Length; + var ret = new List(); + int from = 0; + int len = instance.Length; while (true) { -- cgit v1.2.3 From 93dd59d763146938d59defe270f43091b5579a0a Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Sun, 8 Apr 2018 12:38:02 +0900 Subject: #18051: Remove unnecessary variable assignments --- modules/mono/glue/cs_files/StringExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index 030d1282f3..de85b080df 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -259,7 +259,7 @@ namespace Godot { int basepos = instance.Find("://"); - var rs = string.Empty; + string rs; var @base = string.Empty; if (basepos != -1) @@ -378,7 +378,7 @@ namespace Godot while (instance[src] != 0 && text[tgt] != 0) { - var match = false; + bool match; if (case_insensitive) { -- cgit v1.2.3 From 9097c71255c6e8edb0014c043562caffc84ee2cf Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Sun, 8 Apr 2018 12:39:35 +0900 Subject: #18051: Remove redundant parenthesis --- modules/mono/glue/cs_files/StringExtensions.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index de85b080df..c86208f9bd 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -312,7 +312,7 @@ namespace Godot int c; while ((c = instance[index++]) != 0) - hashv = ((hashv << 5) + hashv) + c; // hash * 33 + c + hashv = (hashv << 5) + hashv + c; // hash * 33 + c return hashv; } @@ -454,7 +454,10 @@ namespace Godot return false; // Don't start with number plz } - bool valid_char = (instance[i] >= '0' && instance[i] <= '9') || (instance[i] >= 'a' && instance[i] <= 'z') || (instance[i] >= 'A' && instance[i] <= 'Z') || instance[i] == '_'; + bool valid_char = instance[i] >= '0' && + instance[i] <= '9' || instance[i] >= 'a' && + instance[i] <= 'z' || instance[i] >= 'A' && + instance[i] <= 'Z' || instance[i] == '_'; if (!valid_char) return false; @@ -550,7 +553,7 @@ namespace Godot case '\0': return instance[0] == 0; case '*': - return ExprMatch(expr + 1, instance, caseSensitive) || (instance[0] != 0 && ExprMatch(expr, instance + 1, caseSensitive)); + return ExprMatch(expr + 1, instance, caseSensitive) || instance[0] != 0 && ExprMatch(expr, instance + 1, caseSensitive); case '?': return instance[0] != 0 && instance[0] != '.' && ExprMatch(expr + 1, instance + 1, caseSensitive); default: @@ -769,7 +772,7 @@ namespace Godot if (pos < 0) return string.Empty; - return instance.Substring(pos, (instance.Length - pos)); + return instance.Substring(pos, instance.Length - pos); } public static byte[] Sha256Buffer(this string instance) @@ -822,7 +825,7 @@ namespace Godot } } - return (2.0f * inter) / sum; + return 2.0f * inter / sum; } // @@ -847,7 +850,7 @@ namespace Godot int end = instance.Find(divisor, from); if (end < 0) end = len; - if (allow_empty || (end > from)) + if (allow_empty || end > @from) ret.Add(float.Parse(instance.Substring(from))); if (end == len) break; -- cgit v1.2.3 From f0bf5532fac919fdb4bb6fa0ba088117aa223524 Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Sun, 8 Apr 2018 12:49:19 +0900 Subject: #18051: Remove redundant verbatim prefixes --- modules/mono/glue/cs_files/StringExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index c86208f9bd..38f7a0941f 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -850,7 +850,7 @@ namespace Godot int end = instance.Find(divisor, from); if (end < 0) end = len; - if (allow_empty || end > @from) + if (allow_empty || end > from) ret.Add(float.Parse(instance.Substring(from))); if (end == len) break; -- cgit v1.2.3 From e59fad39245de82cb243da38ba149ccd0ed957e5 Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Tue, 17 Apr 2018 07:33:42 +0900 Subject: #18051: Do not use `var` in a for-loop, or where type is not obvious --- modules/mono/glue/cs_files/StringExtensions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index 38f7a0941f..ef81769912 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -84,7 +84,7 @@ namespace Godot { var b = new string[instance.Length - 1]; - for (var i = 0; i < b.Length; i++) + for (int i = 0; i < b.Length; i++) { b[i] = instance.Substring(i, 2); } @@ -144,7 +144,7 @@ namespace Godot string aux = instance.Replace("_", " ").ToLower(); var cap = string.Empty; - for (var i = 0; i < aux.GetSliceCount(" "); i++) + for (int i = 0; i < aux.GetSliceCount(" "); i++) { string slice = aux.GetSlicec(' ', i); if (slice.Length > 0) @@ -446,7 +446,7 @@ namespace Godot if (len == 0) return false; - for (var i = 0; i < len; i++) + for (int i = 0; i < len; i++) { if (i == 0) { @@ -485,7 +485,7 @@ namespace Godot if (ip.Length != 4) return false; - for (var i = 0; i < ip.Length; i++) + for (int i = 0; i < ip.Length; i++) { string n = ip[i]; if (!n.IsValidInteger()) @@ -813,9 +813,9 @@ namespace Godot float sum = src_size + tgt_size; float inter = 0; - for (var i = 0; i < src_size; i++) + for (int i = 0; i < src_size; i++) { - for (var j = 0; j < tgt_size; j++) + for (int j = 0; j < tgt_size; j++) { if (srcBigrams[i] == tgtBigrams[j]) { -- cgit v1.2.3 From 6b611e64316ed91b89822a3b660cdedc087a1da9 Mon Sep 17 00:00:00 2001 From: Xavier Cho Date: Tue, 17 Apr 2018 07:53:27 +0900 Subject: #18051: Fix indentation issues introduced during clean up --- modules/mono/glue/cs_files/StringExtensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/mono/glue/cs_files/StringExtensions.cs') diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index ef81769912..21090fb68d 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -141,12 +141,12 @@ namespace Godot // public static string Capitalize(this string instance) { - string aux = instance.Replace("_", " ").ToLower(); + string aux = instance.Replace("_", " ").ToLower(); var cap = string.Empty; for (int i = 0; i < aux.GetSliceCount(" "); i++) { - string slice = aux.GetSlicec(' ', i); + string slice = aux.GetSlicec(' ', i); if (slice.Length > 0) { slice = char.ToUpper(slice[0]) + slice.Substring(1); @@ -842,8 +842,8 @@ namespace Godot public static float[] SplitFloats(this string instance, string divisor, bool allow_empty = true) { var ret = new List(); - int from = 0; - int len = instance.Length; + int from = 0; + int len = instance.Length; while (true) { -- cgit v1.2.3