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.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2006, 2010 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
struct substring recode_substring_pool (const char *to, const char *from,
struct substring text, struct pool *);
+size_t recode_string_len (const char *to, const char *from,
+ const char *text, int len);
+
bool valid_encoding (const char *enc);
char get_system_decimal (void);
/* PSPP - a program for statistical analysis.
- Copyright (C) 2010 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "libpspp/i18n.h"
+#undef NDEBUG
+#include <assert.h>
+
int
main (int argc, char *argv[])
{
i18n_init ();
s = recode_string (argv[2], argv[1], argv[3], -1);
puts (s);
+ assert (strlen (s) == recode_string_len (argv[2], argv[1], argv[3], -1));
free (s);
return 0;