summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacio Etcheverry <neikeq@users.noreply.github.com>2018-09-10 23:52:00 +0200
committerGitHub <noreply@github.com>2018-09-10 23:52:00 +0200
commit8366da5bc6073a6a622add80aae9beef3b215763 (patch)
tree47abd9efef8540711375c25728fc2a197a3ce0bb
parent96014b639111815de4c77ad30739d7b3927852ab (diff)
parent627ed98ed177de3c01c313bd2c7901fb39945af0 (diff)
Merge pull request #21822 from aaronfranke/mono-pascal
[Mono] Various style changes and naming standardization
-rw-r--r--modules/mono/glue/cs_files/AABB.cs72
-rw-r--r--modules/mono/glue/cs_files/Basis.cs90
-rw-r--r--modules/mono/glue/cs_files/Color.cs28
-rw-r--r--modules/mono/glue/cs_files/GodotSynchronizationContext.cs32
-rw-r--r--modules/mono/glue/cs_files/GodotTaskScheduler.cs148
-rw-r--r--modules/mono/glue/cs_files/StringExtensions.cs204
6 files changed, 289 insertions, 285 deletions
diff --git a/modules/mono/glue/cs_files/AABB.cs b/modules/mono/glue/cs_files/AABB.cs
index 0df2e615f1..66490b5e25 100644
--- a/modules/mono/glue/cs_files/AABB.cs
+++ b/modules/mono/glue/cs_files/AABB.cs
@@ -51,24 +51,24 @@ namespace Godot
src_max.z > dst_max.z;
}
- public AABB Expand(Vector3 to_point)
+ public AABB Expand(Vector3 point)
{
Vector3 begin = _position;
Vector3 end = _position + _size;
- if (to_point.x < begin.x)
- begin.x = to_point.x;
- if (to_point.y < begin.y)
- begin.y = to_point.y;
- if (to_point.z < begin.z)
- begin.z = to_point.z;
+ if (point.x < begin.x)
+ begin.x = point.x;
+ if (point.y < begin.y)
+ begin.y = point.y;
+ if (point.z < begin.z)
+ begin.z = point.z;
- if (to_point.x > end.x)
- end.x = to_point.x;
- if (to_point.y > end.y)
- end.y = to_point.y;
- if (to_point.z > end.z)
- end.z = to_point.z;
+ if (point.x > end.x)
+ end.x = point.x;
+ if (point.y > end.y)
+ end.y = point.y;
+ if (point.z > end.z)
+ end.z = point.z;
return new AABB(begin, end - begin);
}
@@ -347,29 +347,29 @@ namespace Godot
for (int i = 0; i < 3; i++)
{
- real_t seg_from = from[i];
- real_t seg_to = to[i];
- real_t box_begin = _position[i];
- real_t box_end = box_begin + _size[i];
+ real_t segFrom = from[i];
+ real_t segTo = to[i];
+ real_t boxBegin = _position[i];
+ real_t boxEnd = boxBegin + _size[i];
real_t cmin, cmax;
- if (seg_from < seg_to)
+ if (segFrom < segTo)
{
- if (seg_from > box_end || seg_to < box_begin)
+ if (segFrom > boxEnd || segTo < boxBegin)
return false;
- real_t length = seg_to - seg_from;
- cmin = seg_from < box_begin ? (box_begin - seg_from) / length : 0f;
- cmax = seg_to > box_end ? (box_end - seg_from) / length : 1f;
+ real_t length = segTo - segFrom;
+ cmin = segFrom < boxBegin ? (boxBegin - segFrom) / length : 0f;
+ cmax = segTo > boxEnd ? (boxEnd - segFrom) / length : 1f;
}
else
{
- if (seg_to > box_end || seg_from < box_begin)
+ if (segTo > boxEnd || segFrom < boxBegin)
return false;
- real_t length = seg_to - seg_from;
- cmin = seg_from > box_end ? (box_end - seg_from) / length : 0f;
- cmax = seg_to < box_begin ? (box_begin - seg_from) / length : 1f;
+ real_t length = segTo - segFrom;
+ cmin = segFrom > boxEnd ? (boxEnd - segFrom) / length : 0f;
+ cmax = segTo < boxBegin ? (boxBegin - segFrom) / length : 1f;
}
if (cmin > min)
@@ -388,21 +388,21 @@ namespace Godot
public AABB Merge(AABB with)
{
- Vector3 beg_1 = _position;
- Vector3 beg_2 = with._position;
- var end_1 = new Vector3(_size.x, _size.y, _size.z) + beg_1;
- var end_2 = new Vector3(with._size.x, with._size.y, with._size.z) + beg_2;
+ Vector3 beg1 = _position;
+ Vector3 beg2 = with._position;
+ var end1 = new Vector3(_size.x, _size.y, _size.z) + beg1;
+ var end2 = new Vector3(with._size.x, with._size.y, with._size.z) + beg2;
var min = new Vector3(
- beg_1.x < beg_2.x ? beg_1.x : beg_2.x,
- beg_1.y < beg_2.y ? beg_1.y : beg_2.y,
- beg_1.z < beg_2.z ? beg_1.z : beg_2.z
+ beg1.x < beg2.x ? beg1.x : beg2.x,
+ beg1.y < beg2.y ? beg1.y : beg2.y,
+ beg1.z < beg2.z ? beg1.z : beg2.z
);
var max = new Vector3(
- end_1.x > end_2.x ? end_1.x : end_2.x,
- end_1.y > end_2.y ? end_1.y : end_2.y,
- end_1.z > end_2.z ? end_1.z : end_2.z
+ end1.x > end2.x ? end1.x : end2.x,
+ end1.y > end2.y ? end1.y : end2.y,
+ end1.z > end2.z ? end1.z : end2.z
);
return new AABB(min, max - min);
diff --git a/modules/mono/glue/cs_files/Basis.cs b/modules/mono/glue/cs_files/Basis.cs
index 10286f3832..ec96a9e2fa 100644
--- a/modules/mono/glue/cs_files/Basis.cs
+++ b/modules/mono/glue/cs_files/Basis.cs
@@ -378,51 +378,51 @@ namespace Godot
);
}
- public Quat Quat() {
- real_t trace = _x[0] + _y[1] + _z[2];
-
- if (trace > 0.0f) {
- real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
- real_t inv_s = 1f / s;
- return new Quat(
- (_z[1] - _y[2]) * inv_s,
- (_x[2] - _z[0]) * inv_s,
- (_y[0] - _x[1]) * inv_s,
- s * 0.25f
- );
- }
-
- if (_x[0] > _y[1] && _x[0] > _z[2]) {
- real_t s = Mathf.Sqrt(_x[0] - _y[1] - _z[2] + 1.0f) * 2f;
- real_t inv_s = 1f / s;
- return new Quat(
- s * 0.25f,
- (_x[1] + _y[0]) * inv_s,
- (_x[2] + _z[0]) * inv_s,
- (_z[1] - _y[2]) * inv_s
- );
- }
-
- if (_y[1] > _z[2]) {
- real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
- real_t inv_s = 1f / s;
- return new Quat(
- (_x[1] + _y[0]) * inv_s,
- s * 0.25f,
- (_y[2] + _z[1]) * inv_s,
- (_x[2] - _z[0]) * inv_s
- );
- } else {
- real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
- real_t inv_s = 1f / s;
- return new Quat(
- (_x[2] + _z[0]) * inv_s,
- (_y[2] + _z[1]) * inv_s,
- s * 0.25f,
- (_y[0] - _x[1]) * inv_s
- );
- }
- }
+ public Quat Quat() {
+ real_t trace = _x[0] + _y[1] + _z[2];
+
+ if (trace > 0.0f) {
+ real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
+ real_t inv_s = 1f / s;
+ return new Quat(
+ (_z[1] - _y[2]) * inv_s,
+ (_x[2] - _z[0]) * inv_s,
+ (_y[0] - _x[1]) * inv_s,
+ s * 0.25f
+ );
+ }
+
+ if (_x[0] > _y[1] && _x[0] > _z[2]) {
+ real_t s = Mathf.Sqrt(_x[0] - _y[1] - _z[2] + 1.0f) * 2f;
+ real_t inv_s = 1f / s;
+ return new Quat(
+ s * 0.25f,
+ (_x[1] + _y[0]) * inv_s,
+ (_x[2] + _z[0]) * inv_s,
+ (_z[1] - _y[2]) * inv_s
+ );
+ }
+
+ if (_y[1] > _z[2]) {
+ real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
+ real_t inv_s = 1f / s;
+ return new Quat(
+ (_x[1] + _y[0]) * inv_s,
+ s * 0.25f,
+ (_y[2] + _z[1]) * inv_s,
+ (_x[2] - _z[0]) * inv_s
+ );
+ } else {
+ real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
+ real_t inv_s = 1f / s;
+ return new Quat(
+ (_x[2] + _z[0]) * inv_s,
+ (_y[2] + _z[1]) * inv_s,
+ s * 0.25f,
+ (_y[0] - _x[1]) * inv_s
+ );
+ }
+ }
public Basis(Quat quat)
{
diff --git a/modules/mono/glue/cs_files/Color.cs b/modules/mono/glue/cs_files/Color.cs
index 49e04b333a..88cb8524b8 100644
--- a/modules/mono/glue/cs_files/Color.cs
+++ b/modules/mono/glue/cs_files/Color.cs
@@ -370,12 +370,12 @@ namespace Godot
{
var txt = string.Empty;
- txt += _to_hex(r);
- txt += _to_hex(g);
- txt += _to_hex(b);
+ txt += ToHex32(r);
+ txt += ToHex32(g);
+ txt += ToHex32(b);
if (include_alpha)
- txt = _to_hex(a) + txt;
+ txt = ToHex32(a) + txt;
return txt;
}
@@ -411,7 +411,7 @@ namespace Godot
r = (rgba & 0xFFFF) / 65535.0f;
}
- private static int _parse_col(string str, int ofs)
+ private static int ParseCol8(string str, int ofs)
{
int ig = 0;
@@ -448,7 +448,7 @@ namespace Godot
return ig;
}
- private String _to_hex(float val)
+ private String ToHex32(float val)
{
int v = Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255));
@@ -490,17 +490,17 @@ namespace Godot
if (alpha)
{
- if (_parse_col(color, 0) < 0)
+ if (ParseCol8(color, 0) < 0)
return false;
}
int from = alpha ? 2 : 0;
- if (_parse_col(color, from + 0) < 0)
+ if (ParseCol8(color, from + 0) < 0)
return false;
- if (_parse_col(color, from + 2) < 0)
+ if (ParseCol8(color, from + 2) < 0)
return false;
- if (_parse_col(color, from + 4) < 0)
+ if (ParseCol8(color, from + 4) < 0)
return false;
return true;
@@ -542,7 +542,7 @@ namespace Godot
if (alpha)
{
- a = _parse_col(rgba, 0) / 255f;
+ a = ParseCol8(rgba, 0) / 255f;
if (a < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba);
@@ -554,17 +554,17 @@ namespace Godot
int from = alpha ? 2 : 0;
- r = _parse_col(rgba, from + 0) / 255f;
+ r = ParseCol8(rgba, from + 0) / 255f;
if (r < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Red part is not valid hexadecimal: " + rgba);
- g = _parse_col(rgba, from + 2) / 255f;
+ g = ParseCol8(rgba, from + 2) / 255f;
if (g < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Green part is not valid hexadecimal: " + rgba);
- b = _parse_col(rgba, from + 4) / 255f;
+ b = ParseCol8(rgba, from + 4) / 255f;
if (b < 0)
throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba);
diff --git a/modules/mono/glue/cs_files/GodotSynchronizationContext.cs b/modules/mono/glue/cs_files/GodotSynchronizationContext.cs
index da3c7bac83..e727781d63 100644
--- a/modules/mono/glue/cs_files/GodotSynchronizationContext.cs
+++ b/modules/mono/glue/cs_files/GodotSynchronizationContext.cs
@@ -4,22 +4,22 @@ using System.Threading;
namespace Godot
{
- public class GodotSynchronizationContext : SynchronizationContext
- {
- private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
+ public class GodotSynchronizationContext : SynchronizationContext
+ {
+ private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
- public override void Post(SendOrPostCallback d, object state)
- {
- queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
- }
+ public override void Post(SendOrPostCallback d, object state)
+ {
+ queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
+ }
- public void ExecutePendingContinuations()
- {
- KeyValuePair<SendOrPostCallback, object> workItem;
- while (queue.TryTake(out workItem))
- {
- workItem.Key(workItem.Value);
- }
- }
- }
+ public void ExecutePendingContinuations()
+ {
+ KeyValuePair<SendOrPostCallback, object> workItem;
+ while (queue.TryTake(out workItem))
+ {
+ workItem.Key(workItem.Value);
+ }
+ }
+ }
}
diff --git a/modules/mono/glue/cs_files/GodotTaskScheduler.cs b/modules/mono/glue/cs_files/GodotTaskScheduler.cs
index 3d23ec10f1..9a40fef5a9 100644
--- a/modules/mono/glue/cs_files/GodotTaskScheduler.cs
+++ b/modules/mono/glue/cs_files/GodotTaskScheduler.cs
@@ -6,89 +6,89 @@ using System.Threading.Tasks;
namespace Godot
{
- public class GodotTaskScheduler : TaskScheduler
- {
- private GodotSynchronizationContext Context { get; set; }
- private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
+ public class GodotTaskScheduler : TaskScheduler
+ {
+ private GodotSynchronizationContext Context { get; set; }
+ private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
- public GodotTaskScheduler()
- {
- Context = new GodotSynchronizationContext();
- SynchronizationContext.SetSynchronizationContext(Context);
- }
+ public GodotTaskScheduler()
+ {
+ Context = new GodotSynchronizationContext();
+ SynchronizationContext.SetSynchronizationContext(Context);
+ }
- protected sealed override void QueueTask(Task task)
- {
- lock (_tasks)
- {
- _tasks.AddLast(task);
- }
- }
+ protected sealed override void QueueTask(Task task)
+ {
+ lock (_tasks)
+ {
+ _tasks.AddLast(task);
+ }
+ }
- protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
- {
- if (SynchronizationContext.Current != Context)
- {
- return false;
- }
+ protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
+ {
+ if (SynchronizationContext.Current != Context)
+ {
+ return false;
+ }
- if (taskWasPreviouslyQueued)
- {
- TryDequeue(task);
- }
+ if (taskWasPreviouslyQueued)
+ {
+ TryDequeue(task);
+ }
- return TryExecuteTask(task);
- }
+ return TryExecuteTask(task);
+ }
- protected sealed override bool TryDequeue(Task task)
- {
- lock (_tasks)
- {
- return _tasks.Remove(task);
- }
- }
+ protected sealed override bool TryDequeue(Task task)
+ {
+ lock (_tasks)
+ {
+ return _tasks.Remove(task);
+ }
+ }
- protected sealed override IEnumerable<Task> GetScheduledTasks()
- {
- lock (_tasks)
- {
- return _tasks.ToArray();
- }
- }
+ protected sealed override IEnumerable<Task> GetScheduledTasks()
+ {
+ lock (_tasks)
+ {
+ return _tasks.ToArray();
+ }
+ }
- public void Activate()
- {
- ExecuteQueuedTasks();
- Context.ExecutePendingContinuations();
- }
+ public void Activate()
+ {
+ ExecuteQueuedTasks();
+ Context.ExecutePendingContinuations();
+ }
- private void ExecuteQueuedTasks()
- {
- while (true)
- {
- Task task;
+ private void ExecuteQueuedTasks()
+ {
+ while (true)
+ {
+ Task task;
- lock (_tasks)
- {
- if (_tasks.Any())
- {
- task = _tasks.First.Value;
- _tasks.RemoveFirst();
- }
- else
- {
- break;
- }
- }
+ lock (_tasks)
+ {
+ if (_tasks.Any())
+ {
+ task = _tasks.First.Value;
+ _tasks.RemoveFirst();
+ }
+ else
+ {
+ break;
+ }
+ }
- if (task != null)
- {
- if (!TryExecuteTask(task))
- {
- throw new InvalidOperationException();
- }
- }
- }
- }
- }
+ if (task != null)
+ {
+ if (!TryExecuteTask(task))
+ {
+ throw new InvalidOperationException();
+ }
+ }
+ }
+ }
+ }
}
diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs
index b58f8bc6a8..cda573f6c5 100644
--- a/modules/mono/glue/cs_files/StringExtensions.cs
+++ b/modules/mono/glue/cs_files/StringExtensions.cs
@@ -26,7 +26,7 @@ namespace Godot
return slices;
}
- private static string GetSlicec(this string instance, char splitter, int slice)
+ private static string GetSliceCharacter(this string instance, char splitter, int slice)
{
if (!instance.Empty() && slice >= 0)
{
@@ -36,12 +36,18 @@ namespace Godot
while (true)
{
- if (instance[i] == 0 || instance[i] == splitter)
+ bool end = instance.Length <= i;
+
+ if (end || instance[i] == splitter)
{
if (slice == count)
{
return instance.Substring(prev, i - prev);
}
+ else if (end)
+ {
+ return string.Empty;
+ }
count++;
prev = i + 1;
@@ -57,7 +63,7 @@ namespace Godot
// <summary>
// If the string is a path to a file, return the path to the file without the extension.
// </summary>
- public static string Basename(this string instance)
+ public static string BaseName(this string instance)
{
int index = instance.LastIndexOf('.');
@@ -144,7 +150,7 @@ namespace Godot
for (int i = 0; i < aux.GetSliceCount(" "); i++)
{
- string slice = aux.GetSlicec(' ', i);
+ string slice = aux.GetSliceCharacter(' ', i);
if (slice.Length > 0)
{
slice = char.ToUpper(slice[0]) + slice.Substring(1);
@@ -162,30 +168,59 @@ namespace Godot
// </summary>
public static int CasecmpTo(this string instance, string to)
{
+ return instance.CompareTo(to, true);
+ }
+
+ // <summary>
+ // Perform a comparison to another string, return -1 if less, 0 if equal and +1 if greater.
+ // </summary>
+ public static int CompareTo(this string instance, string to, bool caseSensitive = true)
+ {
if (instance.Empty())
return to.Empty() ? 0 : -1;
if (to.Empty())
return 1;
- int instance_idx = 0;
- int to_idx = 0;
-
- while (true)
+ int instanceIndex = 0;
+ int toIndex = 0;
+
+ if (caseSensitive) // Outside while loop to avoid checking multiple times, despite some code duplication.
+ {
+ while (true)
+ {
+ if (to[toIndex] == 0 && instance[instanceIndex] == 0)
+ return 0; // We're equal
+ if (instance[instanceIndex] == 0)
+ return -1; // If this is empty, and the other one is not, then we're less... I think?
+ if (to[toIndex] == 0)
+ return 1; // Otherwise the other one is smaller...
+ if (instance[instanceIndex] < to[toIndex]) // More than
+ return -1;
+ if (instance[instanceIndex] > to[toIndex]) // Less than
+ return 1;
+
+ instanceIndex++;
+ toIndex++;
+ }
+ } else
{
- if (to[to_idx] == 0 && instance[instance_idx] == 0)
- return 0; // We're equal
- if (instance[instance_idx] == 0)
- return -1; // If this is empty, and the other one is not, then we're less... I think?
- if (to[to_idx] == 0)
- return 1; // Otherwise the other one is smaller...
- if (instance[instance_idx] < to[to_idx]) // More than
- return -1;
- if (instance[instance_idx] > to[to_idx]) // Less than
- return 1;
-
- instance_idx++;
- to_idx++;
+ while (true)
+ {
+ if (to[toIndex] == 0 && instance[instanceIndex] == 0)
+ return 0; // We're equal
+ if (instance[instanceIndex] == 0)
+ return -1; // If this is empty, and the other one is not, then we're less... I think?
+ if (to[toIndex] == 0)
+ return 1; // Otherwise the other one is smaller..
+ if (char.ToUpper(instance[instanceIndex]) < char.ToUpper(to[toIndex])) // More than
+ return -1;
+ if (char.ToUpper(instance[instanceIndex]) > char.ToUpper(to[toIndex])) // Less than
+ return 1;
+
+ instanceIndex++;
+ toIndex++;
+ }
}
}
@@ -361,7 +396,7 @@ namespace Godot
// <summary>
// Check whether this string is a subsequence of the given string.
// </summary>
- public static bool IsSubsequenceOf(this string instance, string text, bool case_insensitive)
+ public static bool IsSubsequenceOf(this string instance, string text, bool caseSensitive = true)
{
int len = instance.Length;
@@ -371,50 +406,42 @@ namespace Godot
if (len > text.Length)
return false;
- int src = 0;
- int tgt = 0;
+ int source = 0;
+ int target = 0;
- while (instance[src] != 0 && text[tgt] != 0)
+ while (instance[source] != 0 && text[target] != 0)
{
bool match;
- if (case_insensitive)
+ if (!caseSensitive)
{
- char srcc = char.ToLower(instance[src]);
- char tgtc = char.ToLower(text[tgt]);
- match = srcc == tgtc;
+ char sourcec = char.ToLower(instance[source]);
+ char targetc = char.ToLower(text[target]);
+ match = sourcec == targetc;
}
else
{
- match = instance[src] == text[tgt];
+ match = instance[source] == text[target];
}
if (match)
{
- src++;
- if (instance[src] == 0)
+ source++;
+ if (instance[source] == 0)
return true;
}
- tgt++;
+ target++;
}
return false;
}
// <summary>
- // Check whether this string is a subsequence of the given string, considering case.
- // </summary>
- public static bool IsSubsequenceOf(this string instance, string text)
- {
- return instance.IsSubsequenceOf(text, false);
- }
-
- // <summary>
- // Check whether this string is a subsequence of the given string, without considering case.
+ // Check whether this string is a subsequence of the given string, ignoring case differences.
// </summary>
public static bool IsSubsequenceOfI(this string instance, string text)
{
- return instance.IsSubsequenceOf(text, true);
+ return instance.IsSubsequenceOf(text, false);
}
// <summary>
@@ -452,12 +479,12 @@ namespace Godot
return false; // Don't start with number plz
}
- bool valid_char = instance[i] >= '0' &&
+ bool validChar = instance[i] >= '0' &&
instance[i] <= '9' || instance[i] >= 'a' &&
instance[i] <= 'z' || instance[i] >= 'A' &&
instance[i] <= 'Z' || instance[i] == '_';
- if (!valid_char)
+ if (!validChar)
return false;
}
@@ -476,8 +503,9 @@ namespace Godot
// <summary>
// Check whether the string contains a valid IP address.
// </summary>
- public static bool IsValidIpAddress(this string instance)
+ public static bool IsValidIPAddress(this string instance)
{
+ // TODO: Support IPv6 addresses
string[] ip = instance.Split(".");
if (ip.Length != 4)
@@ -500,7 +528,7 @@ namespace Godot
// <summary>
// Return a copy of the string with special characters escaped using the JSON standard.
// </summary>
- public static string JsonEscape(this string instance)
+ public static string JSONEscape(this string instance)
{
var sb = new StringBuilder(string.Copy(instance));
@@ -563,15 +591,15 @@ namespace Godot
// <summary>
// Do a simple case sensitive expression match, using ? and * wildcards (see [method expr_match]).
// </summary>
- public static bool Match(this string instance, string expr)
+ public static bool Match(this string instance, string expr, bool caseSensitive = true)
{
- return instance.ExprMatch(expr, true);
+ return instance.ExprMatch(expr, caseSensitive);
}
// <summary>
// Do a simple case insensitive expression match, using ? and * wildcards (see [method expr_match]).
// </summary>
- public static bool Matchn(this string instance, string expr)
+ public static bool MatchN(this string instance, string expr)
{
return instance.ExprMatch(expr, false);
}
@@ -579,7 +607,7 @@ namespace Godot
// <summary>
// Return the MD5 hash of the string as an array of bytes.
// </summary>
- public static byte[] Md5Buffer(this string instance)
+ public static byte[] MD5Buffer(this string instance)
{
return NativeCalls.godot_icall_String_md5_buffer(instance);
}
@@ -587,7 +615,7 @@ namespace Godot
// <summary>
// Return the MD5 hash of the string as a string.
// </summary>
- public static string Md5Text(this string instance)
+ public static string MD5Text(this string instance)
{
return NativeCalls.godot_icall_String_md5_text(instance);
}
@@ -597,31 +625,7 @@ namespace Godot
// </summary>
public static int NocasecmpTo(this string instance, string to)
{
- if (instance.Empty())
- return to.Empty() ? 0 : -1;
-
- if (to.Empty())
- return 1;
-
- int instance_idx = 0;
- int to_idx = 0;
-
- while (true)
- {
- if (to[to_idx] == 0 && instance[instance_idx] == 0)
- return 0; // We're equal
- if (instance[instance_idx] == 0)
- return -1; // If this is empty, and the other one is not, then we're less... I think?
- if (to[to_idx] == 0)
- return 1; // Otherwise the other one is smaller..
- if (char.ToUpper(instance[instance_idx]) < char.ToUpper(to[to_idx])) // More than
- return -1;
- if (char.ToUpper(instance[instance_idx]) > char.ToUpper(to[to_idx])) // Less than
- return 1;
-
- instance_idx++;
- to_idx++;
- }
+ return instance.CompareTo(to, false);
}
// <summary>
@@ -738,7 +742,7 @@ namespace Godot
// <summary>
// Replace occurrences of a substring for different ones inside the string, but search case-insensitive.
// </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);
}
@@ -746,7 +750,7 @@ namespace Godot
// <summary>
// Perform a search for a substring, but start from the end of the string instead of the beginning.
// </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 NativeCalls.godot_icall_String_rfind(instance, what, from);
}
@@ -754,7 +758,7 @@ namespace Godot
// <summary>
// Perform a search for a substring, but start from the end of the string instead of the beginning. 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 NativeCalls.godot_icall_String_rfindn(instance, what, from);
}
@@ -773,7 +777,7 @@ namespace Godot
return instance.Substring(pos, instance.Length - pos);
}
- public static byte[] Sha256Buffer(this string instance)
+ public static byte[] SHA256Buffer(this string instance)
{
return NativeCalls.godot_icall_String_sha256_buffer(instance);
}
@@ -781,7 +785,7 @@ namespace Godot
// <summary>
// Return the SHA-256 hash of the string as a string.
// </summary>
- public static string Sha256Text(this string instance)
+ public static string SHA256Text(this string instance)
{
return NativeCalls.godot_icall_String_sha256_text(instance);
}
@@ -802,20 +806,20 @@ namespace Godot
return 0.0f;
}
- string[] srcBigrams = instance.Bigrams();
- string[] tgtBigrams = text.Bigrams();
+ string[] sourceBigrams = instance.Bigrams();
+ string[] targetBigrams = text.Bigrams();
- int src_size = srcBigrams.Length;
- int tgt_size = tgtBigrams.Length;
+ int sourceSize = sourceBigrams.Length;
+ int targetSize = targetBigrams.Length;
- float sum = src_size + tgt_size;
+ float sum = sourceSize + targetSize;
float inter = 0;
- for (int i = 0; i < src_size; i++)
+ for (int i = 0; i < sourceSize; i++)
{
- for (int j = 0; j < tgt_size; j++)
+ for (int j = 0; j < targetSize; j++)
{
- if (srcBigrams[i] == tgtBigrams[j])
+ if (sourceBigrams[i] == targetBigrams[j])
{
inter++;
break;
@@ -829,7 +833,7 @@ namespace Godot
// <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 ",".
// </summary>
- public static string[] Split(this string instance, string divisor, bool allow_empty = true)
+ public static string[] Split(this string instance, string divisor, bool allowEmpty = true)
{
return instance.Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
}
@@ -837,7 +841,7 @@ namespace Godot
// <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 ",".
// </summary>
- public static float[] SplitFloats(this string instance, string divisor, bool allow_empty = true)
+ public static float[] SplitFloats(this string instance, string divisor, bool allowEmpty = true)
{
var ret = new List<float>();
int from = 0;
@@ -848,7 +852,7 @@ namespace Godot
int end = instance.Find(divisor, from);
if (end < 0)
end = len;
- if (allow_empty || end > from)
+ if (allowEmpty || end > from)
ret.Add(float.Parse(instance.Substring(from)));
if (end == len)
break;
@@ -859,7 +863,7 @@ namespace Godot
return ret.ToArray();
}
- private static readonly char[] non_printable = {
+ private static readonly char[] _nonPrintable = {
(char)00, (char)01, (char)02, (char)03, (char)04, (char)05,
(char)06, (char)07, (char)08, (char)09, (char)10, (char)11,
(char)12, (char)13, (char)14, (char)15, (char)16, (char)17,
@@ -876,11 +880,11 @@ namespace Godot
if (left)
{
if (right)
- return instance.Trim(non_printable);
- return instance.TrimStart(non_printable);
+ return instance.Trim(_nonPrintable);
+ return instance.TrimStart(_nonPrintable);
}
- return instance.TrimEnd(non_printable);
+ return instance.TrimEnd(_nonPrintable);
}
// <summary>
@@ -934,7 +938,7 @@ namespace Godot
// <summary>
// Convert the String (which is an array of characters) to PoolByteArray (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().
// </summary>
- public static byte[] ToUtf8(this string instance)
+ public static byte[] ToUTF8(this string instance)
{
return Encoding.UTF8.GetBytes(instance);
}
@@ -942,7 +946,7 @@ namespace Godot
// <summary>
// Return a copy of the string with special characters escaped using the XML standard.
// </summary>
- public static string XmlEscape(this string instance)
+ public static string XMLEscape(this string instance)
{
return SecurityElement.Escape(instance);
}
@@ -950,7 +954,7 @@ namespace Godot
// <summary>
// Return a copy of the string with escaped characters replaced by their meanings 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;
}