Commit | Line | Data |
---|---|---|
6e7d5622 | 1 | /* Copyright (C) 1999,2000,2001,2003, 2006 Free Software Foundation, Inc. |
51a186f7 RB |
2 | * |
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. | |
7 | * | |
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. | |
12 | * | |
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 | |
92205699 | 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
51a186f7 RB |
16 | */ |
17 | ||
18 | /* some bits originally by Jim Blandy <jimb@red-bean.com> */ | |
19 | ||
20 | #include "libguile.h" | |
21 | #include "libguile/gh.h" | |
22 | ||
23 | #include <assert.h> | |
24 | #include <string.h> | |
25 | ||
c70c62a6 MV |
26 | #if SCM_ENABLE_DEPRECATED |
27 | ||
51a186f7 RB |
28 | static int |
29 | string_equal (SCM str, char *lit) | |
30 | { | |
31 | int len = strlen (lit); | |
32 | int result; | |
33 | ||
ad6dec05 MV |
34 | result = ((scm_i_string_length (str) == len) |
35 | && (!memcmp (scm_i_string_chars (str), lit, len))); | |
51a186f7 RB |
36 | scm_remember_upto_here_1 (str); |
37 | return result; | |
38 | } | |
39 | ||
40 | static void | |
41 | test_gh_set_substr () | |
42 | { | |
43 | SCM string; | |
44 | ||
45 | string = gh_str02scm ("Free, darnit!"); | |
46 | assert (gh_string_p (string)); | |
47 | ||
48 | gh_set_substr ("dammit", string, 6, 6); | |
49 | assert (string_equal (string, "Free, dammit!")); | |
50 | ||
51 | /* Make sure that we can use the string itself as a source. | |
52 | ||
53 | I guess this behavior isn't really visible, since the GH API | |
54 | doesn't provide any direct access to the string contents. But I | |
55 | think it should, eventually. You can't write efficient string | |
56 | code if you have to copy the string just to look at it. */ | |
57 | ||
58 | /* Copy a substring to an overlapping region to its right. */ | |
ad6dec05 | 59 | gh_set_substr (scm_i_string_chars (string), string, 4, 6); |
51a186f7 RB |
60 | assert (string_equal (string, "FreeFree, it!")); |
61 | ||
62 | string = gh_str02scm ("Free, darnit!"); | |
63 | assert (gh_string_p (string)); | |
64 | ||
65 | /* Copy a substring to an overlapping region to its left. */ | |
ad6dec05 | 66 | gh_set_substr (scm_i_string_chars (string) + 6, string, 2, 6); |
51a186f7 RB |
67 | assert (string_equal (string, "Frdarnitrnit!")); |
68 | } | |
69 | ||
8ab3d8a0 KR |
70 | static void |
71 | tests (void *data, int argc, char **argv) | |
51a186f7 | 72 | { |
51a186f7 | 73 | test_gh_set_substr (); |
8ab3d8a0 KR |
74 | } |
75 | ||
76 | int | |
77 | main (int argc, char *argv[]) | |
78 | { | |
79 | scm_boot_guile (argc, argv, tests, NULL); | |
51a186f7 RB |
80 | return 0; |
81 | } | |
c70c62a6 MV |
82 | |
83 | #else | |
84 | ||
85 | int | |
86 | main (int argc, char *argv[]) | |
87 | { | |
88 | return 0; | |
89 | } | |
90 | ||
91 | #endif /* !SCM_ENABLE_DEPRECATED */ |