i18n: New function recode_string_len().
[pspp-builds.git] / src / libpspp / i18n.c
index cb155723b3e8bc9867c848bc12a9ab8c85fb42c3..29148a0e7a9789cf9cbee7c5d6ac764c83f8ff10 100644 (file)
@@ -110,6 +110,17 @@ recode_string (const char *to, const char *from,
   return recode_string_pool (to, from, text, length, NULL);
 }
 
+/* Returns the length, in bytes, of the string that a similar recode_string()
+   call would return. */
+size_t
+recode_string_len (const char *to, const char *from,
+                   const char *text, int length)
+{
+  char *s = recode_string (to, from, text, length);
+  size_t len = strlen (s);
+  free (s);
+  return len;
+}
 
 /* Uses CONV to convert the INBYTES starting at IP into the OUTBYTES starting
    at OP, and appends a null terminator to the output.
@@ -377,3 +388,12 @@ get_system_decimal (void)
   return radix_char;
 }
 
+const char *
+uc_name (ucs4_t uc, char buffer[16])
+{
+  if (uc >= 0x20 && uc < 0x7f)
+    snprintf (buffer, 16, "`%c'", uc);
+  else
+    snprintf (buffer, 16, "U+%04X", uc);
+  return buffer;
+}