Skip to content

Commit

Permalink
AttributedCharSequence.columnSubSequence does not handle UTF-16 surro…
Browse files Browse the repository at this point in the history
…gate pairs, fixes #314
  • Loading branch information
gnodet committed Jan 28, 2019
1 parent 8de0b68 commit 1e6e9a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public AttributedString columnSubSequence(int start, int stop) {
if (col + w > start) {
break;
}
begin++;
begin += Character.charCount(cp);
col += w;
}
int end = begin;
Expand All @@ -305,7 +305,7 @@ public AttributedString columnSubSequence(int start, int stop) {
if (col + w > stop) {
break;
}
end++;
end += Character.charCount(cp);
col += w;
}
return subSequence(begin, end);
Expand Down
10 changes: 10 additions & 0 deletions terminal/src/test/java/org/jline/utils/AttributedStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,14 @@ public void testColors() {
.toAnsi();
assertEquals("This i\u001B[34ms\u001B[33m a\u001B[31m Test.\u001B[0m", ansiStr);
}

@Test
public void testColumns() {
AttributedString message = new AttributedString("👍");
int messageLength = message.columnLength();
assertEquals(1, messageLength);
AttributedString messageAgain = message.columnSubSequence(0, messageLength);
assertEquals("👍", messageAgain.toString());
}

}

0 comments on commit 1e6e9a6

Please sign in to comment.