dictionary: Truncate file label in dictionary encoding, not UTF-8.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 8 Feb 2012 05:18:08 +0000 (21:18 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 8 Feb 2012 06:59:15 +0000 (22:59 -0800)
The limiting factor is bytes in the on-disk format and so there's
no point in truncating in terms of the in-memory format.

src/data/dictionary.c

index 2d99f6d72cfe2a7e6dc442102f16a4dc687cbe32..b64d84a2ca58622eb06c99ede072579b71d476ed 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2012 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
@@ -1250,15 +1250,18 @@ dict_get_label (const struct dictionary *d)
   return d->label;
 }
 
-/* Sets D's file label to LABEL, truncating it to a maximum of 60
-   characters.
+/* Sets D's file label to LABEL, truncating it to at most 60 bytes in D's
+   encoding.
 
    Removes D's label if LABEL is null or the empty string. */
 void
 dict_set_label (struct dictionary *d, const char *label)
 {
   free (d->label);
-  d->label = label != NULL && label[0] != '\0' ? xstrndup (label, 60) : NULL;
+  if (label == NULL || label[0] == '\0')
+    d->label = NULL;
+  else
+    d->label = utf8_encoding_trunc (label, d->encoding, 60);
 }
 
 /* Returns the documents for D, as an UTF-8 encoded string_array.  The