breakChar = breakString.charAt(0);
int head = 0;
int lastSpace = 0;
StringValue sb = env.createStringBuilder();
for (int i = 0; i < len; i++) {
char ch = string.charAt(i);
if (ch == breakChar && string.regionMatches(
i, breakString, 0, breakLen)) {
sb.append(string, head, i + breakLen);
head = i + breakLen;
} else if (width <= i - head) {
if (ch == ' ') {
sb.append(string, head, i);
sb.append(breakString);
head = i + 1;
} else if (head < lastSpace) {
sb.append(string, head, lastSpace);
sb.append(breakString);
head = lastSpace + 1;
} else if (isCut) {
sb.append(string, head, i);
sb.append(breakString);
head = i;
}
} else if (ch == ' ') {
lastSpace = i;
}
}
if (head < len) {
sb.append(string, head, len);
}
return sb;
}