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:
Taichi Ishitani authored and GitHub committed 2024-07-15 10:39:17 +02:00
1 parent cdf548cad0
commit b5e011dae1
3 files changed
+12 -4

No files matched your search

@@ -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();
}