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
2024-07-15 17:39:17 +09:00
committed by GitHub
parent cdf548cad0
commit b5e011dae1
3 changed files with 12 additions and 4 deletions

View File

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