Add `scm_i_string_data'.
authorLudovic Courtès <ludo@gnu.org>
Sun, 4 Jul 2010 16:38:53 +0000 (18:38 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sun, 4 Jul 2010 16:38:53 +0000 (18:38 +0200)
* libguile/strings.c (STRINGBUF_CONTENTS): New macro.
  (STRINGBUF_CHARS, STRINGBUF_WIDE_CHARS): Use it.
  (scm_i_string_data): New function.

* libguile/strings.h (scm_i_string_data): New declaration.

libguile/strings.c
libguile/strings.h

index d136d98..6d2b7c0 100644 (file)
 #define STRINGBUF_SHARED(buf)   (SCM_CELL_WORD_0(buf) & STRINGBUF_F_SHARED)
 #define STRINGBUF_WIDE(buf)     (SCM_CELL_WORD_0(buf) & STRINGBUF_F_WIDE)
 
-#define STRINGBUF_CHARS(buf)    ((unsigned char *)                     \
+#define STRINGBUF_CONTENTS(buf) ((void *)                              \
                                  SCM_CELL_OBJECT_LOC (buf,             \
                                                      STRINGBUF_HEADER_SIZE))
-#define STRINGBUF_LENGTH(buf)   (SCM_CELL_WORD_1 (buf))
+#define STRINGBUF_CHARS(buf)    ((unsigned char *) STRINGBUF_CONTENTS (buf))
+#define STRINGBUF_WIDE_CHARS(buf) ((scm_t_wchar *) STRINGBUF_CONTENTS (buf))
 
-#define STRINGBUF_WIDE_CHARS(buf) ((scm_t_wchar *) STRINGBUF_CHARS (buf))
+#define STRINGBUF_LENGTH(buf)   (SCM_CELL_WORD_1 (buf))
 
 #define SET_STRINGBUF_SHARED(buf)                                      \
   do                                                                   \
@@ -445,6 +446,23 @@ scm_i_try_narrow_string (SCM str)
   return scm_i_is_narrow_string (str);
 }
 
+/* Return a pointer to the raw data of the string, which can be either Latin-1
+   or UCS-4 encoded data, depending on `scm_i_is_narrow_string (STR)'.  */
+const void *
+scm_i_string_data (SCM str)
+{
+  SCM buf;
+  size_t start;
+  const char *data;
+
+  get_str_buf_start (&str, &buf, &start);
+
+  data = STRINGBUF_CONTENTS (buf);
+  data += start * (scm_i_is_narrow_string (str) ? 1 : 4);
+
+  return data;
+}
+
 /* Returns a pointer to the 8-bit Latin-1 encoded character array of
    STR.  */
 const char *
index 6eafafa..ad9518c 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef SCM_STRINGS_H
 #define SCM_STRINGS_H
 
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2005, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -172,6 +172,8 @@ SCM_INTERNAL size_t scm_i_string_length (SCM str);
 SCM_API /* FIXME: not internal */ const char *scm_i_string_chars (SCM str);
 SCM_API /* FIXME: not internal */ char *scm_i_string_writable_chars (SCM str);
 SCM_INTERNAL const scm_t_wchar *scm_i_string_wide_chars (SCM str);
+SCM_INTERNAL const void *scm_i_string_data (SCM str);
+
 SCM_INTERNAL SCM scm_i_string_start_writing (SCM str);
 SCM_INTERNAL void scm_i_string_stop_writing (void);
 SCM_INTERNAL int scm_i_is_narrow_string (SCM str);