1 /* classes: src_files */
3 /* Copyright (C) 1994 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this software; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 scm_i_index (SCM
* str
, SCM chr
, SCM sub_start
, SCM sub_end
, int pos
, int pos2
, int pos3
, int pos4
, char * why
)
31 scm_i_index (str
, chr
, sub_start
, sub_end
, pos
, pos2
, pos3
, pos4
, why
)
48 SCM_ASSERT (SCM_NIMP (*str
) && SCM_ROSTRINGP (*str
), *str
, pos
, why
);
49 SCM_ASSERT (SCM_ICHRP (chr
), chr
, pos2
, why
);
51 if (sub_start
== SCM_BOOL_F
)
52 sub_start
= SCM_MAKINUM (0);
54 SCM_ASSERT ( SCM_INUMP (sub_start
)
55 && (0 <= SCM_INUM (sub_start
))
56 && (SCM_INUM (sub_start
) <= SCM_ROLENGTH (*str
)),
57 sub_start
, pos3
, why
);
59 if (sub_end
== SCM_BOOL_F
)
60 sub_end
= SCM_MAKINUM (SCM_ROLENGTH (*str
));
62 SCM_ASSERT ( SCM_INUMP (sub_end
)
63 && (SCM_INUM (sub_start
) <= SCM_INUM (sub_end
))
64 && (SCM_INUM (sub_end
) <= SCM_ROLENGTH (*str
)),
67 p
= (unsigned char *)SCM_ROCHARS (*str
) + SCM_INUM (sub_start
);
68 bound
= SCM_INUM (sub_end
);
71 for (x
= SCM_INUM (sub_start
); x
< bound
; ++x
, ++p
)
80 scm_i_rindex (SCM
* str
, SCM chr
, SCM sub_start
, SCM sub_end
, int pos
, int pos2
, int pos3
, int pos4
, char * why
)
83 scm_i_rindex (str
, chr
, sub_start
, sub_end
, pos
, pos2
, pos3
, pos4
, why
)
101 SCM_ASSERT (SCM_NIMP (*str
) && SCM_ROSTRINGP (*str
), *str
, pos
, why
);
102 SCM_ASSERT (SCM_ICHRP (chr
), chr
, pos2
, why
);
104 if (sub_start
== SCM_BOOL_F
)
105 sub_start
= SCM_MAKINUM (0);
107 SCM_ASSERT ( SCM_INUMP (sub_start
)
108 && (0 <= SCM_INUM (sub_start
))
109 && (SCM_INUM (sub_start
) <= SCM_ROLENGTH (*str
)),
110 sub_start
, pos3
, why
);
112 if (sub_end
== SCM_BOOL_F
)
113 sub_end
= SCM_MAKINUM (SCM_ROLENGTH (*str
));
115 SCM_ASSERT ( SCM_INUMP (sub_end
)
116 && (SCM_INUM (sub_start
) <= SCM_INUM (sub_end
))
117 && (SCM_INUM (sub_end
) <= SCM_ROLENGTH (*str
)),
120 upper_bound
= SCM_INUM (sub_end
);
121 lower_bound
= SCM_INUM (sub_start
);
122 p
= upper_bound
- 1 + (unsigned char *)SCM_ROCHARS (*str
);
124 for (x
= upper_bound
- 1; x
>= lower_bound
; --x
, --p
)
132 SCM_PROC(s_string_index
, "string-index", 2, 2, 0, scm_string_index
);
135 scm_string_index (SCM str
, SCM chr
, SCM frm
, SCM to
)
138 scm_string_index (str
, chr
, frm
, to
)
147 if (frm
== SCM_UNDEFINED
)
149 if (to
== SCM_UNDEFINED
)
151 pos
= scm_i_index (&str
, chr
, frm
, to
, SCM_ARG1
, SCM_ARG2
, SCM_ARG3
, SCM_ARG4
, s_string_index
);
154 : SCM_MAKINUM (pos
));
157 SCM_PROC(s_string_rindex
, "string-rindex", 2, 2, 0, scm_string_rindex
);
160 scm_string_rindex (SCM str
, SCM chr
, SCM frm
, SCM to
)
163 scm_string_rindex (str
, chr
, frm
, to
)
172 if (frm
== SCM_UNDEFINED
)
174 if (to
== SCM_UNDEFINED
)
176 pos
= scm_i_rindex (&str
, chr
, frm
, to
, SCM_ARG1
, SCM_ARG2
, SCM_ARG3
, SCM_ARG4
, s_string_index
);
179 : SCM_MAKINUM (pos
));
187 SCM_PROC(s_substring_move_left_x
, "substring-move-left!", 2, 0, 1, scm_substring_move_left_x
);
190 scm_substring_move_left_x (SCM str1
, SCM start1
, SCM args
)
193 scm_substring_move_left_x (str1
, start1
, args
)
199 SCM end1
, str2
, start2
;
201 SCM_ASSERT (3==scm_ilength (args
), args
, SCM_WNA
, s_substring_move_left_x
);
202 end1
= SCM_CAR (args
); args
= SCM_CDR (args
);
203 str2
= SCM_CAR (args
); args
= SCM_CDR (args
);
204 start2
= SCM_CAR (args
);
205 SCM_ASSERT (SCM_NIMP (str1
) && SCM_STRINGP (str1
), str1
, SCM_ARG1
, s_substring_move_left_x
);
206 SCM_ASSERT (SCM_INUMP (start1
), start1
, SCM_ARG2
, s_substring_move_left_x
);
207 SCM_ASSERT (SCM_INUMP (end1
), end1
, SCM_ARG3
, s_substring_move_left_x
);
208 SCM_ASSERT (SCM_NIMP (str2
) && SCM_STRINGP (str2
), str2
, SCM_ARG4
, s_substring_move_left_x
);
209 SCM_ASSERT (SCM_INUMP (start2
), start2
, SCM_ARG5
, s_substring_move_left_x
);
210 i
= SCM_INUM (start1
), j
= SCM_INUM (start2
), e
= SCM_INUM (end1
);
211 SCM_ASSERT (i
<= SCM_LENGTH (str1
) && i
>= 0, start1
, SCM_OUTOFRANGE
, s_substring_move_left_x
);
212 SCM_ASSERT (j
<= SCM_LENGTH (str2
) && j
>= 0, start2
, SCM_OUTOFRANGE
, s_substring_move_left_x
);
213 SCM_ASSERT (e
<= SCM_LENGTH (str1
) && e
>= 0, end1
, SCM_OUTOFRANGE
, s_substring_move_left_x
);
214 SCM_ASSERT (e
-i
+j
<= SCM_LENGTH (str2
), start2
, SCM_OUTOFRANGE
, s_substring_move_left_x
);
215 while (i
<e
) SCM_CHARS (str2
)[j
++] = SCM_CHARS (str1
)[i
++];
216 return SCM_UNSPECIFIED
;
220 SCM_PROC(s_substring_move_right_x
, "substring-move-right!", 2, 0, 1, scm_substring_move_right_x
);
223 scm_substring_move_right_x (SCM str1
, SCM start1
, SCM args
)
226 scm_substring_move_right_x (str1
, start1
, args
)
232 SCM end1
, str2
, start2
;
234 SCM_ASSERT (3==scm_ilength (args
), args
, SCM_WNA
, s_substring_move_right_x
);
235 end1
= SCM_CAR (args
); args
= SCM_CDR (args
);
236 str2
= SCM_CAR (args
); args
= SCM_CDR (args
);
237 start2
= SCM_CAR (args
);
238 SCM_ASSERT (SCM_NIMP (str1
) && SCM_STRINGP (str1
), str1
, SCM_ARG1
, s_substring_move_right_x
);
239 SCM_ASSERT (SCM_INUMP (start1
), start1
, SCM_ARG2
, s_substring_move_right_x
);
240 SCM_ASSERT (SCM_INUMP (end1
), end1
, SCM_ARG3
, s_substring_move_right_x
);
241 SCM_ASSERT (SCM_NIMP (str2
) && SCM_STRINGP (str2
), str2
, SCM_ARG4
, s_substring_move_right_x
);
242 SCM_ASSERT (SCM_INUMP (start2
), start2
, SCM_ARG5
, s_substring_move_right_x
);
243 i
= SCM_INUM (start1
), j
= SCM_INUM (start2
), e
= SCM_INUM (end1
);
244 SCM_ASSERT (i
<= SCM_LENGTH (str1
) && i
>= 0, start1
, SCM_OUTOFRANGE
, s_substring_move_right_x
);
245 SCM_ASSERT (j
<= SCM_LENGTH (str2
) && j
>= 0, start2
, SCM_OUTOFRANGE
, s_substring_move_right_x
);
246 SCM_ASSERT (e
<= SCM_LENGTH (str1
) && e
>= 0, end1
, SCM_OUTOFRANGE
, s_substring_move_right_x
);
247 SCM_ASSERT ((j
= e
-i
+j
) <= SCM_LENGTH (str2
), start2
, SCM_OUTOFRANGE
, s_substring_move_right_x
);
248 while (i
<e
) SCM_CHARS (str2
)[--j
] = SCM_CHARS (str1
)[--e
];
249 return SCM_UNSPECIFIED
;
253 SCM_PROC(s_substring_fill_x
, "substring-fill!", 2, 0, 1, scm_substring_fill_x
);
256 scm_substring_fill_x (SCM str
, SCM start
, SCM args
)
259 scm_substring_fill_x (str
, start
, args
)
268 SCM_ASSERT (2==scm_ilength (args
), args
, SCM_WNA
, s_substring_fill_x
);
269 end
= SCM_CAR (args
); args
= SCM_CDR (args
);
270 fill
= SCM_CAR (args
);
271 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_substring_fill_x
);
272 SCM_ASSERT (SCM_INUMP (start
), start
, SCM_ARG2
, s_substring_fill_x
);
273 SCM_ASSERT (SCM_INUMP (end
), end
, SCM_ARG3
, s_substring_fill_x
);
274 SCM_ASSERT (SCM_ICHRP (fill
), fill
, SCM_ARG4
, s_substring_fill_x
);
275 i
= SCM_INUM (start
), e
= SCM_INUM (end
);c
= SCM_ICHR (fill
);
276 SCM_ASSERT (i
<= SCM_LENGTH (str
) && i
>= 0, start
, SCM_OUTOFRANGE
, s_substring_fill_x
);
277 SCM_ASSERT (e
<= SCM_LENGTH (str
) && e
>= 0, end
, SCM_OUTOFRANGE
, s_substring_fill_x
);
278 while (i
<e
) SCM_CHARS (str
)[i
++] = c
;
279 return SCM_UNSPECIFIED
;
283 SCM_PROC(s_string_null_p
, "string-null?", 1, 0, 0, scm_string_null_p
);
286 scm_string_null_p (SCM str
)
289 scm_string_null_p (str
)
293 SCM_ASSERT (SCM_NIMP (str
) && SCM_ROSTRINGP (str
), str
, SCM_ARG1
, s_string_null_p
);
294 return (SCM_ROLENGTH (str
)
300 SCM_PROC(s_string_to_list
, "string->list", 1, 0, 0, scm_string_to_list
);
303 scm_string_to_list (SCM str
)
306 scm_string_to_list (str
)
313 SCM_ASSERT (SCM_NIMP (str
) && SCM_ROSTRINGP (str
), str
, SCM_ARG1
, s_string_to_list
);
314 src
= SCM_ROUCHARS (str
);
315 for (i
= SCM_ROLENGTH (str
)-1;i
>= 0;i
--) res
= scm_cons ((SCM
)SCM_MAKICHR (src
[i
]), res
);
321 SCM_PROC(s_string_copy
, "string-copy", 1, 0, 0, scm_string_copy
);
324 scm_string_copy (SCM str
)
327 scm_string_copy (str
)
331 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_string_copy
);
332 return scm_makfromstr (SCM_CHARS (str
), (scm_sizet
)SCM_LENGTH (str
), 0);
336 SCM_PROC(s_string_fill_x
, "string-fill!", 2, 0, 0, scm_string_fill_x
);
339 scm_string_fill_x (SCM str
, SCM chr
)
342 scm_string_fill_x (str
, chr
)
347 register char *dst
, c
;
349 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_string_fill_x
);
350 SCM_ASSERT (SCM_ICHRP (chr
), chr
, SCM_ARG2
, s_string_fill_x
);
352 dst
= SCM_CHARS (str
);
353 for (k
= SCM_LENGTH (str
)-1;k
>= 0;k
--) dst
[k
] = c
;
354 return SCM_UNSPECIFIED
;
360 scm_init_strop (void)