Skip to content

Instantly share code, notes, and snippets.

@fetsh-edu
Last active January 27, 2021 12:59
Show Gist options
  • Save fetsh-edu/984b78a2c0355a93029d3a0d1ac92996 to your computer and use it in GitHub Desktop.
Save fetsh-edu/984b78a2c0355a93029d3a0d1ac92996 to your computer and use it in GitHub Desktop.
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));
}
}
@fetsh-edu
Copy link
Author

2021-01-27_15-57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment