+/** @brief Test for a grapheme boundary
+ * @param it Iterator
+ * @return Non-0 if pointing just after a grapheme boundary, otherwise 0
+ *
+ * This function identifies default grapheme cluster boundaries as described in
+ * UAX #29 s3. It returns non-0 if @p it points at the code point just after a
+ * grapheme cluster boundary (including the hypothetical code point just after
+ * the end of the string).
+ */
+int utf32_iterator_grapheme_boundary(utf32_iterator it) {
+ uint32_t before, after;
+ enum unicode_Grapheme_Break gbbefore, gbafter;
+ /* GB1 and GB2 */
+ if(it->n == 0 || it->n == it->ns)
+ return 1;
+ /* Now we know that s[n-1] and s[n] are safe to inspect */
+ /* GB3 */
+ before = it->s[it->n-1];
+ after = it->s[it->n];
+ if(before == 0x000D && after == 0x000A)
+ return 0;
+ gbbefore = utf32__grapheme_break(before);
+ gbafter = utf32__grapheme_break(after);
+ /* GB4 */
+ if(gbbefore == unicode_Grapheme_Break_Control
+ || before == 0x000D
+ || before == 0x000A)
+ return 1;
+ /* GB5 */
+ if(gbafter == unicode_Grapheme_Break_Control
+ || after == 0x000D
+ || after == 0x000A)
+ return 1;
+ /* GB6 */
+ if(gbbefore == unicode_Grapheme_Break_L
+ && (gbafter == unicode_Grapheme_Break_L
+ || gbafter == unicode_Grapheme_Break_V
+ || gbafter == unicode_Grapheme_Break_LV
+ || gbafter == unicode_Grapheme_Break_LVT))
+ return 0;
+ /* GB7 */
+ if((gbbefore == unicode_Grapheme_Break_LV
+ || gbbefore == unicode_Grapheme_Break_V)
+ && (gbafter == unicode_Grapheme_Break_V
+ || gbafter == unicode_Grapheme_Break_T))
+ return 0;
+ /* GB8 */
+ if((gbbefore == unicode_Grapheme_Break_LVT
+ || gbbefore == unicode_Grapheme_Break_T)
+ && gbafter == unicode_Grapheme_Break_T)
+ return 0;
+ /* GB9 */
+ if(gbafter == unicode_Grapheme_Break_Extend)
+ return 0;
+ /* GB10 */
+ return 1;
+
+}
+
+/** @brief Test for a word boundary
+ * @param it Iterator
+ * @return Non-0 if pointing just after a word boundary, otherwise 0
+ *
+ * This function identifies default word boundaries as described in UAX #29 s4.
+ * It returns non-0 if @p it points at the code point just after a word
+ * boundary (including the hypothetical code point just after the end of the
+ * string) and 0 otherwise.
+ */
+int utf32_iterator_word_boundary(utf32_iterator it) {
+ enum unicode_Word_Break twobefore, before, after, twoafter;
+ size_t nn;
+
+ /* WB1 and WB2 */
+ if(it->n == 0 || it->n == it->ns)
+ return 1;
+ /* WB3 */
+ if(it->s[it->n-1] == 0x000D && it->s[it->n] == 0x000A)
+ return 0;
+ /* WB4 */
+ /* (!Sep) x (Extend|Format) as in UAX #29 s6.2 */
+ if(utf32__sentence_break(it->s[it->n-1]) != unicode_Sentence_Break_Sep
+ && utf32__boundary_ignorable(utf32__iterator_word_break(it, it->s[it->n])))
+ return 0;
+ /* Gather the property values we'll need for the rest of the test taking the
+ * s6.2 changes into account */
+ /* First we look at the code points after the proposed boundary */
+ nn = it->n; /* <it->ns */
+ after = utf32__iterator_word_break(it, it->s[nn++]);
+ if(!utf32__boundary_ignorable(after)) {
+ /* X (Extend|Format)* -> X */
+ while(nn < it->ns
+ && utf32__boundary_ignorable(utf32__iterator_word_break(it,
+ it->s[nn])))
+ ++nn;
+ }
+ /* It's possible now that nn=ns */
+ if(nn < it->ns)
+ twoafter = utf32__iterator_word_break(it, it->s[nn]);
+ else
+ twoafter = unicode_Word_Break_Other;
+
+ /* We've already recorded the non-ignorable code points before the proposed
+ * boundary */
+ before = utf32__iterator_word_break(it, it->last[1]);
+ twobefore = utf32__iterator_word_break(it, it->last[0]);
+
+ /* WB5 */
+ if(before == unicode_Word_Break_ALetter
+ && after == unicode_Word_Break_ALetter)
+ return 0;
+ /* WB6 */
+ if(before == unicode_Word_Break_ALetter
+ && after == unicode_Word_Break_MidLetter
+ && twoafter == unicode_Word_Break_ALetter)
+ return 0;
+ /* WB7 */
+ if(twobefore == unicode_Word_Break_ALetter
+ && before == unicode_Word_Break_MidLetter
+ && after == unicode_Word_Break_ALetter)
+ return 0;
+ /* WB8 */
+ if(before == unicode_Word_Break_Numeric
+ && after == unicode_Word_Break_Numeric)
+ return 0;
+ /* WB9 */
+ if(before == unicode_Word_Break_ALetter
+ && after == unicode_Word_Break_Numeric)
+ return 0;
+ /* WB10 */
+ if(before == unicode_Word_Break_Numeric
+ && after == unicode_Word_Break_ALetter)
+ return 0;
+ /* WB11 */
+ if(twobefore == unicode_Word_Break_Numeric
+ && before == unicode_Word_Break_MidNum
+ && after == unicode_Word_Break_Numeric)
+ return 0;
+ /* WB12 */
+ if(before == unicode_Word_Break_Numeric
+ && after == unicode_Word_Break_MidNum
+ && twoafter == unicode_Word_Break_Numeric)
+ return 0;
+ /* WB13 */
+ if(before == unicode_Word_Break_Katakana
+ && after == unicode_Word_Break_Katakana)
+ return 0;
+ /* WB13a */
+ if((before == unicode_Word_Break_ALetter
+ || before == unicode_Word_Break_Numeric
+ || before == unicode_Word_Break_Katakana
+ || before == unicode_Word_Break_ExtendNumLet)
+ && after == unicode_Word_Break_ExtendNumLet)
+ return 0;
+ /* WB13b */
+ if(before == unicode_Word_Break_ExtendNumLet
+ && (after == unicode_Word_Break_ALetter
+ || after == unicode_Word_Break_Numeric
+ || after == unicode_Word_Break_Katakana))
+ return 0;
+ /* WB14 */
+ return 1;
+}
+
+/*@}*/
+/** @defgroup utf32 Functions that operate on UTF-32 strings */
+/*@{*/
+
+/** @brief Return the length of a 0-terminated UTF-32 string
+ * @param s Pointer to 0-terminated string
+ * @return Length of string in code points (excluding terminator)
+ *
+ * Unlike the conversion functions no validity checking is done on the string.