Remove "face-lift" comment.
[bpt/guile.git] / libguile / strings.c
index 476493e..acb53be 100644 (file)
@@ -39,8 +39,6 @@
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
 
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
-   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
 
 \f
 
 
 #include "libguile/_scm.h"
 #include "libguile/chars.h"
-
+#include "libguile/root.h"
 #include "libguile/strings.h"
+#include "libguile/deprecation.h"
 #include "libguile/validate.h"
+
 \f
 
 /* {Strings}
@@ -105,7 +105,7 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
   {
     unsigned char *data = SCM_STRING_UCHARS (result);
 
-    while (SCM_NNULLP (chrs))
+    while (!SCM_NULLP (chrs))
       {
        SCM elt = SCM_CAR (chrs);
 
@@ -121,7 +121,7 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1,
 #if (SCM_DEBUG_DEPRECATED == 0)
 
 SCM 
-scm_makstr (long len, int dummy)
+scm_makstr (size_t len, int dummy)
 #define FUNC_NAME "scm_makstr"
 {
   SCM s;
@@ -153,7 +153,7 @@ scm_makfromstrs (int argc, char **argv)
   if (0 > i)
     for (i = 0; argv[i]; i++);
   while (i--)
-    lst = scm_cons (scm_makfromstr (argv[i], (scm_sizet) strlen (argv[i]), 0), lst);
+    lst = scm_cons (scm_mem2string (argv[i], strlen (argv[i])), lst);
   return lst;
 }
 
@@ -167,7 +167,7 @@ scm_makfromstrs (int argc, char **argv)
    strings by claiming they're shared substrings of a string we just
    made up.  */
 SCM
-scm_take_str (char *s, int len)
+scm_take_str (char *s, size_t len)
 #define FUNC_NAME "scm_take_str"
 {
   SCM answer;
@@ -191,8 +191,21 @@ scm_take0str (char *s)
   return scm_take_str (s, strlen (s));
 }
 
+#if (SCM_DEBUG_DEPRECATED == 0)
+
+SCM 
+scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
+{
+  scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
+                                  "Use `scm_mem2string' instead.");
+
+  return scm_mem2string (src, len);
+}
+
+#endif
+
 SCM 
-scm_makfromstr (const char *src, scm_sizet len, int dummy)
+scm_mem2string (const char *src, size_t len)
 {
   SCM s = scm_allocate_string (len);
   char *dst = SCM_STRING_CHARS (s);
@@ -206,7 +219,7 @@ SCM
 scm_makfrom0str (const char *src)
 {
   if (!src) return SCM_BOOL_F;
-  return scm_makfromstr (src, (scm_sizet) strlen (src), 0);
+  return scm_mem2string (src, strlen (src));
 }
 
 
@@ -218,7 +231,7 @@ scm_makfrom0str_opt (const char *src)
 
 
 SCM
-scm_allocate_string (scm_sizet len)
+scm_allocate_string (size_t len)
 #define FUNC_NAME "scm_allocate_string"
 {
   char *mem;
@@ -290,7 +303,7 @@ SCM_DEFINE (scm_string_ref, "string-ref", 2, 0, 0,
            "indexing. @var{k} must be a valid index of @var{str}.")
 #define FUNC_NAME s_scm_string_ref
 {
-  int idx;
+  long idx;
 
   SCM_VALIDATE_STRING (1, str);
   SCM_VALIDATE_INUM_COPY (2, k, idx);
@@ -332,6 +345,7 @@ SCM_DEFINE (scm_substring, "substring", 2, 1, 0,
 {
   long int from;
   long int to;
+  SCM substr;
 
   SCM_VALIDATE_STRING (1, str);
   SCM_VALIDATE_INUM (2, start);
@@ -342,7 +356,9 @@ SCM_DEFINE (scm_substring, "substring", 2, 1, 0,
   to = SCM_INUM (end);
   SCM_ASSERT_RANGE (3, end, from <= to && to <= SCM_STRING_LENGTH (str));
 
-  return scm_makfromstr (&SCM_STRING_CHARS (str)[from], (scm_sizet) (to - from), 0);
+  substr = scm_mem2string (&SCM_STRING_CHARS (str)[from], to - from);
+  scm_remember_upto_here_1 (str);
+  return substr;
 }
 #undef FUNC_NAME
 
@@ -354,7 +370,7 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
 #define FUNC_NAME s_scm_string_append
 {
   SCM res;
-  register long i = 0;
+  size_t i = 0;
   register SCM l, s;
   register unsigned char *data;
 
@@ -366,7 +382,7 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
   }
   res = scm_allocate_string (i);
   data = SCM_STRING_UCHARS (res);
-  for (l = args;SCM_NIMP (l);l = SCM_CDR (l)) {
+  for (l = args; !SCM_NULLP (l);l = SCM_CDR (l)) {
     s = SCM_CAR (l);
     for (i = 0;i<SCM_STRING_LENGTH (s);i++) *data++ = SCM_STRING_UCHARS (s)[i];
   }
@@ -384,7 +400,7 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
 
 SCM_DEFINE (scm_make_shared_substring, "make-shared-substring", 1, 2, 0,
            (SCM str, SCM start, SCM end),
-           "Return a shared substring of @var{str}.  The semantics are the\n"
+           "Return a shared substring of @var{str}.  The arguments are the\n"
            "same as for the @code{substring} function: the shared substring\n"
            "returned includes all of the text from @var{str} between\n"
            "indexes @var{start} (inclusive) and @var{end} (exclusive).  If\n"
@@ -437,6 +453,8 @@ SCM_DEFINE (scm_make_shared_substring, "make-shared-substring", 1, 2, 0,
 void
 scm_init_strings ()
 {
+  scm_nullstr = scm_allocate_string (0);
+
 #ifndef SCM_MAGIC_SNARFER
 #include "libguile/strings.x"
 #endif