Skip to content
Snippets Groups Projects
Commit 24dabe81 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

trim strings when casting to integer

parent 41339a76
No related branches found
No related tags found
No related merge requests found
......@@ -450,7 +450,8 @@ public class RRuntime {
// FIXME use R rules
int result;
try {
result = Integer.decode(Utils.trimLeadingZeros(s)); // decode supports hex constants
result = Integer.decode(Utils.trimLeadingZeros(s.trim())); // decode supports hex
// constants
} catch (NumberFormatException e) {
if (exceptionOnFail) {
throw e;
......
......@@ -7377,7 +7377,7 @@ NAs introduced by coercion to integer range
[551] 4 4 2 4 4 4 4 3 2 3 3 2 NA 3 4 4 3 3 4 4 4 1 4 4 4
[576] 4 4 4 4 2 4 2 3 4 1 3 1 NA 4 1 2 2 1 4 3 3 4 1 1 3
 
##com.oracle.truffle.r.test.builtins.TestBuiltin_asinteger.testasinteger2#Ignored.ImplementationError#
##com.oracle.truffle.r.test.builtins.TestBuiltin_asinteger.testasinteger2#
#argv <- list(c(' 33', ' 34', ' 35', ' 36', ' 37', ' 38', ' 18', ' 19', ' 20', ' 21', ' 22', ' 23', ' 36', ' 37', ' 38', ' 39'));as.integer(argv[[1]]);
[1] 33 34 35 36 37 38 18 19 20 21 22 23 36 37 38 39
 
......@@ -34,9 +34,7 @@ public class TestBuiltin_asinteger extends TestBase {
@Test
public void testasinteger2() {
// FIXME according to docs a leading whitespace should be accepted
assertEval(Ignored.ImplementationError,
"argv <- list(c(' 33', ' 34', ' 35', ' 36', ' 37', ' 38', ' 18', ' 19', ' 20', ' 21', ' 22', ' 23', ' 36', ' 37', ' 38', ' 39'));as.integer(argv[[1]]);");
assertEval("argv <- list(c(' 33', ' 34', ' 35', ' 36', ' 37', ' 38', ' 18', ' 19', ' 20', ' 21', ' 22', ' 23', ' 36', ' 37', ' 38', ' 39'));as.integer(argv[[1]]);");
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment