pxd: initial work
[pspp] / src / libpspp / intern.c
index fc31acf0b439fec19c339296abe3e5fe8f5ce314..101a14d3c3a829df3d6ce38989339069b260cf71 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 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
@@ -59,7 +59,12 @@ intern_lookup__ (const char *s, size_t length, unsigned int hash)
 const char *
 intern_new (const char *s)
 {
-  size_t length = strlen (s);
+  return intern_buffer (s, strlen (s));
+}
+
+const char *
+intern_buffer (const char *s, size_t length)
+{
   unsigned int hash = hash_bytes (s, length, 0);
   struct interned_string *is;
 
@@ -110,6 +115,13 @@ intern_unref (const char *s)
     }
 }
 
+/* Returns the length of interned string S. */
+size_t
+intern_strlen (const char *s)
+{
+  return interned_string_from_string (s)->length;
+}
+
 /* Given null-terminated string S, returns true if S is an interned string
    returned by intern_string_new(), false otherwise.
 
@@ -123,11 +135,3 @@ is_interned_string (const char *s)
   unsigned int hash = hash_bytes (s, length, 0);
   return intern_lookup__ (s, length, hash) != NULL;
 }
-
-/* Returns the length of S, which must be an interned string returned by
-   intern_new(). */
-size_t
-intern_strlen (const char *s)
-{
-  return interned_string_from_string (s)->length;
-}