str: Make str_format_26adic() able to use lowercase.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 8 Sep 2014 06:02:03 +0000 (23:02 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 13 Sep 2014 18:07:03 +0000 (11:07 -0700)
The output engine will use lowercase for footnote markers.

src/data/dictionary.c
src/data/short-names.c
src/libpspp/str.c
src/libpspp/str.h
tests/libpspp/str-test.c
tests/libpspp/stringi-map-test.c
tests/libpspp/stringi-set-test.c

index 79952b58140f386432851a05f41586ff10172c79..4eaaefae18ed9ae4889275bccd00b0e568c26e8d 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014 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
@@ -907,7 +907,7 @@ make_hinted_name (const struct dictionary *dict, const char *hint)
           char *name;
 
           suffix[0] = '_';
-          if (!str_format_26adic (i + 1, &suffix[1], sizeof suffix - 1))
+          if (!str_format_26adic (i + 1, true, &suffix[1], sizeof suffix - 1))
             NOT_REACHED ();
 
           name = utf8_encoding_concat (root, suffix, dict->encoding, 64);
index aa157bae1b13c105f4685fb120e7c92980f13938..ea8df782b42b52c0467b23efa3413a4499d0db48 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009, 2010, 2011, 2014 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
@@ -62,7 +62,7 @@ assign_short_name (struct variable *v, size_t i,
       else
         {
           suffix[0] = '_';
-          str_format_26adic (trial, &suffix[1], sizeof suffix - 1);
+          str_format_26adic (trial, true, &suffix[1], sizeof suffix - 1);
         }
 
       /* Set name. */
index d7c71b11f5509f15678693555676c54cc4662e3f..3fa2fbe9a75fbe48d0ed75dc48a1b32916b0ef88 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2014 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
@@ -257,9 +257,10 @@ str_lowercase (char *s)
 }
 
 /* Converts NUMBER into a string in 26-adic notation in BUFFER,
-   which has room for SIZE bytes.  Returns true if successful,
-   false if NUMBER, plus a trailing null, is too large to fit in
-   the available space.
+   which has room for SIZE bytes.  Uses uppercase if UPPERCASE is
+   true, otherwise lowercase, Returns true if successful, false
+   if NUMBER, plus a trailing null, is too large to fit in the
+   available space.
 
    26-adic notation is "spreadsheet column numbering": 1 = A, 2 =
    B, 3 = C, ... 26 = Z, 27 = AA, 28 = AB, 29 = AC, ...
@@ -271,15 +272,18 @@ str_lowercase (char *s)
    For more information, see
    http://en.wikipedia.org/wiki/Bijective_numeration. */
 bool
-str_format_26adic (unsigned long int number, char buffer[], size_t size)
+str_format_26adic (unsigned long int number, bool uppercase,
+                   char buffer[], size_t size)
 {
+  const char *alphabet
+    = uppercase ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "abcdefghijklmnopqrstuvwxyz";
   size_t length = 0;
 
   while (number-- > 0)
     {
       if (length >= size)
         goto overflow;
-      buffer[length++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[number % 26];
+      buffer[length++] = alphabet[number % 26];
       number /= 26;
     }
 
index 306bd8ba89f110762dbf31f04abace081227b0cc..dd41ede819a04c27cc15407167f7f4106fa8bbc0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2014 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
@@ -47,7 +47,8 @@ void str_copy_buf_trunc (char *, size_t, const char *, size_t);
 void str_uppercase (char *);
 void str_lowercase (char *);
 
-bool str_format_26adic (unsigned long int number, char buffer[], size_t);
+bool str_format_26adic (unsigned long int number, bool uppercase,
+                        char buffer[], size_t);
 
 void *mempset (void *, int, size_t);
 \f
index c341d887b8a89da7683cc0d664ad38596cd0668b..36d54157440a764b7311b1ac67daa977b4c0336e 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2010, 2014 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
@@ -34,7 +34,7 @@ static void
 check_26adic (unsigned long int number, const char *expected_string)
 {
   char string[8];
-  str_format_26adic (number, string, sizeof string);
+  str_format_26adic (number, true, string, sizeof string);
   if (strcmp (string, expected_string))
     {
       printf ("base-26 of %lu: expected \"%s\", got \"%s\"\n",
index 3ae027fb36db78b5afaf6b28890810a1da26847b..20b8ce5c2c8e85039be225bae5b377be1d94e19b 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009, 2010, 2012, 2014 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
@@ -145,7 +145,7 @@ get_string (int idx)
   if (*s == NULL)
     {
       *s = xmalloc (16);
-      str_format_26adic (idx + 1, *s, 16);
+      str_format_26adic (idx + 1, true, *s, 16);
     }
   return *s;
 }
index daf7b2fa6d97a6cfaf382c5e1b71ffbfe5ce8024..2bcc760780c4bde4f78e718582d9fbcdf9f92f03 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008, 2009, 2010, 2012, 2014 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
@@ -133,7 +133,7 @@ make_string (int value)
   if (*s == NULL)
     {
       *s = xmalloc (16);
-      str_format_26adic (value + 1, *s, 16);
+      str_format_26adic (value + 1, true, *s, 16);
     }
   return *s;
 }