/[guile]/guile/guile-core/srfi/srfi-13.c
ViewVC logotype

Diff of /guile/guile-core/srfi/srfi-13.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11.2.5 by ttn, Thu Mar 14 05:32:48 2002 UTC revision 1.11.2.6 by mvo, Fri Apr 26 19:16:38 2002 UTC
# Line 2798  SCM_DEFINE (scm_string_replace, "string- Line 2798  SCM_DEFINE (scm_string_replace, "string-
2798    
2799    
2800  SCM_DEFINE (scm_string_tokenize, "string-tokenize", 1, 3, 0,  SCM_DEFINE (scm_string_tokenize, "string-tokenize", 1, 3, 0,
2801              (SCM s, SCM token_char, SCM start, SCM end),              (SCM s, SCM token_set, SCM start, SCM end),
2802              "Split the string @var{s} into a list of substrings, where each\n"              "Split the string @var{s} into a list of substrings, where each\n"
2803              "substring is a maximal non-empty contiguous sequence of\n"              "substring is a maximal non-empty contiguous sequence of\n"
2804              "characters equal to the character @var{token_char}, or\n"              "characters from the character set @var{token_set}, which\n"
2805              "whitespace, if @var{token_char} is not given.  If\n"              "defaults to an equivalent of @code{char-set:graphic}.\n"
2806              "@var{token_char} is a character set, it is used for finding the\n"              "If @var{start} or @var{end} indices are provided, they restrict\n"
2807              "token borders.")              "@code{string-tokenize} to operating on the indicated substring\n"
2808                "of @var{s}.")
2809  #define FUNC_NAME s_scm_string_tokenize  #define FUNC_NAME s_scm_string_tokenize
2810  {  {
2811    char * cstr;    char * cstr;
# Line 2814  SCM_DEFINE (scm_string_tokenize, "string Line 2815  SCM_DEFINE (scm_string_tokenize, "string
2815    SCM_VALIDATE_SUBSTRING_SPEC_COPY (1, s, cstr,    SCM_VALIDATE_SUBSTRING_SPEC_COPY (1, s, cstr,
2816                                      3, start, cstart,                                      3, start, cstart,
2817                                      4, end, cend);                                      4, end, cend);
2818    if (SCM_UNBNDP (token_char))    if (SCM_UNBNDP (token_set))
2819      {      {
2820        int idx;        int idx;
2821    
# Line 2822  SCM_DEFINE (scm_string_tokenize, "string Line 2823  SCM_DEFINE (scm_string_tokenize, "string
2823          {          {
2824            while (cstart < cend)            while (cstart < cend)
2825              {              {
2826                if (!isspace (cstr[cend - 1]))                if (isgraph (cstr[cend - 1]))
2827                  break;                  break;
2828                cend--;                cend--;
2829              }              }
# Line 2831  SCM_DEFINE (scm_string_tokenize, "string Line 2832  SCM_DEFINE (scm_string_tokenize, "string
2832            idx = cend;            idx = cend;
2833            while (cstart < cend)            while (cstart < cend)
2834              {              {
2835                if (isspace (cstr[cend - 1]))                if (!isgraph (cstr[cend - 1]))
2836                  break;                  break;
2837                cend--;                cend--;
2838              }              }
2839            result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result);            result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result);
2840          }          }
2841      }      }
2842    else if (SCM_CHARSETP (token_char))    else if (SCM_CHARSETP (token_set))
2843      {      {
2844        int idx;        int idx;
2845    
# Line 2846  SCM_DEFINE (scm_string_tokenize, "string Line 2847  SCM_DEFINE (scm_string_tokenize, "string
2847          {          {
2848            while (cstart < cend)            while (cstart < cend)
2849              {              {
2850                if (!SCM_CHARSET_GET (token_char, cstr[cend - 1]))                if (SCM_CHARSET_GET (token_set, cstr[cend - 1]))
2851                  break;                  break;
2852                cend--;                cend--;
2853              }              }
# Line 2855  SCM_DEFINE (scm_string_tokenize, "string Line 2856  SCM_DEFINE (scm_string_tokenize, "string
2856            idx = cend;            idx = cend;
2857            while (cstart < cend)            while (cstart < cend)
2858              {              {
2859                if (SCM_CHARSET_GET (token_char, cstr[cend - 1]))                if (!SCM_CHARSET_GET (token_set, cstr[cend - 1]))
                 break;  
               cend--;  
             }  
           result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result);  
         }  
     }  
   else  
     {  
       int idx;  
       char chr;  
   
       SCM_VALIDATE_CHAR (2, token_char);  
       chr = SCM_CHAR (token_char);  
   
       while (cstart < cend)  
         {  
           while (cstart < cend)  
             {  
               if (cstr[cend - 1] != chr)  
                 break;  
               cend--;  
             }  
           if (cstart >= cend)  
             break;  
           idx = cend;  
           while (cstart < cend)  
             {  
               if (cstr[cend - 1] == chr)  
2860                  break;                  break;
2861                cend--;                cend--;
2862              }              }
2863            result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result);            result = scm_cons (scm_mem2string (cstr + cend, idx - cend), result);
2864          }          }
2865      }      }
2866      else SCM_WRONG_TYPE_ARG (2, token_set);
2867    return result;    return result;
2868  }  }
2869  #undef FUNC_NAME  #undef FUNC_NAME

Legend:
Removed from v.1.11.2.5  
changed lines
  Added in v.1.11.2.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26