Skip to content

Commit d40c4d5

Browse files
committed
Добавлены функции parseInt, parseLong
1 parent cd90045 commit d40c4d5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.annimon.ownlang.modules.std;
2+
3+
import com.annimon.ownlang.lib.Arguments;
4+
import com.annimon.ownlang.lib.NumberValue;
5+
import com.annimon.ownlang.lib.Value;
6+
7+
public final class StringFunctions {
8+
9+
public static Value parseInt(Value... args) {
10+
Arguments.checkOrOr(1, 2, args.length);
11+
final int radix = (args.length == 2) ? args[1].asInt() : 10;
12+
return NumberValue.of(Integer.parseInt(args[0].asString(), radix));
13+
}
14+
15+
public static Value parseLong(Value... args) {
16+
Arguments.checkOrOr(1, 2, args.length);
17+
final int radix = (args.length == 2) ? args[1].asInt() : 10;
18+
return NumberValue.of(Long.parseLong(args[0].asString(), radix));
19+
}
20+
}

src/main/java/com/annimon/ownlang/modules/std/std.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public void init() {
3030
// String
3131
Functions.set("sprintf", new std_sprintf());
3232
Functions.set("split", new std_split());
33-
Functions.set("join", new std_join());
3433
Functions.set("indexOf", new std_indexof());
3534
Functions.set("lastIndexOf", new std_lastindexof());
3635
Functions.set("charAt", new std_charat());
@@ -42,9 +41,12 @@ public void init() {
4241
Functions.set("replace", new std_replace());
4342
Functions.set("replaceAll", new std_replaceall());
4443
Functions.set("replaceFirst", new std_replacefirst());
45-
44+
Functions.set("parseInt", StringFunctions::parseInt);
45+
Functions.set("parseLong", StringFunctions::parseLong);
46+
4647
// Arrays and maps
4748
Functions.set("newarray", new std_newarray());
49+
Functions.set("join", new std_join());
4850
Functions.set("sort", new std_sort());
4951
Functions.set("arrayCombine", new std_arrayCombine());
5052
Functions.set("arrayKeyExists", new std_arrayKeyExists());

0 commit comments

Comments
 (0)