pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 10/18] i18n: New function recode_string_len().


From: Ben Pfaff
Subject: [PATCH 10/18] i18n: New function recode_string_len().
Date: Sat, 19 Mar 2011 17:09:56 -0700

---
 src/libpspp/i18n.c        |   11 +++++++++++
 src/libpspp/i18n.h        |    5 ++++-
 tests/libpspp/i18n-test.c |    7 ++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c
index 13a46a5..29148a0 100644
--- a/src/libpspp/i18n.c
+++ b/src/libpspp/i18n.c
@@ -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.
diff --git a/src/libpspp/i18n.h b/src/libpspp/i18n.h
index 2f55a69..78a9737 100644
--- a/src/libpspp/i18n.h
+++ b/src/libpspp/i18n.h
@@ -1,5 +1,5 @@
 /* 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
@@ -41,6 +41,9 @@ char *recode_string_pool (const char *to, const char *from,
 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);
diff --git a/tests/libpspp/i18n-test.c b/tests/libpspp/i18n-test.c
index f2bead9..03b96f2 100644
--- a/tests/libpspp/i18n-test.c
+++ b/tests/libpspp/i18n-test.c
@@ -1,5 +1,5 @@
 /* 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
@@ -18,9 +18,13 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "libpspp/i18n.h"
 
+#undef NDEBUG
+#include <assert.h>
+
 int
 main (int argc, char *argv[])
 {
@@ -40,6 +44,7 @@ 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;
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]