From e9b3c85e840a31085faa824c337110290bedd350 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 02:31:35 -0400 Subject: [PATCH 01/10] fix length() --- OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 3b041fea67..ebc6f04dda 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -1594,7 +1594,7 @@ public static DreamValue NativeProc_json_encode(NativeProc.Bundle bundle, DreamO public static DreamValue _length(DreamValue value, bool countBytes) { if (value.TryGetValueAsString(out var str)) { - return new DreamValue(countBytes ? str.Length : str.EnumerateRunes().Count()); + return new DreamValue(countBytes ? Encoding.UTF8.GetByteCount(str) : str.EnumerateRunes().Count()); } else if (value.TryGetValueAsDreamList(out var list)) { return new DreamValue(list.GetLength()); } else if (value.Type is DreamValueType.Float or DreamValueType.DreamObject or DreamValueType.DreamType) { From ade1cf5fd4a95719ad2577e0d7549155210d6c19 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 02:46:33 -0400 Subject: [PATCH 02/10] fix splittext, add splittext_char, fix length() --- .../Procs/Native/DreamProcNative.cs | 1 + .../Procs/Native/DreamProcNativeRoot.cs | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNative.cs b/OpenDreamRuntime/Procs/Native/DreamProcNative.cs index a8b2a1131a..0367db436d 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNative.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNative.cs @@ -96,6 +96,7 @@ public static void SetupNativeProcs(DreamObjectTree objectTree) { objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_splicetext); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_splicetext_char); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_splittext); + objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_splittext_char); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_stat); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_statpanel); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_text2ascii); diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index ebc6f04dda..749b9996ac 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -2779,30 +2779,46 @@ public static DreamValue NativeProc_splicetext_char(NativeProc.Bundle bundle, Dr [DreamProcParameter("End", Type = DreamValueTypeFlag.Float, DefaultValue = 0)] [DreamProcParameter("include_delimiters", Type = DreamValueTypeFlag.Float, DefaultValue = 0)] public static DreamValue NativeProc_splittext(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) { + return SplitText(bundle, src, usr, true); + } + + [DreamProc("splittext_char")] + [DreamProcParameter("Text", Type = DreamValueTypeFlag.String)] + [DreamProcParameter("Delimiter", Type = DreamValueTypeFlag.String)] + [DreamProcParameter("Start", Type = DreamValueTypeFlag.Float, DefaultValue = 1)] + [DreamProcParameter("End", Type = DreamValueTypeFlag.Float, DefaultValue = 0)] + [DreamProcParameter("include_delimiters", Type = DreamValueTypeFlag.Float, DefaultValue = 0)] + public static DreamValue NativeProc_splittext_char(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) { + return SplitText(bundle, src, usr, false); + } + + private static DreamValue SplitText(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr, bool useByteLength) { if (!bundle.GetArgument(0, "Text").TryGetValueAsString(out var text)) { return new DreamValue(bundle.ObjectTree.CreateList()); } + int consideredLength = useByteLength ? Encoding.UTF8.GetByteCount(text) : text.EnumerateRunes().Count(); int start = 0; int end = 0; - if(bundle.GetArgument(2, "Start").TryGetValueAsInteger(out start)) + if (bundle.GetArgument(2, "Start").TryGetValueAsInteger(out start)) start -= 1; //1-indexed - if(bundle.GetArgument(3, "End").TryGetValueAsInteger(out end)) - if(end == 0) - end = text.Length; + if (bundle.GetArgument(3, "End").TryGetValueAsInteger(out end)) + if (end == 0) + end = consideredLength; else end -= 1; //1-indexed + bool includeDelimiters = false; - if(bundle.GetArgument(4, "include_delimiters").TryGetValueAsInteger(out var includeDelimitersInt)) + if (bundle.GetArgument(4, "include_delimiters").TryGetValueAsInteger(out var includeDelimitersInt)) includeDelimiters = includeDelimitersInt != 0; //idk why BYOND doesn't just use truthiness, but it doesn't, so... - if(start > 0 || end < text.Length) - text = text[Math.Max(start,0)..Math.Min(end, text.Length)]; + if (start > 0 || end < consideredLength) + text = text[Math.Max(start, 0)..Math.Min(end, consideredLength)]; var delim = bundle.GetArgument(1, "Delimiter"); //can either be a regex or string if (delim.TryGetValueAsDreamObject(out var regexObject)) { - if(includeDelimiters) { + if (includeDelimiters) { var values = new List(); int pos = 0; foreach (Match m in regexObject.Regex.Matches(text)) { @@ -2818,13 +2834,13 @@ public static DreamValue NativeProc_splittext(NativeProc.Bundle bundle, DreamObj } } else if (delim.TryGetValueAsString(out var delimiter)) { string[] splitText; - if(includeDelimiters) { + if (includeDelimiters) { //basically split on delimeter, and then add the delimiter back in after each split (except the last one) - splitText= text.Split(delimiter); + splitText = text.Split(delimiter); string[] longerSplitText = new string[splitText.Length * 2 - 1]; - for(int i = 0; i < splitText.Length; i++) { + for (int i = 0; i < splitText.Length; i++) { longerSplitText[i * 2] = splitText[i]; - if(i < splitText.Length - 1) + if (i < splitText.Length - 1) longerSplitText[i * 2 + 1] = delimiter; } From f45239043c7b5fbeb81df49155fe60c6d2b6775c Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 04:07:20 -0400 Subject: [PATCH 03/10] copytext and copytext_char --- .../Procs/Native/DreamProcNativeRoot.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 749b9996ac..780a5e1a93 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -630,13 +630,13 @@ public static DreamValue NativeProc_copytext(NativeProc.Bundle bundle, DreamObje if (!bundle.GetArgument(1, "Start").TryGetValueAsInteger(out int start)) //1-indexed return new DreamValue(""); - if (end <= 0) end += text.Length + 1; - else if (end > text.Length + 1) end = text.Length + 1; + var textAsBytes = Encoding.UTF8.GetBytes(text); + if (end <= 0) end += textAsBytes.Length + 1; + else if (end > textAsBytes.Length + 1) end = textAsBytes.Length + 1; if (start == 0) return new DreamValue(""); - else if (start < 0) start += text.Length + 1; - - return new DreamValue(text.Substring(start - 1, end - start)); + else if (start < 0) start += textAsBytes.Length + 1; + return new DreamValue(Encoding.UTF8.GetString(new ArraySegment(textAsBytes, start - 1, end - start))); } [DreamProc("copytext_char")] @@ -651,18 +651,24 @@ public static DreamValue NativeProc_copytext_char(NativeProc.Bundle bundle, Drea if (!bundle.GetArgument(1, "Start").TryGetValueAsInteger(out int start)) //1-indexed return new DreamValue(""); - StringInfo textElements = new StringInfo(text); + ; + + Rune[] runes = text.EnumerateRunes().ToArray(); - if (end <= 0) end += textElements.LengthInTextElements + 1; - else if (end > textElements.LengthInTextElements + 1) end = textElements.LengthInTextElements + 1; + if (end <= 0) end += runes.Length + 1; + else if (end > runes.Length + 1) end = runes.Length + 1; if (start == 0) return new DreamValue(""); - else if (start < 0) start += textElements.LengthInTextElements + 1; + else if (start < 0) start += runes.Length + 1; - if (start > textElements.LengthInTextElements) - return new(string.Empty); + if (start > runes.Length) + return new DreamValue(string.Empty); - return new DreamValue(textElements.SubstringByTextElements(start - 1, end - start)); + var stringBuilder = new StringBuilder(); + for (int i = start - 1; i < end - 1; i++) { + stringBuilder.Append(runes[i].ToString()); + } + return new DreamValue(stringBuilder.ToString()); } [DreamProc("CRASH")] From 8b6172d72e75b790f78328f69122f890393fdd3b Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 04:20:36 -0400 Subject: [PATCH 04/10] text helpers --- .../Procs/Native/DreamProcNativeRoot.cs | 7 ++----- OpenDreamRuntime/Util/TextHelpers.cs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 OpenDreamRuntime/Util/TextHelpers.cs diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 780a5e1a93..2890df041d 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -25,6 +25,7 @@ using Robust.Server; using Robust.Shared.Asynchronous; using Vector4 = Robust.Shared.Maths.Vector4; +using OpenDreamRuntime.Util; namespace OpenDreamRuntime.Procs.Native; @@ -664,11 +665,7 @@ public static DreamValue NativeProc_copytext_char(NativeProc.Bundle bundle, Drea if (start > runes.Length) return new DreamValue(string.Empty); - var stringBuilder = new StringBuilder(); - for (int i = start - 1; i < end - 1; i++) { - stringBuilder.Append(runes[i].ToString()); - } - return new DreamValue(stringBuilder.ToString()); + return new DreamValue(TextHelpers.RuneSubstring(runes, start - 1, end - 1)); } [DreamProc("CRASH")] diff --git a/OpenDreamRuntime/Util/TextHelpers.cs b/OpenDreamRuntime/Util/TextHelpers.cs new file mode 100644 index 0000000000..c14579f8e7 --- /dev/null +++ b/OpenDreamRuntime/Util/TextHelpers.cs @@ -0,0 +1,17 @@ +using System.Text; + +namespace OpenDreamRuntime.Util; + +public static class TextHelpers { + // Like string.Substring(), but takes an array of runes instead. + public static string RuneSubstring(Rune[] runes, int start, int end) { + if (start < 0) throw new ArgumentOutOfRangeException("Start position is less than zero"); + if (end < 0 || end > runes.Length) throw new ArgumentOutOfRangeException("End position is not within array size"); + + var stringBuilder = new StringBuilder(); + for (int i = start; i < end; i++) { + stringBuilder.Append(runes[i].ToString()); + } + return stringBuilder.ToString(); + } +} From e4d676d77768fe485aa8f3596c68ebf991e8eaae Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 20:36:29 -0400 Subject: [PATCH 05/10] revert back to chars --- OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 2890df041d..c883d2ea3b 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -1597,7 +1597,7 @@ public static DreamValue NativeProc_json_encode(NativeProc.Bundle bundle, DreamO public static DreamValue _length(DreamValue value, bool countBytes) { if (value.TryGetValueAsString(out var str)) { - return new DreamValue(countBytes ? Encoding.UTF8.GetByteCount(str) : str.EnumerateRunes().Count()); + return new DreamValue(countBytes ? str.Length : str.EnumerateRunes().Count()); } else if (value.TryGetValueAsDreamList(out var list)) { return new DreamValue(list.GetLength()); } else if (value.Type is DreamValueType.Float or DreamValueType.DreamObject or DreamValueType.DreamType) { @@ -2800,7 +2800,7 @@ private static DreamValue SplitText(NativeProc.Bundle bundle, DreamObject? src, return new DreamValue(bundle.ObjectTree.CreateList()); } - int consideredLength = useByteLength ? Encoding.UTF8.GetByteCount(text) : text.EnumerateRunes().Count(); + int consideredLength = useByteLength ? text.Length : text.EnumerateRunes().Count(); int start = 0; int end = 0; if (bundle.GetArgument(2, "Start").TryGetValueAsInteger(out start)) From 003cf0cbd02f67834a2f51b88c146a31f2b5b7e1 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 20:40:04 -0400 Subject: [PATCH 06/10] revert copytext --- OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index c883d2ea3b..be103fb09e 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -631,13 +631,13 @@ public static DreamValue NativeProc_copytext(NativeProc.Bundle bundle, DreamObje if (!bundle.GetArgument(1, "Start").TryGetValueAsInteger(out int start)) //1-indexed return new DreamValue(""); - var textAsBytes = Encoding.UTF8.GetBytes(text); - if (end <= 0) end += textAsBytes.Length + 1; - else if (end > textAsBytes.Length + 1) end = textAsBytes.Length + 1; + if (end <= 0) end += text.Length + 1; + else if (end > text.Length + 1) end = text.Length + 1; if (start == 0) return new DreamValue(""); - else if (start < 0) start += textAsBytes.Length + 1; - return new DreamValue(Encoding.UTF8.GetString(new ArraySegment(textAsBytes, start - 1, end - start))); + else if (start < 0) start += text.Length + 1; + + return new DreamValue(text.Substring(start - 1, end - start)); } [DreamProc("copytext_char")] From 3ac588e32f985b41a27ee2d45e4e4c315bfa8b09 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 20:53:23 -0400 Subject: [PATCH 07/10] splicetext_char -> runes --- .../Procs/Native/DreamProcNativeRoot.cs | 21 ++++++++++--------- OpenDreamRuntime/Util/TextHelpers.cs | 6 +++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index be103fb09e..74d5fdd34e 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -2755,22 +2755,23 @@ public static DreamValue NativeProc_splicetext_char(NativeProc.Bundle bundle, Dr else if(text == "") return new DreamValue(insertText); + Rune[] runes = text.EnumerateRunes().ToArray(); + //runtime if start = 0 runtime error: bad text or out of bounds - StringInfo textElements = new StringInfo(text); - if(end == 0 || end > textElements.LengthInTextElements + 1) - end = textElements.LengthInTextElements+1; + if (end == 0 || end > runes.Length + 1) + end = runes.Length + 1; if(start < 0) - start = Math.Max(start + textElements.LengthInTextElements + 1, 1); + start = Math.Max(start + runes.Length + 1, 1); if(end < 0) - end = Math.Min(end + textElements.LengthInTextElements + 1, textElements.LengthInTextElements); + end = Math.Min(end + runes.Length + 1, runes.Length); - if(start == 0 || start > textElements.LengthInTextElements || start > end) - throw new Exception("bad text or out of bounds"); + if(start == 0 || start > runes.Length || start > end) + throw new ArgumentException("bad text or out of bounds"); - string result = textElements.SubstringByTextElements(0, start - 1); + string result = TextHelpers.RuneSubstring(runes, 0, start - 1); result += insertText; - if(end <= textElements.LengthInTextElements) - result += textElements.SubstringByTextElements(end - 1); + if(end <= runes.Length) + result += TextHelpers.RuneSubstring(runes, end - 1, 0); return new DreamValue(result); } diff --git a/OpenDreamRuntime/Util/TextHelpers.cs b/OpenDreamRuntime/Util/TextHelpers.cs index c14579f8e7..24ab59b50a 100644 --- a/OpenDreamRuntime/Util/TextHelpers.cs +++ b/OpenDreamRuntime/Util/TextHelpers.cs @@ -3,11 +3,15 @@ namespace OpenDreamRuntime.Util; public static class TextHelpers { - // Like string.Substring(), but takes an array of runes instead. + // Returns a slice of a rune array as a string. public static string RuneSubstring(Rune[] runes, int start, int end) { if (start < 0) throw new ArgumentOutOfRangeException("Start position is less than zero"); if (end < 0 || end > runes.Length) throw new ArgumentOutOfRangeException("End position is not within array size"); + if (end == 0) { + end = runes.Length; + } + var stringBuilder = new StringBuilder(); for (int i = start; i < end; i++) { stringBuilder.Append(runes[i].ToString()); From 9815d4b2c402a9a83b644c23a1015f2ac0ab77d4 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 20:57:47 -0400 Subject: [PATCH 08/10] text2ascii_char --- OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 74d5fdd34e..621807fae5 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -2934,17 +2934,17 @@ public static DreamValue NativeProc_text2ascii_char(NativeProc.Bundle bundle, Dr return new DreamValue(0); } - StringInfo textElements = new StringInfo(text); + Rune[] runes = text.EnumerateRunes().ToArray(); bundle.GetArgument(1, "pos").TryGetValueAsInteger(out var pos); //1-indexed if (pos == 0) pos = 1; //0 is same as 1 - else if (pos < 0) pos += textElements.LengthInTextElements + 1; //Wraps around + else if (pos < 0) pos += runes.Length + 1; //Wraps around - if (pos > textElements.LengthInTextElements || pos < 1) { + if (pos > runes.Length || pos < 1) { return new DreamValue(0); } else { //practically identical to (our) text2ascii but more explicit about subchar indexing - return new DreamValue((int)textElements.SubstringByTextElements(pos - 1, 1)[0]); + return new DreamValue((int)runes[pos].ToString()[0]); } } From b57ee3973ed6b8c9f3cc0ffddfa01bbf61ffd43a Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 21:07:06 -0400 Subject: [PATCH 09/10] spantext_char --- .../Procs/Native/DreamProcNativeRoot.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 621807fae5..7d501133d0 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -2656,24 +2656,24 @@ public static DreamValue NativeProc_spantext_char(NativeProc.Bundle bundle, Drea return new DreamValue(0); } - StringInfo textStringInfo = new StringInfo(text); + Rune[] runes = text.EnumerateRunes().ToArray(); if(start < 0) { - start = Math.Max(start + textStringInfo.LengthInTextElements + 1, 1); + start = Math.Max(start + runes.Length + 1, 1); } int result = 0; - TextElementEnumerator needlesElementEnumerator = StringInfo.GetTextElementEnumerator(needles); - TextElementEnumerator textElementEnumerator = StringInfo.GetTextElementEnumerator(text, start - 1); + IEnumerator needlesRuneEnumerator = needles.EnumerateRunes(); + IEnumerator textElementEnumerator = TextHelpers.RuneSubstring(runes, start - 1, 0).EnumerateRunes(); while(textElementEnumerator.MoveNext()) { bool found = false; - needlesElementEnumerator.Reset(); + needlesRuneEnumerator.Reset(); //lol O(N*M) - while (needlesElementEnumerator.MoveNext()) { - if (textElementEnumerator.Current.Equals(needlesElementEnumerator.Current)) { + while (needlesRuneEnumerator.MoveNext()) { + if (textElementEnumerator.Current.Equals(textElementEnumerator.Current)) { result++; found = true; break; From 79a09104c87ae77d9acc270b3fca149e0380ed31 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 22 Jul 2025 21:19:22 -0400 Subject: [PATCH 10/10] fix --- OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index 7d501133d0..75bbdf6f1f 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -2665,15 +2665,15 @@ public static DreamValue NativeProc_spantext_char(NativeProc.Bundle bundle, Drea int result = 0; IEnumerator needlesRuneEnumerator = needles.EnumerateRunes(); - IEnumerator textElementEnumerator = TextHelpers.RuneSubstring(runes, start - 1, 0).EnumerateRunes(); + IEnumerator textRuneEnumerator = TextHelpers.RuneSubstring(runes, start - 1, 0).EnumerateRunes(); - while(textElementEnumerator.MoveNext()) { + while(textRuneEnumerator.MoveNext()) { bool found = false; needlesRuneEnumerator.Reset(); //lol O(N*M) while (needlesRuneEnumerator.MoveNext()) { - if (textElementEnumerator.Current.Equals(textElementEnumerator.Current)) { + if (textRuneEnumerator.Current.Equals(needlesRuneEnumerator.Current)) { result++; found = true; break;