Skip to content

Commit

Permalink
Fixed prettier and replaced deprecated substr() method
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral committed Sep 7, 2023
1 parent 94304cd commit a223c2a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/stdlib/String.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { BrsType, Callable, ValueKind, BrsString, Int32, Float, StdlibArgument, BrsInvalid } from "../brsTypes";
import * as Expr from "../parser/Expression";
import {
Callable,
ValueKind,
BrsString,
Int32,
Float,
StdlibArgument,
BrsInvalid,
} from "../brsTypes";
import { Interpreter } from "../interpreter";
import { BrsNumber } from "../brsTypes/BrsNumber";
import { Lexeme } from "../lexer";

/** Converts the string to all uppercase. */
export const UCase = new Callable("UCase", {
Expand Down Expand Up @@ -61,7 +67,7 @@ export const Left = new Callable("Left", {
returns: ValueKind.String,
},
impl: (interpreter: Interpreter, s: BrsString, n: Int32) =>
new BrsString(s.value.substr(0, n.getValue())),
new BrsString(s.value.slice(0, n.getValue())),
});

/**
Expand All @@ -73,12 +79,8 @@ export const Right = new Callable("Right", {
returns: ValueKind.String,
},
impl: (interpreter: Interpreter, s: BrsString, n: Int32) => {
let end = s.value.length - 1;
let start = end - (n.getValue() - 1);

if (n.getValue() <= 0) return new BrsString("");
else if (start < 0) return new BrsString(s.value);
return new BrsString(s.value.substr(start, end));
return new BrsString(s.value.slice(-n.getValue()));
},
});

Expand Down

0 comments on commit a223c2a

Please sign in to comment.