FXMisc / RichTextFX

Rich-text area for JavaFX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: is textArea.getLength() equal to the number of Unicode code points

PavelTurk opened this issue · comments

Could anyone say if textArea.getLength() is always equal to textArea.getText().codePoints().count()?

No they are not always equal.

@Jugen Thank you for your answer. Could you explain? Are talking about situations then "\t" is displayed using spaces?

No, it's about those characters where more than one Unicode code unit is required to represent the character. String.length() returns the number of Unicode code units while codePoints() combines these code units into a single integer value and returns that. So String.length can be larger than the count of integers returned by codePoints.

@Jugen Yes, I totally agree with you. But then maybe javadoc for getLength() The number of characters in this text-editing area is incorrect:

var codeArea = new CodeArea("𝕒b");
System.out.println(codeArea.getLength() + " / " + codeArea.getText().length());

output:

3 / 3

I agree, I've updated the JavaDoc for getLength()
Thanks.