mirror of
https://github.com/apple/pkl.git
synced 2026-04-14 12:39:44 +02:00
Allow to toInt() to parse a string including "__" (#578)
Fix the issue where String#toInt() cannot parse a Int string including sequence of "_" like "1_2__3___".
This commit is contained in:
@@ -768,7 +768,7 @@ public final class StringNodes {
|
||||
@Specialization
|
||||
protected long eval(String self) {
|
||||
try {
|
||||
return Long.parseLong(self);
|
||||
return Long.parseLong(self.replaceAll("_", ""));
|
||||
} catch (NumberFormatException e) {
|
||||
throw exceptionBuilder()
|
||||
.evalError("cannotParseStringAs", "Int")
|
||||
@@ -783,7 +783,7 @@ public final class StringNodes {
|
||||
@Specialization
|
||||
protected Object eval(String self) {
|
||||
try {
|
||||
return Long.parseLong(self);
|
||||
return Long.parseLong(self.replaceAll("_", ""));
|
||||
} catch (NumberFormatException e) {
|
||||
return VmNull.withoutDefault();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user