[Top][All Lists]
[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
- [PATCH 00/18] rewrite PSPP lexer, Ben Pfaff, 2011/03/19
- [PATCH 01/18] data-reader: Remove unreachable "return" statements., Ben Pfaff, 2011/03/19
- [PATCH 07/18] str: New functions for checking for and removing string suffixes., Ben Pfaff, 2011/03/19
- [PATCH 10/18] i18n: New function recode_string_len().,
Ben Pfaff <=
- [PATCH 09/18] i18n: New function uc_name()., Ben Pfaff, 2011/03/19
- [PATCH 14/18] encoding-guesser: New library to guess the encoding of a text file., Ben Pfaff, 2011/03/19
- [PATCH 04/18] output: New function text_item_create_nocopy()., Ben Pfaff, 2011/03/19
- [PATCH 05/18] str: New function ss_realloc()., Ben Pfaff, 2011/03/19
- [PATCH 13/18] i18n: New functions and data structure for obtaining encoding info., Ben Pfaff, 2011/03/19
- [PATCH 06/18] str: Rename ss_chomp() to ss_chomp_byte(), ds_chomp() to ds_chomp_byte()., Ben Pfaff, 2011/03/19
- [PATCH 02/18] file-name: Do not make output files line-buffered in fn_open()., Ben Pfaff, 2011/03/19
- [PATCH 12/18] identifier: Rename token_type_to_string() and make a new version., Ben Pfaff, 2011/03/19
- [PATCH 08/18] hash-functions: New function hash_case_bytes()., Ben Pfaff, 2011/03/19
- [PATCH 11/18] i18n: New functions for truncating strings in an arbitrary encoding., Ben Pfaff, 2011/03/19