mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-07 08:40:21 +02:00
Replaced SCM_STRINGP, SCM_STRING_CHARS, and
SCM_STRING_LENGTH with SCM_I_STRINGP, SCM_I_STRING_CHARS, and SCM_I_STRING_LENGTH, respectively. (gh_scm2newstr): Implement in terms of scm_to_locale_string.
This commit is contained in:
parent
24d1f17168
commit
79c98b33fe
1 changed files with 14 additions and 27 deletions
|
@ -80,10 +80,10 @@ gh_set_substr (char *src, SCM dst, long start, size_t len)
|
||||||
char *dst_ptr;
|
char *dst_ptr;
|
||||||
size_t dst_len;
|
size_t dst_len;
|
||||||
|
|
||||||
SCM_ASSERT (SCM_STRINGP (dst), dst, SCM_ARG3, "gh_set_substr");
|
SCM_ASSERT (SCM_I_STRINGP (dst), dst, SCM_ARG3, "gh_set_substr");
|
||||||
|
|
||||||
dst_ptr = SCM_STRING_CHARS (dst);
|
dst_ptr = SCM_I_STRING_CHARS (dst);
|
||||||
dst_len = SCM_STRING_LENGTH (dst);
|
dst_len = SCM_I_STRING_LENGTH (dst);
|
||||||
SCM_ASSERT (start + len <= dst_len, dst, SCM_ARG4, "gh_set_substr");
|
SCM_ASSERT (start + len <= dst_len, dst, SCM_ARG4, "gh_set_substr");
|
||||||
|
|
||||||
memmove (dst_ptr + start, src, len);
|
memmove (dst_ptr + start, src, len);
|
||||||
|
@ -259,12 +259,12 @@ gh_scm2chars (SCM obj, char *m)
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case scm_tc7_string:
|
case scm_tc7_string:
|
||||||
n = SCM_STRING_LENGTH (obj);
|
n = SCM_I_STRING_LENGTH (obj);
|
||||||
if (m == 0)
|
if (m == 0)
|
||||||
m = (char *) malloc (n * sizeof (char));
|
m = (char *) malloc (n * sizeof (char));
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
memcpy (m, SCM_VELTS (obj), n * sizeof (char));
|
memcpy (m, SCM_I_STRING_CHARS (obj), n * sizeof (char));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
scm_wrong_type_arg (0, 0, obj);
|
scm_wrong_type_arg (0, 0, obj);
|
||||||
|
@ -518,30 +518,17 @@ char *
|
||||||
gh_scm2newstr (SCM str, size_t *lenp)
|
gh_scm2newstr (SCM str, size_t *lenp)
|
||||||
{
|
{
|
||||||
char *ret_str;
|
char *ret_str;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
SCM_ASSERT (SCM_STRINGP (str), str, SCM_ARG3, "gh_scm2newstr");
|
/* We can't use scm_to_locale_stringn directly since it does not
|
||||||
|
guarantee null-termination when lenp is non-NULL.
|
||||||
len = SCM_STRING_LENGTH (str);
|
*/
|
||||||
|
|
||||||
ret_str = (char *) malloc ((len + 1) * sizeof (char));
|
|
||||||
if (ret_str == NULL)
|
|
||||||
return NULL;
|
|
||||||
/* so we copy tmp_str to ret_str, which is what we will allocate */
|
|
||||||
memcpy (ret_str, SCM_STRING_CHARS (str), len);
|
|
||||||
scm_remember_upto_here_1 (str);
|
|
||||||
/* now make sure we null-terminate it */
|
|
||||||
ret_str[len] = '\0';
|
|
||||||
|
|
||||||
if (lenp != NULL)
|
|
||||||
{
|
|
||||||
*lenp = len;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ret_str = scm_to_locale_string (str);
|
||||||
|
if (lenp)
|
||||||
|
*lenp = SCM_I_STRING_LENGTH (str);
|
||||||
return ret_str;
|
return ret_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Copy LEN characters at START from the Scheme string SRC to memory
|
/* Copy LEN characters at START from the Scheme string SRC to memory
|
||||||
at DST. START is an index into SRC; zero means the beginning of
|
at DST. START is an index into SRC; zero means the beginning of
|
||||||
the string. DST has already been allocated by the caller.
|
the string. DST has already been allocated by the caller.
|
||||||
|
@ -553,11 +540,11 @@ void
|
||||||
gh_get_substr (SCM src, char *dst, long start, size_t len)
|
gh_get_substr (SCM src, char *dst, long start, size_t len)
|
||||||
{
|
{
|
||||||
size_t src_len, effective_length;
|
size_t src_len, effective_length;
|
||||||
SCM_ASSERT (SCM_STRINGP (src), src, SCM_ARG3, "gh_get_substr");
|
SCM_ASSERT (SCM_I_STRINGP (src), src, SCM_ARG3, "gh_get_substr");
|
||||||
|
|
||||||
src_len = SCM_STRING_LENGTH (src);
|
src_len = SCM_I_STRING_LENGTH (src);
|
||||||
effective_length = (len < src_len) ? len : src_len;
|
effective_length = (len < src_len) ? len : src_len;
|
||||||
memcpy (dst + start, SCM_STRING_CHARS (src), effective_length * sizeof (char));
|
memcpy (dst + start, SCM_I_STRING_CHARS (src), effective_length * sizeof (char));
|
||||||
/* FIXME: must signal an error if len > src_len */
|
/* FIXME: must signal an error if len > src_len */
|
||||||
scm_remember_upto_here_1 (src);
|
scm_remember_upto_here_1 (src);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue