char *
mixed_string_buffer_done (struct mixed_string_buffer *bp)
{
- char *utf8_buffer;
+ if (bp->utf8_buffer || bp->utf16_surr != 0)
+ {
+ char *utf8_buffer;
- /* Flush all into bp->utf8_buffer. */
- mixed_string_buffer_flush_utf16_surr (bp);
- mixed_string_buffer_flush_curr_buffer (bp, bp->line_number);
- /* NUL-terminate it. */
- mixed_string_buffer_grow_utf8_buffer (bp, 1);
- bp->utf8_buffer[bp->utf8_buflen] = '\0';
+ /* Flush all into bp->utf8_buffer. */
+ mixed_string_buffer_flush_utf16_surr (bp);
+ mixed_string_buffer_flush_curr_buffer (bp, bp->line_number);
+ /* NUL-terminate it. */
+ mixed_string_buffer_grow_utf8_buffer (bp, 1);
+ bp->utf8_buffer[bp->utf8_buflen] = '\0';
+
+ /* Free curr_buffer and bp itself. */
+ utf8_buffer = bp->utf8_buffer;
+ free (bp->curr_buffer);
+ free (bp);
+
+ /* Return it. */
+ return utf8_buffer;
+ }
+ else
+ {
+ char *curr_buffer;
- /* Free curr_buffer and bp itself. */
- utf8_buffer = bp->utf8_buffer;
- free (bp->curr_buffer);
- free (bp);
+ /* NUL-terminate it. */
+ mixed_string_buffer_append_to_curr_buffer (bp, '\0');
- /* Return it. */
- return utf8_buffer;
+ /* Free utf8_buffer and bp itself. */
+ curr_buffer = bp->curr_buffer;
+ free (bp->utf8_buffer);
+ free (bp);
+
+ /* Return it. */
+ return curr_buffer;
+ }
}
extern void mixed_string_buffer_append_unicode (struct mixed_string_buffer *bp,
int c);
-/* Frees mixed_string_buffer and returns the accumulated string as a
- UTF-8 string. */
+/* Frees mixed_string_buffer and returns the accumulated string. If
+ any Unicode character has been added to BP, the result is in UTF-8.
+ Otherwise, it doesn't do any conversion. */
extern char * mixed_string_buffer_done (struct mixed_string_buffer *bp);