Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements most _char procs and findlastextEx() #358

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions DMCompiler/DMStandard/_Standard.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ proc/file2text(File)
proc/findtext(Haystack, Needle, Start = 1, End = 0)
proc/findtextEx(Haystack, Needle, Start = 1, End = 0)
proc/findlasttext(Haystack, Needle, Start = 1, End = 0)
proc/findlasttextEx(Haystack, Needle, Start = 1, End = 0)
proc/flick(Icon, Object)
proc/flist(Path)
proc/hascall(Object, ProcName)
Expand Down Expand Up @@ -269,9 +270,27 @@ proc/jointext(list/List, Glue, Start = 1, End = 0)

return List.Join(Glue, Start, End)

proc/copytext_char(T,Start=1,End=0)
return copytext(T, Start, End)

proc/length_char(E)
return length(E)

proc/lentext(T)
return length(T)

proc/text2ascii_char(T,pos=1)
return text2ascii(T,pos)

proc/findtext_char(Haystack,Needle,Start=1,End=0)
return findtext(Haystack,Needle,Start,End)

proc/findlasttext_char(Haystack,Needle,Start=0,End=1)
return findlasttext(Haystack,Needle,Start,End)

proc/findlasttextEx_char(Haystack,Needle,Start=0,End=1)
return findlasttextEx(Haystack,Needle,Start,End)

proc/isobj(Loc1)
for(var/arg in args)
if (!istype(arg, /obj)) return 0
Expand Down
25 changes: 24 additions & 1 deletion OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static DreamValue NativeProc_findtextEx(DreamObject instance, DreamObject
end = text.Length + 1;
}

int needleIndex = text.IndexOf(needle, start - 1, end - start);
int needleIndex = text.IndexOf(needle, start - 1, end - start, StringComparison.OrdinalIgnoreCase);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is necessary but findtext() includes it so...

if (needleIndex != -1) {
return new DreamValue(needleIndex + 1); //1-indexed
} else {
Expand Down Expand Up @@ -364,6 +364,29 @@ public static DreamValue NativeProc_findlasttext(DreamObject instance, DreamObje
}
}

[DreamProc("findlasttextEx")]
[DreamProcParameter("Haystack", Type = DreamValueType.String)]
[DreamProcParameter("Needle", Type = DreamValueType.String)]
[DreamProcParameter("Start", Type = DreamValueType.Float, DefaultValue = 1)]
[DreamProcParameter("End", Type = DreamValueType.Float, DefaultValue = 0)]
public static DreamValue NativeProc_findlasttextEx(DreamObject instance, DreamObject usr, DreamProcArguments arguments) {
string text = arguments.GetArgument(0, "Haystack").GetValueAsString();
string needle = arguments.GetArgument(1, "Needle").GetValueAsString();
int start = arguments.GetArgument(2, "Start").GetValueAsInteger(); //1-indexed
int end = arguments.GetArgument(3, "End").GetValueAsInteger(); //1-indexed

if (end == 0) {
end = text.Length + 1;
}

int needleIndex = text.LastIndexOf(needle, end - 1, end - start);
if (needleIndex != -1) {
return new DreamValue(needleIndex + 1); //1-indexed
} else {
return new DreamValue(0);
}
}

[DreamProc("flick")]
[DreamProcParameter("Icon", Type = DreamValueType.String | DreamValueType.DreamResource)]
[DreamProcParameter("Object", Type = DreamValueType.String | DreamValueType.DreamResource)]
Expand Down