Closed GoogleCodeExporter closed 9 years ago
Can you give some detail about how this would differ from the current behavior?
If your inputs are CharSequences, then Joiner should already be calling
StringBuilder.append(CharSequence). Is that not happening, or do you want a
different behavior?
Original comment by cpov...@google.com
on 2 Mar 2014 at 2:33
No, it's not working.
Neither:
public static CharSequence concatLines(CharSequence... lines) {
return Joiner.on(LINE_SEPARATOR).join(lines);
}
My own method works:
Nor:
public static CharSequence concatLines(CharSequence... lines) {
StringBuilder stringBuilder = new StringBuilder();
Joiner.on(LINE_SEPARATOR).appendTo(stringBuilder, lines);
return stringBuilder;
}
My own method works:
public static CharSequence concatLines(CharSequence... lines) {
CharSequence text = null;
for (CharSequence line : lines)
if (TextUtils.isEmpty(text))
text = line;
else
text = TextUtils.concat(text, LINE_SEPARATOR, line);
return text;
}
Original comment by android....@gmail.com
on 2 Mar 2014 at 9:38
Please explain the behavior you are seeing and the desired behavior.
Original comment by cpov...@google.com
on 2 Mar 2014 at 9:40
I am passing in some annotated CharSequences. I have basically formatting
Spans attached to them. So they are Android SpannedString objects.
http://developer.android.com/reference/android/text/SpannedString.html
But after I run them through a Joiner, the returned object has the formatting
stripped out. In the case of join(), it's expected, as the return is defined
to be a String, so it's expected. It would be nice if join() could return a
CharSequence, or there'd be a new method joinToCharSequence.
But the
StringBuilder stringBuilder = new StringBuilder();
Joiner.on(LINE_SEPARATOR).appendTo(stringBuilder, lines);
return stringBuilder;
pattern also strips out the formatting, so I suspect there is a .toString()
some place in the Joiner code that does that.
Original comment by android....@gmail.com
on 2 Mar 2014 at 9:48
It sounds like you want a SpannedString as the output?
Original comment by cpov...@google.com
on 2 Mar 2014 at 9:55
This doesn't sound possible. How could Joiner know how to append to something
that doesn't at least implement Appendable? How would you possibly implement
this, OP?
Original comment by wasserman.louis
on 2 Mar 2014 at 9:58
I suppose so. Like how android.text.TextUtils.concat() also maintains the
spans. But now, I am looking at the sources for TextUtils.concat() and it has
special logic just for SpannedStrings, so that obviously not going to fly with
Guava. That's cool, now I understand what's going on. You can close this
issue as out of scope.
Original comment by android....@gmail.com
on 2 Mar 2014 at 10:02
Original comment by cpov...@google.com
on 2 Mar 2014 at 10:04
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:09
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:07
Original issue reported on code.google.com by
android....@gmail.com
on 2 Mar 2014 at 6:14