diff options
author | Andy Wingo <wingo@pobox.com> | 2016-05-22 20:15:09 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-05-22 20:21:49 +0200 |
commit | 2badbd06f695127039e8772f56e9ba44ec875896 (patch) | |
tree | af8b65cfe476fa4f783b491a6fd920a4e0a90782 /libguile/strings.c | |
parent | fd17cf9f72bcfc1832775c848e678e695d05dbd8 (diff) | |
parent | a7d0a0de2fa5fd99f001b1c6d42c0ae497a2cb1f (diff) | |
download | guile-2badbd06f695127039e8772f56e9ba44ec875896.tar.gz |
Merge from stable-2.0
This cherry-picks changes from stable-2.0, starting from
acd2c8e36a25d77e9e9c9b6782780b23a1764973 and ending in
461b62efc90135d3ca8719ba0f3b6ced4ad13754, inclusively. I did not
cherry-pick patches that were already on master and did not cherry-pick
ones that don't make sense on master (for example because of the port
re-write). I did pick all tests though.
I also did not cherry-pick the "Revert foreign objects" patch from
ff98cbb643d43c9f8c6ee0e0b4e1bad72aced62e; further discussion necessary.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 2e5647e6d..dc2e4f5fe 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -1,5 +1,5 @@ /* Copyright (C) 1995, 1996, 1998, 2000, 2001, 2004, 2006, - * 2008-2015 Free Software Foundation, Inc. + * 2008-2016 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 @@ -2065,6 +2065,38 @@ u32_u8_length_in_bytes (const scm_t_uint32 *str, size_t len) return ret; } +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), + scm_i_string_length (str)); + else + return u32_u8_length_in_bytes + ((scm_t_uint32 *) scm_i_string_wide_chars (str), + scm_i_string_length (str)); +} + +size_t +scm_c_string_utf8_length (SCM string) +#define FUNC_NAME "scm_c_string_utf8_length" +{ + SCM_VALIDATE_STRING (1, string); + return utf8_length (string); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_string_utf8_length, "string-utf8-length", 1, 0, 0, + (SCM string), + "Returns the number of bytes in the UTF-8 representation of " + "@var{string}.") +#define FUNC_NAME s_scm_string_utf8_length +{ + SCM_VALIDATE_STRING (1, string); + return scm_from_size_t (utf8_length (string)); +} +#undef FUNC_NAME + char * scm_to_utf8_stringn (SCM str, size_t *lenp) #define FUNC_NAME "scm_to_utf8_stringn" |