Last active
January 27, 2021 12:59
-
-
Save fetsh-edu/984b78a2c0355a93029d3a0d1ac92996 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
class GraphemesTest { | |
public static void main(String[] args) throws IOException { | |
analyzeResult("чернокожий человек делает фейспалм"); | |
analyzeResult("чернокожий мужчина делает фейспалм"); | |
analyzeResult("family"); | |
} | |
private static void analyzeResult(String fileName) throws IOException { | |
byte[] bytes = readTmp(fileName + ".txt"); | |
var result = new String(bytes).strip(); | |
System.out.printf("`%s` bytes: [%d]\n", fileName, bytes.length); | |
System.out.printf("`%s` in chars: [%d]\n", fileName, result.toCharArray().length); | |
System.out.printf("`%s` in codePoints: [%d]\n", fileName, result.codePoints().toArray().length); | |
System.out.printf("`%s`.length(): [%d]\n", fileName, result.length()); | |
System.out.printf("`%s`: %s\n", fileName, result); | |
System.out.printf("`%s` reversed: %s\n", fileName, new StringBuilder(result).reverse().toString()); | |
} | |
private static byte[] readTmp(String txt) throws IOException { | |
return Files.readAllBytes(Path.of(System.getProperty("user.home"), "tmp", txt)); | |
} | |
} |
Author
fetsh-edu
commented
Jan 27, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment