Skip to content
Snippets Groups Projects
Commit b1611d67 authored by Tomas Stupka's avatar Tomas Stupka
Browse files

fixed wrong prefix/suffix in string sequence

parent 6a2a364d
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -312,8 +312,14 @@ public abstract class Paste extends RBuiltinNode.Arg3 {
}
RIntSequence seq = (RIntSequence) values.getDataAt(seqPos);
StringBuilder suffix = new StringBuilder();
for (int i = seqPos + 1; i < length; i++) {
suffix.append(values.getDataAt(i)).append(sep);
if (seqPos + 1 < length) {
suffix.append(sep);
for (int i = seqPos + 1; i < length; i++) {
suffix.append(values.getDataAt(i));
if (i < length - 1) {
suffix.append(sep);
}
}
}
return RDataFactory.createStringSequence(prefix.toString(), suffix.toString(), seq.getStart(), seq.getStride(), seq.getLength());
}
......
......@@ -4,7 +4,7 @@
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Copyright (c) 2012-2014, Purdue University
* Copyright (c) 2013, 2017, Oracle and/or its affiliates
* Copyright (c) 2013, 2018, Oracle and/or its affiliates
*
* All rights reserved.
*/
......@@ -84,6 +84,12 @@ public class TestBuiltin_paste extends TestBase {
assertEval("{ paste(NA) }");
assertEval("{ paste(c(1,NA)) }");
assertEval("{ s<-c('1',NA); paste(s); s; }");
assertEval("{ paste(1:3, sep='.') }");
assertEval("{ paste('a', 1:3, sep='.') }");
assertEval("{ paste(1:3, 'b', sep='.') }");
assertEval("{ paste('a', 1:3, 'b', sep='.') }");
assertEval("{ paste('a', 'a', 1:3, 'b', 'b', sep='.') }");
}
@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