1 /* Copyright (C) 1999,2000,2001,2003 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 /* some bits originally by Jim Blandy <jimb@red-bean.com> */
21 #include "libguile/gh.h"
27 string_equal (SCM str
, char *lit
)
29 int len
= strlen (lit
);
32 result
= ((scm_i_string_length (str
) == len
)
33 && (!memcmp (scm_i_string_chars (str
), lit
, len
)));
34 scm_remember_upto_here_1 (str
);
43 string
= gh_str02scm ("Free, darnit!");
44 assert (gh_string_p (string
));
46 gh_set_substr ("dammit", string
, 6, 6);
47 assert (string_equal (string
, "Free, dammit!"));
49 /* Make sure that we can use the string itself as a source.
51 I guess this behavior isn't really visible, since the GH API
52 doesn't provide any direct access to the string contents. But I
53 think it should, eventually. You can't write efficient string
54 code if you have to copy the string just to look at it. */
56 /* Copy a substring to an overlapping region to its right. */
57 gh_set_substr (scm_i_string_chars (string
), string
, 4, 6);
58 assert (string_equal (string
, "FreeFree, it!"));
60 string
= gh_str02scm ("Free, darnit!");
61 assert (gh_string_p (string
));
63 /* Copy a substring to an overlapping region to its left. */
64 gh_set_substr (scm_i_string_chars (string
) + 6, string
, 2, 6);
65 assert (string_equal (string
, "Frdarnitrnit!"));
69 main (int argc
, char *argv
[])
72 test_gh_set_substr ();