+ @brief Get information about the text data in M-text.
+
+ The mtext_data () function returns a pointer to the text data of
+ M-text $MT. If $FMT is not NULL, the format of the text data is
+ stored in it. If $NUNITS is not NULL, the number of units of the
+ text data is stored in it.
+
+ If $POS_IDX is not NULL and it points to a non-negative number,
+ what it points to is a character position. In this case, the
+ return value is a pointer to the text data of a character at that
+ position.
+
+ Otherwise, if $UNIT_IDX is not NULL, it points to a unit position.
+ In this case, the return value is a pointer to the text data of a
+ character containing that unit.
+
+ The character position and unit position of the return value are
+ stored in $POS_IDX and $UNIT_DIX respectively if they are not
+ NULL.
+
+ <ul>
+
+ <li> If the format of the text data is MTEXT_FORMAT_US_ASCII or
+ MTEXT_FORMAT_UTF_8, one unit is unsigned char.
+
+ <li> If the format is MTEXT_FORMAT_UTF_16LE or
+ MTEXT_FORMAT_UTF_16BE, one unit is unsigned short.
+
+ <li> If the format is MTEXT_FORMAT_UTF_32LE or
+ MTEXT_FORMAT_UTF_32BE, one unit is unsigned int.
+
+ </ul> */
+
+void *
+mtext_data (MText *mt, enum MTextFormat *fmt, int *nunits,
+ int *pos_idx, int *unit_idx)
+{
+ void *data;
+ int pos = 0, unit_pos = 0;
+
+ if (fmt)
+ *fmt = mt->format;
+ data = MTEXT_DATA (mt);
+ if (pos_idx && *pos_idx >= 0)
+ {
+ pos = *pos_idx;
+ if (pos > mtext_nchars (mt))
+ MERROR (MERROR_MTEXT, NULL);
+ unit_pos = POS_CHAR_TO_BYTE (mt, pos);
+ }
+ else if (unit_idx)
+ {
+ unit_pos = *unit_idx;
+
+ if (unit_pos < 0 || unit_pos > mtext_nbytes (mt))
+ MERROR (MERROR_MTEXT, NULL);
+ pos = POS_BYTE_TO_CHAR (mt, unit_pos);
+ unit_pos = POS_CHAR_TO_BYTE (mt, pos);
+ }
+ if (nunits)
+ *nunits = mtext_nbytes (mt) - unit_pos;
+ if (pos_idx)
+ *pos_idx = pos;
+ if (unit_idx)
+ *unit_idx = unit_pos;
+ if (unit_pos > 0)
+ {
+ if (mt->format <= MTEXT_FORMAT_UTF_8)
+ data = (unsigned char *) data + unit_pos;
+ else if (mt->format <= MTEXT_FORMAT_UTF_16BE)
+ data = (unsigned short *) data + unit_pos;
+ else
+ data = (unsigned int *) data + unit_pos;
+ }
+ return data;
+}
+
+/*=*/
+
+/***en