mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 14:50:19 +02:00
* strop.c (scm_string_split): New procedure.
* strop.h (scm_string_split): Added prototype.
This commit is contained in:
parent
76f944c3ca
commit
dd2a6f3ac6
3 changed files with 56 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2001-05-04 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
|
||||||
|
|
||||||
|
* strop.c (scm_string_split): New procedure.
|
||||||
|
|
||||||
|
* strop.h (scm_string_split): Added prototype.
|
||||||
|
|
||||||
2001-05-04 Gary Houston <ghouston@arglist.com>
|
2001-05-04 Gary Houston <ghouston@arglist.com>
|
||||||
|
|
||||||
* socket.c: define uint32_t if netdb.h doesn't. thanks to
|
* socket.c: define uint32_t if netdb.h doesn't. thanks to
|
||||||
|
|
|
@ -509,6 +509,55 @@ SCM_DEFINE (scm_string_capitalize, "string-capitalize", 1, 0, 0,
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
||||||
|
SCM_DEFINE (scm_string_split, "string-split", 2, 0, 0,
|
||||||
|
(SCM str, SCM chr),
|
||||||
|
"Split the string @var{str} into the a list of the substrings delimited\n"
|
||||||
|
"by appearances of the character @var{chr}. Note that an empty substring\n"
|
||||||
|
"between separator characters will result in an empty string in the\n"
|
||||||
|
"result list.\n"
|
||||||
|
"\n"
|
||||||
|
"@lisp\n"
|
||||||
|
"(string-split \"root:x:0:0:root:/root:/bin/bash\" #\:)\n"
|
||||||
|
"@result{}\n"
|
||||||
|
"(\"root\" \"x\" \"0\" \"0\" \"root\" \"/root\" \"/bin/bash\")\n"
|
||||||
|
"\n"
|
||||||
|
"(string-split \"::\" #\:)\n"
|
||||||
|
"@result{}\n"
|
||||||
|
"(\"\" \"\" \"\")\n"
|
||||||
|
"\n"
|
||||||
|
"(string-split \"\" #\:)\n"
|
||||||
|
"@result{}\n"
|
||||||
|
"(\"\")\n"
|
||||||
|
"@end lisp")
|
||||||
|
#define FUNC_NAME s_scm_string_split
|
||||||
|
{
|
||||||
|
int idx, last_idx;
|
||||||
|
char * p;
|
||||||
|
int ch;
|
||||||
|
SCM res = SCM_EOL;
|
||||||
|
|
||||||
|
SCM_VALIDATE_STRING (1, str);
|
||||||
|
SCM_VALIDATE_CHAR (2, chr);
|
||||||
|
|
||||||
|
idx = SCM_STRING_LENGTH (str);
|
||||||
|
p = SCM_STRING_CHARS (str);
|
||||||
|
ch = SCM_CHAR (chr);
|
||||||
|
while (idx >= 0)
|
||||||
|
{
|
||||||
|
last_idx = idx;
|
||||||
|
while (idx > 0 && p[idx - 1] != ch)
|
||||||
|
idx--;
|
||||||
|
if (idx >= 0)
|
||||||
|
{
|
||||||
|
res = scm_cons (scm_makfromstr (p + idx, last_idx - idx, 0), res);
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
||||||
SCM_DEFINE (scm_string_ci_to_symbol, "string-ci->symbol", 1, 0, 0,
|
SCM_DEFINE (scm_string_ci_to_symbol, "string-ci->symbol", 1, 0, 0,
|
||||||
(SCM str),
|
(SCM str),
|
||||||
"Return the symbol whose name is @var{str}. @var{str} is\n"
|
"Return the symbol whose name is @var{str}. @var{str} is\n"
|
||||||
|
|
|
@ -64,6 +64,7 @@ extern SCM scm_string_downcase_x (SCM v);
|
||||||
extern SCM scm_string_downcase (SCM v);
|
extern SCM scm_string_downcase (SCM v);
|
||||||
extern SCM scm_string_capitalize_x (SCM v);
|
extern SCM scm_string_capitalize_x (SCM v);
|
||||||
extern SCM scm_string_capitalize (SCM v);
|
extern SCM scm_string_capitalize (SCM v);
|
||||||
|
extern SCM scm_string_split (SCM str, SCM chr);
|
||||||
extern SCM scm_string_ci_to_symbol (SCM v);
|
extern SCM scm_string_ci_to_symbol (SCM v);
|
||||||
|
|
||||||
#define scm_substring_move_left_x scm_substring_move_x
|
#define scm_substring_move_left_x scm_substring_move_x
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue