- Copyright (C) 1997-9, 2000, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009, 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
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 <data/data-out.h>
-#include <data/value.h>
-#include <data/variable.h>
-#include <libpspp/array.h>
-#include <libpspp/cast.h>
-#include <libpspp/compiler.h>
-#include <libpspp/hash-functions.h>
-#include <libpspp/hmap.h>
-#include <libpspp/intern.h>
-#include <libpspp/message.h>
-#include <libpspp/str.h>
+#include "data/data-out.h"
+#include "data/value.h"
+#include "data/variable.h"
+#include "libpspp/array.h"
+#include "libpspp/cast.h"
+#include "libpspp/compiler.h"
+#include "libpspp/hash-functions.h"
+#include "libpspp/hmap.h"
+#include "libpspp/intern.h"
+#include "libpspp/message.h"
+#include "libpspp/str.h"
copy = val_labs_create (vls->width);
HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
copy = val_labs_create (vls->width);
HMAP_FOR_EACH (label, struct val_lab, node, &vls->labels)
hmap_delete (&vls->labels, &label->node);
value_destroy (&label->value, vls->width);
intern_unref (label->label);
hmap_delete (&vls->labels, &label->node);
value_destroy (&label->value, vls->width);
intern_unref (label->label);
+static void
+set_label (struct val_lab *lab, const char *escaped_label)
+{
+ lab->escaped_label = intern_new (escaped_label);
+ if (strstr (escaped_label, "\\n") == NULL)
+ lab->label = intern_ref (lab->escaped_label);
+ else
+ {
+ struct string s;
+ const char *p;
+
+ ds_init_empty (&s);
+ ds_extend (&s, intern_strlen (lab->escaped_label));
+ for (p = escaped_label; *p != '\0'; p++)
+ {
+ char c = *p;
+ if (c == '\\' && p[1] == 'n')
+ {
+ c = '\n';
+ p++;
+ }
+ ds_put_byte (&s, c);
+ }
+ lab->label = intern_new (ds_cstr (&s));
+ ds_destroy (&s);
+ }
+}
+
{
struct val_lab *lab = xmalloc (sizeof *lab);
value_clone (&lab->value, value, vls->width);
{
struct val_lab *lab = xmalloc (sizeof *lab);
value_clone (&lab->value, value, vls->width);
hmap_insert (&vls->labels, &lab->node, value_hash (value, vls->width, 0));
}
hmap_insert (&vls->labels, &lab->node, value_hash (value, vls->width, 0));
}
-/* If VLS does not already contain a value label for VALUE, adds
- LABEL for it and returns true. Otherwise, returns false. */
+/* If VLS does not already contain a value label for VALUE, adds the UTF-8
+ encoded LABEL for it and returns true. Otherwise, returns false.
+
+ In LABEL, the two-byte sequence "\\n" is interpreted as a new-line. */
hmap_delete (&vls->labels, &label->node);
value_destroy (&label->value, vls->width);
intern_unref (label->label);
hmap_delete (&vls->labels, &label->node);
value_destroy (&label->value, vls->width);
intern_unref (label->label);
-/* Searches VLS for a value label for VALUE. If successful,
- returns the string used as the label; otherwise, returns a
- null pointer. Returns a null pointer if VLS is null. */
+/* Searches VLS for a value label for VALUE. If successful, returns the string
+ used as the label, as a UTF-8 encoded string in a format suitable for
+ output. Otherwise, returns a null pointer. Returns a null pointer if VLS
+ is null. */