mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-14 07:30:32 +02:00
Use string accessors for string->number conversion
* libguile/numbers.c (scm_i_print_fraction): use string accessors (XDIGIT2UINT): use libunistring function (mem2uinteger, mem2integer, mem2decimal_from_point, mem2ureal) (mem2complex): take scheme string instead of c string; use accessors (scm_i_string_to_number): new function (scm_c_locale_string_to_number): use scm_i_string_to_number * libguile/numbers.h: declaration for scm_i_string_to_number * libguile/strings.c (scm_i_string_strcmp): new function * libguile/strings.h: declaration for scm_i_string_strcmp
This commit is contained in:
parent
e23106d53e
commit
3f47e52621
4 changed files with 93 additions and 55 deletions
|
@ -590,6 +590,29 @@ scm_i_string_ref (SCM str, size_t x)
|
|||
return scm_i_string_wide_chars (str)[x];
|
||||
}
|
||||
|
||||
int
|
||||
scm_i_string_strcmp (SCM sstr, size_t start_x, const char *cstr)
|
||||
{
|
||||
if (scm_i_is_narrow_string (sstr))
|
||||
{
|
||||
const char *a = scm_i_string_chars (sstr) + start_x;
|
||||
const char *b = cstr;
|
||||
return strncmp (a, b, strlen(b));
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t i;
|
||||
const scm_t_wchar *a = scm_i_string_wide_chars (sstr) + start_x;
|
||||
const char *b = cstr;
|
||||
for (i = 0; i < strlen (b); i++)
|
||||
{
|
||||
if (a[i] != (unsigned char) b[i])
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the Pth character of STR to UCS-4 codepoint CHR. */
|
||||
void
|
||||
scm_i_string_set_x (SCM str, size_t p, scm_t_wchar chr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue