]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Allow mixed_string_buffer_done to return non-UTF-8 string
authorDaiki Ueno <ueno@gnu.org>
Fri, 2 May 2014 19:53:05 +0000 (04:53 +0900)
committerDaiki Ueno <ueno@gnu.org>
Fri, 2 May 2014 19:57:22 +0000 (04:57 +0900)
gettext-tools/src/xgettext.c
gettext-tools/src/xgettext.h

index ca957fd47a9e36896035a732c4c0ac72f94c4084..c30139e712cdce30dd4ed3f579096569a37a2ebb 100644 (file)
@@ -3230,22 +3230,40 @@ mixed_string_buffer_append_unicode (struct mixed_string_buffer *bp, int c)
 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;
+    }
 }
 
 
index 81e82667f32b50f97352782d6ca08072c0bef2da..706309a1a549b1501ff9384b2353dcb1cc694ff1 100644 (file)
@@ -370,8 +370,9 @@ extern void mixed_string_buffer_append_char (struct mixed_string_buffer *bp,
 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);