Add more string functions (#911)

* Add more string functions

* add doc strings from std.mi

* fix strleft
This commit is contained in:
jberg 2019-09-10 09:27:10 -07:00 committed by GitHub
parent 54c5adc0b3
commit 6f7cb02bf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 20 deletions

View file

@ -91,7 +91,6 @@ describe("Maki classes", () => {
test("Track unimplemented methods", () => {
expect(unimplementedRuntimeMethods).toMatchInlineSnapshot(`
Set {
"System.gettoken",
"System.getparam",
"System.getskinname",
"System.getplayitemstring",
@ -121,10 +120,6 @@ Set {
"System.seteqband",
"System.seteqpreamp",
"System.seteq",
"System.strmid",
"System.strleft",
"System.strright",
"System.strsearch",
"System.removepath",
"System.getpath",
"System.getextension",

View file

@ -52,9 +52,13 @@ class System extends MakiObject {
return "5.666";
}
gettoken(str: string, separator: string, tokennum: number) {
unimplementedWarning("gettoken");
return "Some Token String";
// Retreive a token from a list of tokens seperated by separator.
gettoken(str: string, separator: string, tokennum: number): string {
const tokens = str.split(separator);
if (tokens.length > tokennum) {
return tokens[tokennum];
}
return "";
}
getparam() {
@ -514,24 +518,29 @@ class System extends MakiObject {
return Math.floor(Date.now() / 1000);
}
strmid(str: string, start: number, len: number) {
unimplementedWarning("strmid");
return;
// Get a substring from a string.
strmid(str: string, start: number, len: number): string {
return str.substring(start, start + len);
}
strleft(str: string, nchars: number) {
unimplementedWarning("strleft");
return;
// Get a substring from a string, starting from the left.
strleft(str: string, nchars: number): string {
return str.substring(0, nchars);
}
strright(str: string, nchars: number) {
unimplementedWarning("strright");
return;
// Get a substring from a string, starting from the right. Since
// the start point is the right of the string (or the end). It will
// extract the string starting from the END going towards the BEGINNING.
strright(str: string, nchars: number): string {
return str.substring(str.length - nchars);
}
strsearch(str: string, substr: string) {
unimplementedWarning("strsearch");
return;
// Search a string for any occurance of substring. If the substring was
// found in the string, it will return the position of the substring in
// the string searched. If the substring is not found, the return value
// is -1.
strsearch(str: string, substr: string): number {
return str.indexOf(substr);
}
strlen(str: string): number {