diff options
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 131 |
1 files changed, 65 insertions, 66 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 180fae1ce..aab104498 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -1,21 +1,21 @@ -/* Copyright (C) 1995, 1996, 1998, 2000, 2001, 2004, 2006, - * 2008-2016, 2018, 2019 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 - * as published by the Free Software Foundation; either version 3 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ +/* Copyright 1995-1996,1998,2000-2001,2004,2006,2008-2016,2018-2019 + Free Software Foundation, Inc. + + This file is part of Guile. + + Guile is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Guile is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Guile. If not, see + <https://www.gnu.org/licenses/>. */ @@ -27,24 +27,29 @@ #include <string.h> #include <stdio.h> #include <ctype.h> +#include <errno.h> #include <uninorm.h> #include <unistr.h> #include <uniconv.h> #include <c-strcase.h> #include <intprops.h> +#include "chars.h" +#include "deprecation.h" +#include "error.h" +#include "generalized-vectors.h" +#include "gsubr.h" +#include "numbers.h" +#include "pairs.h" +#include "ports-internal.h" +#include "ports.h" +#include "private-options.h" #include "striconveh.h" +#include "symbols.h" +#include "threads.h" + +#include "strings.h" -#include "libguile/_scm.h" -#include "libguile/chars.h" -#include "libguile/strings.h" -#include "libguile/ports.h" -#include "libguile/ports-internal.h" -#include "libguile/error.h" -#include "libguile/generalized-vectors.h" -#include "libguile/deprecation.h" -#include "libguile/validate.h" -#include "libguile/private-options.h" #ifndef SCM_MAX_ALLOCA # define SCM_MAX_ALLOCA 4096 /* Max bytes per string to allocate via alloca */ @@ -163,7 +168,7 @@ make_wide_stringbuf (size_t len) if (len > (((size_t) -(STRINGBUF_HEADER_BYTES + 32 + sizeof (scm_t_wchar))) / sizeof (scm_t_wchar))) scm_num_overflow ("make_wide_stringbuf"); - + raw_len = (len + 1) * sizeof (scm_t_wchar); buf = SCM_PACK_POINTER (scm_gc_malloc_pointerless (STRINGBUF_HEADER_BYTES + raw_len, "string")); @@ -378,8 +383,8 @@ substring_with_immutable_stringbuf (SCM str, size_t start, size_t end, if (STRINGBUF_WIDE (buf)) { new_buf = make_wide_stringbuf (len); - u32_cpy ((scm_t_uint32 *) STRINGBUF_WIDE_CHARS (new_buf), - (scm_t_uint32 *) (STRINGBUF_WIDE_CHARS (buf) + start), len); + u32_cpy ((uint32_t *) STRINGBUF_WIDE_CHARS (new_buf), + (uint32_t *) (STRINGBUF_WIDE_CHARS (buf) + start), len); new_str = scm_double_cell (tag, SCM_UNPACK (new_buf), 0, len); scm_i_try_narrow_string (new_str); } @@ -446,8 +451,8 @@ scm_i_string_ensure_mutable_x (SCM str) if (STRINGBUF_WIDE (buf)) { new_buf = make_wide_stringbuf (len); - u32_cpy ((scm_t_uint32 *) STRINGBUF_WIDE_CHARS (new_buf), - (scm_t_uint32 *) STRINGBUF_WIDE_CHARS (buf), len); + u32_cpy ((uint32_t *) STRINGBUF_WIDE_CHARS (new_buf), + (uint32_t *) STRINGBUF_WIDE_CHARS (buf), len); } else { @@ -933,8 +938,8 @@ SCM_DEFINE (scm_sys_string_dump, "%string-dump", 1, 0, 0, (SCM str), size_t len = STRINGBUF_LENGTH (buf); scm_t_wchar *cbuf; SCM sbc = scm_i_make_wide_string (len, &cbuf, 0); - u32_cpy ((scm_t_uint32 *) cbuf, - (scm_t_uint32 *) STRINGBUF_WIDE_CHARS (buf), len); + u32_cpy ((uint32_t *) cbuf, + (uint32_t *) STRINGBUF_WIDE_CHARS (buf), len); e6 = scm_cons (scm_from_latin1_symbol ("stringbuf-chars"), sbc); } @@ -1006,8 +1011,8 @@ SCM_DEFINE (scm_sys_symbol_dump, "%symbol-dump", 1, 0, 0, (SCM sym), size_t len = STRINGBUF_LENGTH (buf); scm_t_wchar *cbuf; SCM sbc = scm_i_make_wide_string (len, &cbuf, 0); - u32_cpy ((scm_t_uint32 *) cbuf, - (scm_t_uint32 *) STRINGBUF_WIDE_CHARS (buf), len); + u32_cpy ((uint32_t *) cbuf, + (uint32_t *) STRINGBUF_WIDE_CHARS (buf), len); e4 = scm_cons (scm_from_latin1_symbol ("stringbuf-chars"), sbc); } @@ -1436,8 +1441,8 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1, data.wide[i] = (unsigned char) src[i]; } else - u32_cpy ((scm_t_uint32 *) data.wide, - (scm_t_uint32 *) scm_i_string_wide_chars (s), len); + u32_cpy ((uint32_t *) data.wide, + (uint32_t *) scm_i_string_wide_chars (s), len); data.wide += len; } total -= len; @@ -1555,7 +1560,7 @@ scm_from_stringn (const char *str, size_t len, const char *encoding, { scm_t_wchar *wdst; res = scm_i_make_wide_string (u32len, &wdst, 0); - u32_cpy ((scm_t_uint32 *) wdst, (scm_t_uint32 *) u32, u32len); + u32_cpy ((uint32_t *) wdst, (uint32_t *) u32, u32len); wdst[u32len] = 0; } @@ -1615,7 +1620,7 @@ SCM scm_from_utf8_stringn (const char *str, size_t len) { size_t i, char_len; - const scm_t_uint8 *ustr = (const scm_t_uint8 *) str; + const uint8_t *ustr = (const uint8_t *) str; int ascii = 1, narrow = 1; SCM res; @@ -1949,7 +1954,7 @@ scm_to_utf8_string (SCM str) } static size_t -latin1_u8_strlen (const scm_t_uint8 *str, size_t len) +latin1_u8_strlen (const uint8_t *str, size_t len) { size_t ret, i; for (i = 0, ret = 0; i < len; i++) @@ -1957,9 +1962,9 @@ latin1_u8_strlen (const scm_t_uint8 *str, size_t len) return ret; } -static scm_t_uint8* -latin1_to_u8 (const scm_t_uint8 *str, size_t latin_len, - scm_t_uint8 *u8_result, size_t *u8_lenp) +static uint8_t* +latin1_to_u8 (const uint8_t *str, size_t latin_len, + uint8_t *u8_result, size_t *u8_lenp) { size_t i, n; size_t u8_len = latin1_u8_strlen (str, latin_len); @@ -1999,13 +2004,13 @@ latin1_to_u8 (const scm_t_uint8 *str, size_t latin_len, */ static size_t -u32_u8_length_in_bytes (const scm_t_uint32 *str, size_t len) +u32_u8_length_in_bytes (const uint32_t *str, size_t len) { size_t ret, i; for (i = 0, ret = 0; i < len; i++) { - scm_t_uint32 c = str[i]; + uint32_t c = str[i]; if (c <= 0x7f) ret += 1; @@ -2028,11 +2033,11 @@ static size_t utf8_length (SCM str) { if (scm_i_is_narrow_string (str)) - return latin1_u8_strlen ((scm_t_uint8 *) scm_i_string_chars (str), + return latin1_u8_strlen ((uint8_t *) scm_i_string_chars (str), scm_i_string_length (str)); else return u32_u8_length_in_bytes - ((scm_t_uint32 *) scm_i_string_wide_chars (str), + ((uint32_t *) scm_i_string_wide_chars (str), scm_i_string_length (str)); } @@ -2063,13 +2068,13 @@ scm_to_utf8_stringn (SCM str, size_t *lenp) SCM_VALIDATE_STRING (1, str); if (scm_i_is_narrow_string (str)) - return (char *) latin1_to_u8 ((scm_t_uint8 *) scm_i_string_chars (str), + return (char *) latin1_to_u8 ((uint8_t *) scm_i_string_chars (str), scm_i_string_length (str), NULL, lenp); else { - scm_t_uint32 *chars = (scm_t_uint32 *) scm_i_string_wide_chars (str); - scm_t_uint8 *buf, *ret; + uint32_t *chars = (uint32_t *) scm_i_string_wide_chars (str); + uint8_t *buf, *ret; size_t num_chars = scm_i_string_length (str); size_t num_bytes_predicted, num_bytes_actual; @@ -2126,10 +2131,10 @@ scm_to_utf32_stringn (SCM str, size_t *lenp) if (scm_i_is_narrow_string (str)) { - scm_t_uint8 *codepoints; + uint8_t *codepoints; size_t i, len; - codepoints = (scm_t_uint8*) scm_i_string_chars (str); + codepoints = (uint8_t*) scm_i_string_chars (str); len = scm_i_string_length (str); if (lenp) *lenp = len; @@ -2262,7 +2267,7 @@ scm_to_stringn (SCM str, size_t *lenp, const char *encoding, { buf = u32_conv_to_encoding (encoding, (enum iconv_ilseq_handler) handler, - (scm_t_uint32 *) scm_i_string_wide_chars (str), + (uint32_t *) scm_i_string_wide_chars (str), ilen, NULL, NULL, &len); @@ -2333,8 +2338,8 @@ static SCM normalize_str (SCM string, uninorm_t form) { SCM ret; - scm_t_uint32 *w_str; - scm_t_uint32 *w_norm_str; + uint32_t *w_str; + uint32_t *w_norm_str; scm_t_wchar *cbuf; int malloc_p; size_t norm_len, len = scm_i_string_length (string); @@ -2355,13 +2360,13 @@ normalize_str (SCM string, uninorm_t form) else { malloc_p = 0; - w_str = (scm_t_uint32 *) scm_i_string_wide_chars (string); + w_str = (uint32_t *) scm_i_string_wide_chars (string); } w_norm_str = u32_normalize (form, w_str, len, NULL, &norm_len); ret = scm_i_make_wide_string (norm_len, &cbuf, 0); - u32_cpy ((scm_t_uint32 *) cbuf, w_norm_str, norm_len); + u32_cpy ((uint32_t *) cbuf, w_norm_str, norm_len); free (w_norm_str); if (malloc_p) free (w_str); @@ -2495,12 +2500,6 @@ scm_init_strings () { scm_nullstr = scm_i_make_string (0, NULL, 0); -#include "libguile/strings.x" +#include "strings.x" } - -/* - Local Variables: - c-file-style: "gnu" - End: -*/ |