in src/main/java/org/apache/commons/text/WordUtils.java [457:486]
public static String swapCase(final String str) {
if (StringUtils.isEmpty(str)) {
return str;
}
final int strLen = str.length();
final int[] newCodePoints = new int[strLen];
int outOffset = 0;
boolean whitespace = true;
for (int index = 0; index < strLen;) {
final int oldCodepoint = str.codePointAt(index);
final int newCodePoint;
if (Character.isUpperCase(oldCodepoint) || Character.isTitleCase(oldCodepoint)) {
newCodePoint = Character.toLowerCase(oldCodepoint);
whitespace = false;
} else if (Character.isLowerCase(oldCodepoint)) {
if (whitespace) {
newCodePoint = Character.toTitleCase(oldCodepoint);
whitespace = false;
} else {
newCodePoint = Character.toUpperCase(oldCodepoint);
}
} else {
whitespace = Character.isWhitespace(oldCodepoint);
newCodePoint = oldCodepoint;
}
newCodePoints[outOffset++] = newCodePoint;
index += Character.charCount(newCodePoint);
}
return new String(newCodePoints, 0, outOffset);
}