Package fr.becpg.repo.helper
Class UnicodeHelper
java.lang.Object
fr.becpg.repo.helper.UnicodeHelper
Utility methods for Unicode text sanitization.
- Author:
- beCPG
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsNonBmp(String text) Checks if a string holds any character thatsanitizeBmp(String)strips, that is a supplementary character or an unpaired surrogate.private static booleanisStorableCodePoint(int codePoint) Checks whether a code point can be stored in a MySQL utf8/utf8mb3 column.static StringsanitizeBmp(String text) Strips the characters that MySQL utf8/utf8mb3 tables cannot store, to prevent SQLException: non-BMP characters (code points > 0xFFFF, e.g. 4-byte UTF-8 emojis) and unpaired surrogates.
-
Constructor Details
-
UnicodeHelper
private UnicodeHelper()
-
-
Method Details
-
sanitizeBmp
Strips the characters that MySQL utf8/utf8mb3 tables cannot store, to prevent SQLException: non-BMP characters (code points > 0xFFFF, e.g. 4-byte UTF-8 emojis) and unpaired surrogates.- Parameters:
text- input text- Returns:
- sanitized text holding only storable code points, or original text if unchanged
-
isStorableCodePoint
private static boolean isStorableCodePoint(int codePoint) Checks whether a code point can be stored in a MySQL utf8/utf8mb3 column. A supplementary code point needs 4 UTF-8 bytes, and an unpaired surrogate, which is a BMP code point on its own, has no valid UTF-8 encoding at all.- Parameters:
codePoint- code point to check- Returns:
- true if the code point is a BMP code point other than a surrogate
-
containsNonBmp
Checks if a string holds any character thatsanitizeBmp(String)strips, that is a supplementary character or an unpaired surrogate.- Parameters:
text- text to check- Returns:
- true if text contains at least one surrogate char
-