Merge pull request #21822 from aaronfranke/mono-pascal
[Mono] Various style changes and naming standardization
This commit is contained in:
commit
8366da5bc6
6 changed files with 285 additions and 281 deletions
|
@ -51,24 +51,24 @@ namespace Godot
|
||||||
src_max.z > dst_max.z;
|
src_max.z > dst_max.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AABB Expand(Vector3 to_point)
|
public AABB Expand(Vector3 point)
|
||||||
{
|
{
|
||||||
Vector3 begin = _position;
|
Vector3 begin = _position;
|
||||||
Vector3 end = _position + _size;
|
Vector3 end = _position + _size;
|
||||||
|
|
||||||
if (to_point.x < begin.x)
|
if (point.x < begin.x)
|
||||||
begin.x = to_point.x;
|
begin.x = point.x;
|
||||||
if (to_point.y < begin.y)
|
if (point.y < begin.y)
|
||||||
begin.y = to_point.y;
|
begin.y = point.y;
|
||||||
if (to_point.z < begin.z)
|
if (point.z < begin.z)
|
||||||
begin.z = to_point.z;
|
begin.z = point.z;
|
||||||
|
|
||||||
if (to_point.x > end.x)
|
if (point.x > end.x)
|
||||||
end.x = to_point.x;
|
end.x = point.x;
|
||||||
if (to_point.y > end.y)
|
if (point.y > end.y)
|
||||||
end.y = to_point.y;
|
end.y = point.y;
|
||||||
if (to_point.z > end.z)
|
if (point.z > end.z)
|
||||||
end.z = to_point.z;
|
end.z = point.z;
|
||||||
|
|
||||||
return new AABB(begin, end - begin);
|
return new AABB(begin, end - begin);
|
||||||
}
|
}
|
||||||
|
@ -347,29 +347,29 @@ namespace Godot
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
real_t seg_from = from[i];
|
real_t segFrom = from[i];
|
||||||
real_t seg_to = to[i];
|
real_t segTo = to[i];
|
||||||
real_t box_begin = _position[i];
|
real_t boxBegin = _position[i];
|
||||||
real_t box_end = box_begin + _size[i];
|
real_t boxEnd = boxBegin + _size[i];
|
||||||
real_t cmin, cmax;
|
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;
|
return false;
|
||||||
|
|
||||||
real_t length = seg_to - seg_from;
|
real_t length = segTo - segFrom;
|
||||||
cmin = seg_from < box_begin ? (box_begin - seg_from) / length : 0f;
|
cmin = segFrom < boxBegin ? (boxBegin - segFrom) / length : 0f;
|
||||||
cmax = seg_to > box_end ? (box_end - seg_from) / length : 1f;
|
cmax = segTo > boxEnd ? (boxEnd - segFrom) / length : 1f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (seg_to > box_end || seg_from < box_begin)
|
if (segTo > boxEnd || segFrom < boxBegin)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
real_t length = seg_to - seg_from;
|
real_t length = segTo - segFrom;
|
||||||
cmin = seg_from > box_end ? (box_end - seg_from) / length : 0f;
|
cmin = segFrom > boxEnd ? (boxEnd - segFrom) / length : 0f;
|
||||||
cmax = seg_to < box_begin ? (box_begin - seg_from) / length : 1f;
|
cmax = segTo < boxBegin ? (boxBegin - segFrom) / length : 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmin > min)
|
if (cmin > min)
|
||||||
|
@ -388,21 +388,21 @@ namespace Godot
|
||||||
|
|
||||||
public AABB Merge(AABB with)
|
public AABB Merge(AABB with)
|
||||||
{
|
{
|
||||||
Vector3 beg_1 = _position;
|
Vector3 beg1 = _position;
|
||||||
Vector3 beg_2 = with._position;
|
Vector3 beg2 = with._position;
|
||||||
var end_1 = new Vector3(_size.x, _size.y, _size.z) + beg_1;
|
var end1 = new Vector3(_size.x, _size.y, _size.z) + beg1;
|
||||||
var end_2 = new Vector3(with._size.x, with._size.y, with._size.z) + beg_2;
|
var end2 = new Vector3(with._size.x, with._size.y, with._size.z) + beg2;
|
||||||
|
|
||||||
var min = new Vector3(
|
var min = new Vector3(
|
||||||
beg_1.x < beg_2.x ? beg_1.x : beg_2.x,
|
beg1.x < beg2.x ? beg1.x : beg2.x,
|
||||||
beg_1.y < beg_2.y ? beg_1.y : beg_2.y,
|
beg1.y < beg2.y ? beg1.y : beg2.y,
|
||||||
beg_1.z < beg_2.z ? beg_1.z : beg_2.z
|
beg1.z < beg2.z ? beg1.z : beg2.z
|
||||||
);
|
);
|
||||||
|
|
||||||
var max = new Vector3(
|
var max = new Vector3(
|
||||||
end_1.x > end_2.x ? end_1.x : end_2.x,
|
end1.x > end2.x ? end1.x : end2.x,
|
||||||
end_1.y > end_2.y ? end_1.y : end_2.y,
|
end1.y > end2.y ? end1.y : end2.y,
|
||||||
end_1.z > end_2.z ? end_1.z : end_2.z
|
end1.z > end2.z ? end1.z : end2.z
|
||||||
);
|
);
|
||||||
|
|
||||||
return new AABB(min, max - min);
|
return new AABB(min, max - min);
|
||||||
|
|
|
@ -378,51 +378,51 @@ namespace Godot
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quat Quat() {
|
public Quat Quat() {
|
||||||
real_t trace = _x[0] + _y[1] + _z[2];
|
real_t trace = _x[0] + _y[1] + _z[2];
|
||||||
|
|
||||||
if (trace > 0.0f) {
|
if (trace > 0.0f) {
|
||||||
real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
|
real_t s = Mathf.Sqrt(trace + 1.0f) * 2f;
|
||||||
real_t inv_s = 1f / s;
|
real_t inv_s = 1f / s;
|
||||||
return new Quat(
|
return new Quat(
|
||||||
(_z[1] - _y[2]) * inv_s,
|
(_z[1] - _y[2]) * inv_s,
|
||||||
(_x[2] - _z[0]) * inv_s,
|
(_x[2] - _z[0]) * inv_s,
|
||||||
(_y[0] - _x[1]) * inv_s,
|
(_y[0] - _x[1]) * inv_s,
|
||||||
s * 0.25f
|
s * 0.25f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_x[0] > _y[1] && _x[0] > _z[2]) {
|
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 s = Mathf.Sqrt(_x[0] - _y[1] - _z[2] + 1.0f) * 2f;
|
||||||
real_t inv_s = 1f / s;
|
real_t inv_s = 1f / s;
|
||||||
return new Quat(
|
return new Quat(
|
||||||
s * 0.25f,
|
s * 0.25f,
|
||||||
(_x[1] + _y[0]) * inv_s,
|
(_x[1] + _y[0]) * inv_s,
|
||||||
(_x[2] + _z[0]) * inv_s,
|
(_x[2] + _z[0]) * inv_s,
|
||||||
(_z[1] - _y[2]) * inv_s
|
(_z[1] - _y[2]) * inv_s
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_y[1] > _z[2]) {
|
if (_y[1] > _z[2]) {
|
||||||
real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
|
real_t s = Mathf.Sqrt(-_x[0] + _y[1] - _z[2] + 1.0f) * 2f;
|
||||||
real_t inv_s = 1f / s;
|
real_t inv_s = 1f / s;
|
||||||
return new Quat(
|
return new Quat(
|
||||||
(_x[1] + _y[0]) * inv_s,
|
(_x[1] + _y[0]) * inv_s,
|
||||||
s * 0.25f,
|
s * 0.25f,
|
||||||
(_y[2] + _z[1]) * inv_s,
|
(_y[2] + _z[1]) * inv_s,
|
||||||
(_x[2] - _z[0]) * inv_s
|
(_x[2] - _z[0]) * inv_s
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
|
real_t s = Mathf.Sqrt(-_x[0] - _y[1] + _z[2] + 1.0f) * 2f;
|
||||||
real_t inv_s = 1f / s;
|
real_t inv_s = 1f / s;
|
||||||
return new Quat(
|
return new Quat(
|
||||||
(_x[2] + _z[0]) * inv_s,
|
(_x[2] + _z[0]) * inv_s,
|
||||||
(_y[2] + _z[1]) * inv_s,
|
(_y[2] + _z[1]) * inv_s,
|
||||||
s * 0.25f,
|
s * 0.25f,
|
||||||
(_y[0] - _x[1]) * inv_s
|
(_y[0] - _x[1]) * inv_s
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Basis(Quat quat)
|
public Basis(Quat quat)
|
||||||
{
|
{
|
||||||
|
|
|
@ -370,12 +370,12 @@ namespace Godot
|
||||||
{
|
{
|
||||||
var txt = string.Empty;
|
var txt = string.Empty;
|
||||||
|
|
||||||
txt += _to_hex(r);
|
txt += ToHex32(r);
|
||||||
txt += _to_hex(g);
|
txt += ToHex32(g);
|
||||||
txt += _to_hex(b);
|
txt += ToHex32(b);
|
||||||
|
|
||||||
if (include_alpha)
|
if (include_alpha)
|
||||||
txt = _to_hex(a) + txt;
|
txt = ToHex32(a) + txt;
|
||||||
|
|
||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ namespace Godot
|
||||||
r = (rgba & 0xFFFF) / 65535.0f;
|
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;
|
int ig = 0;
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ namespace Godot
|
||||||
return ig;
|
return ig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _to_hex(float val)
|
private String ToHex32(float val)
|
||||||
{
|
{
|
||||||
int v = Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255));
|
int v = Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255));
|
||||||
|
|
||||||
|
@ -490,17 +490,17 @@ namespace Godot
|
||||||
|
|
||||||
if (alpha)
|
if (alpha)
|
||||||
{
|
{
|
||||||
if (_parse_col(color, 0) < 0)
|
if (ParseCol8(color, 0) < 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int from = alpha ? 2 : 0;
|
int from = alpha ? 2 : 0;
|
||||||
|
|
||||||
if (_parse_col(color, from + 0) < 0)
|
if (ParseCol8(color, from + 0) < 0)
|
||||||
return false;
|
return false;
|
||||||
if (_parse_col(color, from + 2) < 0)
|
if (ParseCol8(color, from + 2) < 0)
|
||||||
return false;
|
return false;
|
||||||
if (_parse_col(color, from + 4) < 0)
|
if (ParseCol8(color, from + 4) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -542,7 +542,7 @@ namespace Godot
|
||||||
|
|
||||||
if (alpha)
|
if (alpha)
|
||||||
{
|
{
|
||||||
a = _parse_col(rgba, 0) / 255f;
|
a = ParseCol8(rgba, 0) / 255f;
|
||||||
|
|
||||||
if (a < 0)
|
if (a < 0)
|
||||||
throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba);
|
throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba);
|
||||||
|
@ -554,17 +554,17 @@ namespace Godot
|
||||||
|
|
||||||
int from = alpha ? 2 : 0;
|
int from = alpha ? 2 : 0;
|
||||||
|
|
||||||
r = _parse_col(rgba, from + 0) / 255f;
|
r = ParseCol8(rgba, from + 0) / 255f;
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
throw new ArgumentOutOfRangeException("Invalid color code. Red part is not valid hexadecimal: " + rgba);
|
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)
|
if (g < 0)
|
||||||
throw new ArgumentOutOfRangeException("Invalid color code. Green part is not valid hexadecimal: " + rgba);
|
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)
|
if (b < 0)
|
||||||
throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba);
|
throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba);
|
||||||
|
|
|
@ -4,22 +4,22 @@ using System.Threading;
|
||||||
|
|
||||||
namespace Godot
|
namespace Godot
|
||||||
{
|
{
|
||||||
public class GodotSynchronizationContext : SynchronizationContext
|
public class GodotSynchronizationContext : SynchronizationContext
|
||||||
{
|
{
|
||||||
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
|
private readonly BlockingCollection<KeyValuePair<SendOrPostCallback, object>> queue = new BlockingCollection<KeyValuePair<SendOrPostCallback, object>>();
|
||||||
|
|
||||||
public override void Post(SendOrPostCallback d, object state)
|
public override void Post(SendOrPostCallback d, object state)
|
||||||
{
|
{
|
||||||
queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
|
queue.Add(new KeyValuePair<SendOrPostCallback, object>(d, state));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecutePendingContinuations()
|
public void ExecutePendingContinuations()
|
||||||
{
|
{
|
||||||
KeyValuePair<SendOrPostCallback, object> workItem;
|
KeyValuePair<SendOrPostCallback, object> workItem;
|
||||||
while (queue.TryTake(out workItem))
|
while (queue.TryTake(out workItem))
|
||||||
{
|
{
|
||||||
workItem.Key(workItem.Value);
|
workItem.Key(workItem.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,89 +6,89 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Godot
|
namespace Godot
|
||||||
{
|
{
|
||||||
public class GodotTaskScheduler : TaskScheduler
|
public class GodotTaskScheduler : TaskScheduler
|
||||||
{
|
{
|
||||||
private GodotSynchronizationContext Context { get; set; }
|
private GodotSynchronizationContext Context { get; set; }
|
||||||
private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
|
private readonly LinkedList<Task> _tasks = new LinkedList<Task>();
|
||||||
|
|
||||||
public GodotTaskScheduler()
|
public GodotTaskScheduler()
|
||||||
{
|
{
|
||||||
Context = new GodotSynchronizationContext();
|
Context = new GodotSynchronizationContext();
|
||||||
SynchronizationContext.SetSynchronizationContext(Context);
|
SynchronizationContext.SetSynchronizationContext(Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override void QueueTask(Task task)
|
protected sealed override void QueueTask(Task task)
|
||||||
{
|
{
|
||||||
lock (_tasks)
|
lock (_tasks)
|
||||||
{
|
{
|
||||||
_tasks.AddLast(task);
|
_tasks.AddLast(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
||||||
{
|
{
|
||||||
if (SynchronizationContext.Current != Context)
|
if (SynchronizationContext.Current != Context)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskWasPreviouslyQueued)
|
if (taskWasPreviouslyQueued)
|
||||||
{
|
{
|
||||||
TryDequeue(task);
|
TryDequeue(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TryExecuteTask(task);
|
return TryExecuteTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override bool TryDequeue(Task task)
|
protected sealed override bool TryDequeue(Task task)
|
||||||
{
|
{
|
||||||
lock (_tasks)
|
lock (_tasks)
|
||||||
{
|
{
|
||||||
return _tasks.Remove(task);
|
return _tasks.Remove(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override IEnumerable<Task> GetScheduledTasks()
|
protected sealed override IEnumerable<Task> GetScheduledTasks()
|
||||||
{
|
{
|
||||||
lock (_tasks)
|
lock (_tasks)
|
||||||
{
|
{
|
||||||
return _tasks.ToArray();
|
return _tasks.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Activate()
|
public void Activate()
|
||||||
{
|
{
|
||||||
ExecuteQueuedTasks();
|
ExecuteQueuedTasks();
|
||||||
Context.ExecutePendingContinuations();
|
Context.ExecutePendingContinuations();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteQueuedTasks()
|
private void ExecuteQueuedTasks()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Task task;
|
Task task;
|
||||||
|
|
||||||
lock (_tasks)
|
lock (_tasks)
|
||||||
{
|
{
|
||||||
if (_tasks.Any())
|
if (_tasks.Any())
|
||||||
{
|
{
|
||||||
task = _tasks.First.Value;
|
task = _tasks.First.Value;
|
||||||
_tasks.RemoveFirst();
|
_tasks.RemoveFirst();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task != null)
|
if (task != null)
|
||||||
{
|
{
|
||||||
if (!TryExecuteTask(task))
|
if (!TryExecuteTask(task))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Godot
|
||||||
return slices;
|
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)
|
if (!instance.Empty() && slice >= 0)
|
||||||
{
|
{
|
||||||
|
@ -36,12 +36,18 @@ namespace Godot
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (instance[i] == 0 || instance[i] == splitter)
|
bool end = instance.Length <= i;
|
||||||
|
|
||||||
|
if (end || instance[i] == splitter)
|
||||||
{
|
{
|
||||||
if (slice == count)
|
if (slice == count)
|
||||||
{
|
{
|
||||||
return instance.Substring(prev, i - prev);
|
return instance.Substring(prev, i - prev);
|
||||||
}
|
}
|
||||||
|
else if (end)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
prev = i + 1;
|
prev = i + 1;
|
||||||
|
@ -57,7 +63,7 @@ namespace Godot
|
||||||
// <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('.');
|
||||||
|
|
||||||
|
@ -144,7 +150,7 @@ namespace Godot
|
||||||
|
|
||||||
for (int i = 0; i < aux.GetSliceCount(" "); i++)
|
for (int i = 0; i < aux.GetSliceCount(" "); i++)
|
||||||
{
|
{
|
||||||
string slice = aux.GetSlicec(' ', i);
|
string slice = aux.GetSliceCharacter(' ', i);
|
||||||
if (slice.Length > 0)
|
if (slice.Length > 0)
|
||||||
{
|
{
|
||||||
slice = char.ToUpper(slice[0]) + slice.Substring(1);
|
slice = char.ToUpper(slice[0]) + slice.Substring(1);
|
||||||
|
@ -161,6 +167,14 @@ namespace Godot
|
||||||
// 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, 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())
|
if (instance.Empty())
|
||||||
return to.Empty() ? 0 : -1;
|
return to.Empty() ? 0 : -1;
|
||||||
|
@ -168,24 +182,45 @@ namespace Godot
|
||||||
if (to.Empty())
|
if (to.Empty())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int instance_idx = 0;
|
int instanceIndex = 0;
|
||||||
int to_idx = 0;
|
int toIndex = 0;
|
||||||
|
|
||||||
while (true)
|
if (caseSensitive) // Outside while loop to avoid checking multiple times, despite some code duplication.
|
||||||
{
|
{
|
||||||
if (to[to_idx] == 0 && instance[instance_idx] == 0)
|
while (true)
|
||||||
return 0; // We're equal
|
{
|
||||||
if (instance[instance_idx] == 0)
|
if (to[toIndex] == 0 && instance[instanceIndex] == 0)
|
||||||
return -1; // If this is empty, and the other one is not, then we're less... I think?
|
return 0; // We're equal
|
||||||
if (to[to_idx] == 0)
|
if (instance[instanceIndex] == 0)
|
||||||
return 1; // Otherwise the other one is smaller...
|
return -1; // If this is empty, and the other one is not, then we're less... I think?
|
||||||
if (instance[instance_idx] < to[to_idx]) // More than
|
if (to[toIndex] == 0)
|
||||||
return -1;
|
return 1; // Otherwise the other one is smaller...
|
||||||
if (instance[instance_idx] > to[to_idx]) // Less than
|
if (instance[instanceIndex] < to[toIndex]) // More than
|
||||||
return 1;
|
return -1;
|
||||||
|
if (instance[instanceIndex] > to[toIndex]) // Less than
|
||||||
|
return 1;
|
||||||
|
|
||||||
instance_idx++;
|
instanceIndex++;
|
||||||
to_idx++;
|
toIndex++;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
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>
|
// <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 case_insensitive)
|
public static bool IsSubsequenceOf(this string instance, string text, bool caseSensitive = true)
|
||||||
{
|
{
|
||||||
int len = instance.Length;
|
int len = instance.Length;
|
||||||
|
|
||||||
|
@ -371,50 +406,42 @@ namespace Godot
|
||||||
if (len > text.Length)
|
if (len > text.Length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int src = 0;
|
int source = 0;
|
||||||
int tgt = 0;
|
int target = 0;
|
||||||
|
|
||||||
while (instance[src] != 0 && text[tgt] != 0)
|
while (instance[source] != 0 && text[target] != 0)
|
||||||
{
|
{
|
||||||
bool match;
|
bool match;
|
||||||
|
|
||||||
if (case_insensitive)
|
if (!caseSensitive)
|
||||||
{
|
{
|
||||||
char srcc = char.ToLower(instance[src]);
|
char sourcec = char.ToLower(instance[source]);
|
||||||
char tgtc = char.ToLower(text[tgt]);
|
char targetc = char.ToLower(text[target]);
|
||||||
match = srcc == tgtc;
|
match = sourcec == targetc;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
match = instance[src] == text[tgt];
|
match = instance[source] == text[target];
|
||||||
}
|
}
|
||||||
if (match)
|
if (match)
|
||||||
{
|
{
|
||||||
src++;
|
source++;
|
||||||
if (instance[src] == 0)
|
if (instance[source] == 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tgt++;
|
target++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
// Check whether this string is a subsequence of the given string, considering case.
|
// Check whether this string is a subsequence of the given string, ignoring case differences.
|
||||||
// </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.
|
|
||||||
// </summary>
|
// </summary>
|
||||||
public static bool IsSubsequenceOfI(this string instance, string text)
|
public static bool IsSubsequenceOfI(this string instance, string text)
|
||||||
{
|
{
|
||||||
return instance.IsSubsequenceOf(text, true);
|
return instance.IsSubsequenceOf(text, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
|
@ -452,12 +479,12 @@ namespace Godot
|
||||||
return false; // Don't start with number plz
|
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] <= '9' || instance[i] >= 'a' &&
|
||||||
instance[i] <= 'z' || instance[i] >= 'A' &&
|
instance[i] <= 'z' || instance[i] >= 'A' &&
|
||||||
instance[i] <= 'Z' || instance[i] == '_';
|
instance[i] <= 'Z' || instance[i] == '_';
|
||||||
|
|
||||||
if (!valid_char)
|
if (!validChar)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,8 +503,9 @@ namespace Godot
|
||||||
// <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
|
||||||
string[] ip = instance.Split(".");
|
string[] ip = instance.Split(".");
|
||||||
|
|
||||||
if (ip.Length != 4)
|
if (ip.Length != 4)
|
||||||
|
@ -500,7 +528,7 @@ namespace Godot
|
||||||
// <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));
|
||||||
|
|
||||||
|
@ -563,15 +591,15 @@ 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 [method expr_match]).
|
||||||
// </summary>
|
// </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>
|
// <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 [method expr_match]).
|
||||||
// </summary>
|
// </summary>
|
||||||
public static bool Matchn(this string instance, string expr)
|
public static bool MatchN(this string instance, string expr)
|
||||||
{
|
{
|
||||||
return instance.ExprMatch(expr, false);
|
return instance.ExprMatch(expr, false);
|
||||||
}
|
}
|
||||||
|
@ -579,7 +607,7 @@ namespace Godot
|
||||||
// <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 NativeCalls.godot_icall_String_md5_buffer(instance);
|
return NativeCalls.godot_icall_String_md5_buffer(instance);
|
||||||
}
|
}
|
||||||
|
@ -587,7 +615,7 @@ namespace Godot
|
||||||
// <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 NativeCalls.godot_icall_String_md5_text(instance);
|
return NativeCalls.godot_icall_String_md5_text(instance);
|
||||||
}
|
}
|
||||||
|
@ -597,31 +625,7 @@ namespace Godot
|
||||||
// </summary>
|
// </summary>
|
||||||
public static int NocasecmpTo(this string instance, string to)
|
public static int NocasecmpTo(this string instance, string to)
|
||||||
{
|
{
|
||||||
if (instance.Empty())
|
return instance.CompareTo(to, false);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
|
@ -738,7 +742,7 @@ namespace Godot
|
||||||
// <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);
|
||||||
}
|
}
|
||||||
|
@ -746,7 +750,7 @@ namespace Godot
|
||||||
// <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 NativeCalls.godot_icall_String_rfind(instance, what, from);
|
return NativeCalls.godot_icall_String_rfind(instance, what, from);
|
||||||
}
|
}
|
||||||
|
@ -754,7 +758,7 @@ namespace Godot
|
||||||
// <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. Also search case-insensitive.
|
||||||
// </summary>
|
// </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);
|
return NativeCalls.godot_icall_String_rfindn(instance, what, from);
|
||||||
}
|
}
|
||||||
|
@ -773,7 +777,7 @@ namespace Godot
|
||||||
return instance.Substring(pos, instance.Length - pos);
|
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);
|
return NativeCalls.godot_icall_String_sha256_buffer(instance);
|
||||||
}
|
}
|
||||||
|
@ -781,7 +785,7 @@ namespace Godot
|
||||||
// <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 NativeCalls.godot_icall_String_sha256_text(instance);
|
return NativeCalls.godot_icall_String_sha256_text(instance);
|
||||||
}
|
}
|
||||||
|
@ -802,20 +806,20 @@ namespace Godot
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] srcBigrams = instance.Bigrams();
|
string[] sourceBigrams = instance.Bigrams();
|
||||||
string[] tgtBigrams = text.Bigrams();
|
string[] targetBigrams = text.Bigrams();
|
||||||
|
|
||||||
int src_size = srcBigrams.Length;
|
int sourceSize = sourceBigrams.Length;
|
||||||
int tgt_size = tgtBigrams.Length;
|
int targetSize = targetBigrams.Length;
|
||||||
|
|
||||||
float sum = src_size + tgt_size;
|
float sum = sourceSize + targetSize;
|
||||||
float inter = 0;
|
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++;
|
inter++;
|
||||||
break;
|
break;
|
||||||
|
@ -829,7 +833,7 @@ namespace Godot
|
||||||
// <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. Example "One,Two,Three" will return ["One","Two","Three"] if split by ",".
|
||||||
// </summary>
|
// </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);
|
return instance.Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
}
|
}
|
||||||
|
@ -837,7 +841,7 @@ namespace Godot
|
||||||
// <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. Example "1,2.5,3" will return [1,2.5,3] if split by ",".
|
||||||
// </summary>
|
// </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>();
|
var ret = new List<float>();
|
||||||
int from = 0;
|
int from = 0;
|
||||||
|
@ -848,7 +852,7 @@ namespace Godot
|
||||||
int end = instance.Find(divisor, from);
|
int end = instance.Find(divisor, from);
|
||||||
if (end < 0)
|
if (end < 0)
|
||||||
end = len;
|
end = len;
|
||||||
if (allow_empty || end > from)
|
if (allowEmpty || end > from)
|
||||||
ret.Add(float.Parse(instance.Substring(from)));
|
ret.Add(float.Parse(instance.Substring(from)));
|
||||||
if (end == len)
|
if (end == len)
|
||||||
break;
|
break;
|
||||||
|
@ -859,7 +863,7 @@ namespace Godot
|
||||||
return ret.ToArray();
|
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)00, (char)01, (char)02, (char)03, (char)04, (char)05,
|
||||||
(char)06, (char)07, (char)08, (char)09, (char)10, (char)11,
|
(char)06, (char)07, (char)08, (char)09, (char)10, (char)11,
|
||||||
(char)12, (char)13, (char)14, (char)15, (char)16, (char)17,
|
(char)12, (char)13, (char)14, (char)15, (char)16, (char)17,
|
||||||
|
@ -876,11 +880,11 @@ namespace Godot
|
||||||
if (left)
|
if (left)
|
||||||
{
|
{
|
||||||
if (right)
|
if (right)
|
||||||
return instance.Trim(non_printable);
|
return instance.Trim(_nonPrintable);
|
||||||
return instance.TrimStart(non_printable);
|
return instance.TrimStart(_nonPrintable);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance.TrimEnd(non_printable);
|
return instance.TrimEnd(_nonPrintable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
|
@ -934,7 +938,7 @@ namespace Godot
|
||||||
// <summary>
|
// <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().
|
// 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>
|
// </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);
|
||||||
}
|
}
|
||||||
|
@ -942,7 +946,7 @@ namespace Godot
|
||||||
// <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);
|
||||||
}
|
}
|
||||||
|
@ -950,7 +954,7 @@ namespace Godot
|
||||||
// <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 according to the XML standard.
|
||||||
// </summary>
|
// </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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue