mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Добавлены функции parseInt, parseLong
This commit is contained in:
parent
cd90045fd2
commit
d40c4d5284
@ -0,0 +1,20 @@
|
|||||||
|
package com.annimon.ownlang.modules.std;
|
||||||
|
|
||||||
|
import com.annimon.ownlang.lib.Arguments;
|
||||||
|
import com.annimon.ownlang.lib.NumberValue;
|
||||||
|
import com.annimon.ownlang.lib.Value;
|
||||||
|
|
||||||
|
public final class StringFunctions {
|
||||||
|
|
||||||
|
public static Value parseInt(Value... args) {
|
||||||
|
Arguments.checkOrOr(1, 2, args.length);
|
||||||
|
final int radix = (args.length == 2) ? args[1].asInt() : 10;
|
||||||
|
return NumberValue.of(Integer.parseInt(args[0].asString(), radix));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Value parseLong(Value... args) {
|
||||||
|
Arguments.checkOrOr(1, 2, args.length);
|
||||||
|
final int radix = (args.length == 2) ? args[1].asInt() : 10;
|
||||||
|
return NumberValue.of(Long.parseLong(args[0].asString(), radix));
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,6 @@ public final class std implements Module {
|
|||||||
// String
|
// String
|
||||||
Functions.set("sprintf", new std_sprintf());
|
Functions.set("sprintf", new std_sprintf());
|
||||||
Functions.set("split", new std_split());
|
Functions.set("split", new std_split());
|
||||||
Functions.set("join", new std_join());
|
|
||||||
Functions.set("indexOf", new std_indexof());
|
Functions.set("indexOf", new std_indexof());
|
||||||
Functions.set("lastIndexOf", new std_lastindexof());
|
Functions.set("lastIndexOf", new std_lastindexof());
|
||||||
Functions.set("charAt", new std_charat());
|
Functions.set("charAt", new std_charat());
|
||||||
@ -42,9 +41,12 @@ public final class std implements Module {
|
|||||||
Functions.set("replace", new std_replace());
|
Functions.set("replace", new std_replace());
|
||||||
Functions.set("replaceAll", new std_replaceall());
|
Functions.set("replaceAll", new std_replaceall());
|
||||||
Functions.set("replaceFirst", new std_replacefirst());
|
Functions.set("replaceFirst", new std_replacefirst());
|
||||||
|
Functions.set("parseInt", StringFunctions::parseInt);
|
||||||
|
Functions.set("parseLong", StringFunctions::parseLong);
|
||||||
|
|
||||||
// Arrays and maps
|
// Arrays and maps
|
||||||
Functions.set("newarray", new std_newarray());
|
Functions.set("newarray", new std_newarray());
|
||||||
|
Functions.set("join", new std_join());
|
||||||
Functions.set("sort", new std_sort());
|
Functions.set("sort", new std_sort());
|
||||||
Functions.set("arrayCombine", new std_arrayCombine());
|
Functions.set("arrayCombine", new std_arrayCombine());
|
||||||
Functions.set("arrayKeyExists", new std_arrayKeyExists());
|
Functions.set("arrayKeyExists", new std_arrayKeyExists());
|
||||||
|
Loading…
Reference in New Issue
Block a user