Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

StringUtils.wrapText will not split surrogate pair.#103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,10 +21,10 @@
final class StringUtils {

/**
* Replaces all openingan closing tags with <code>&lt;</code> or <code>&gt;</code>.
* Replaces all openingand closing tags with <code>&lt;</code> or <code>&gt;</code>.
*
* @param str
* @return
* @return str with some HTML meta characters escaped.
*/
public static String htmlEntites(String str) {
return str.replace("<", "&lt;").replace(">", "&gt;");
Expand DownExpand Up@@ -61,7 +61,17 @@ public static String wrapText(String line, int columnWidth) {
StringBuilder b = new StringBuilder(line);

for (int count = 0; length > widthIndex; count++) {
b.insert(widthIndex + delimiter * count, "<br/>");
int breakPoint = widthIndex + delimiter * count;
if (Character.isHighSurrogate(b.charAt(breakPoint - 1)) &&
Character.isLowSurrogate(b.charAt(breakPoint))) {
// Shift a breakpoint that would split a supplemental code-point.
breakPoint += 1;
if (breakPoint == b.length()) {
// Break before instead of after if this is the last code-point.
breakPoint -= 2;
}
}
b.insert(breakPoint, "<br/>");
widthIndex += columnWidth;
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,8 @@ public void testWrapText_String_int() {
assertEquals("te<br/>st", StringUtils.wrapText("test", 2));
assertEquals("tes<br/>t", StringUtils.wrapText("test", 3));
assertEquals("test", StringUtils.wrapText("test", 10));
assertEquals(".\uD800\uDC01<br/>.", StringUtils.wrapText(".\uD800\uDC01.", 2));
assertEquals("..<br/>\uD800\uDC01", StringUtils.wrapText("..\uD800\uDC01", 3));
}

@Test
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp