diff options
author | Ludovic Courtès <ludo@gnu.org> | 2010-07-04 18:38:53 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2010-07-04 18:38:53 +0200 |
commit | 100e20c7fa1a3ae268152842a0781d9f867eda96 (patch) | |
tree | 74da66ac662c3fde2034758de14f458ce12f8715 /libguile/strings.c | |
parent | 6069e9733163cf802e806bfa55cb4fcc54fc6ac7 (diff) | |
download | guile-100e20c7fa1a3ae268152842a0781d9f867eda96.tar.gz |
Add `scm_i_string_data'.
* 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.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index d136d9835..6d2b7c079 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -82,12 +82,13 @@ #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 * |