+ * Test for a combining character.
+ *
+ * Similar to __CFUniCharIsNonBaseCharacter except that
+ * unicode_combinable also includes Hangul Jamo characters.
+ */
+static inline int
+unicode_combinable(u_int16_t character)
+{
+ const u_int8_t *bitmap = __CFUniCharCombiningBitmap;
+ u_int8_t value;
+
+ if (character < 0x0300)
+ return (0);
+
+ value = bitmap[(character >> 8) & 0xFF];
+
+ if (value == 0xFF) {
+ return (1);
+ } else if (value) {
+ bitmap = bitmap + ((value - 1) * 32) + 256;
+ return (bitmap[(character & 0xFF) / 8] & (1 << (character % 8)) ? 1 : 0);
+ }
+ return (0);
+}
+
+/*
+ * Test for a precomposed character.
+ *
+ * Similar to __CFUniCharIsDecomposableCharacter.
+ */
+static inline int
+unicode_decomposeable(u_int16_t character) {
+ const u_int8_t *bitmap = __CFUniCharDecomposableBitmap;
+ u_int8_t value;
+
+ if (character < 0x00C0)
+ return (0);
+
+ value = bitmap[(character >> 8) & 0xFF];
+
+ if (value == 0xFF) {
+ return (1);
+ } else if (value) {
+ bitmap = bitmap + ((value - 1) * 32) + 256;
+ return (bitmap[(character & 0xFF) / 8] & (1 << (character % 8)) ? 1 : 0);
+ }
+ return (0);
+}
+
+
+/*
+ * Get the combing class.
+ *
+ * Similar to CFUniCharGetCombiningPropertyForCharacter.
+ */
+static inline u_int8_t
+get_combining_class(u_int16_t character) {
+ const u_int8_t *bitmap = __CFUniCharCombiningPropertyBitmap;
+
+ u_int8_t value = bitmap[(character >> 8)];
+
+ if (value) {
+ bitmap = bitmap + (value * 256);
+ return bitmap[character % 256];
+ }
+ return (0);
+}
+
+
+static int unicode_decompose(u_int16_t character, u_int16_t *convertedChars);
+
+static u_int16_t unicode_combine(u_int16_t base, u_int16_t combining);
+
+static void priortysort(u_int16_t* characters, int count);
+
+char utf_extrabytes[32] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 2, 2, 3, -1
+};
+
+
+/*
+ * utf8_encodelen - Calculates the UTF-8 encoding length for a Unicode filename