[Contents]   [Back]   [Prev]   [Up]   [Next]   [Forward]  


strop.[ch]

Status: useful

Description: strop provides a number of useful string operations, though some bits aren't completely clear. This documentation applies to strop + http://home.thezone.net/~gharvey/guile/strop.diff

Internal C Function: static int scm_i_index (SCM *str, SCM chr, int direction, SCM sub_start, SCM sub_end, char *why)
This is a workhorse function that performs either an index or rindex function, depending on the value of direction. I'm not at all clear on the usage of the pos arguments, though the purpose seems to be correct reporting of which argument values are reporting errors. Why you would do that, rather than just use SCM_ARG[1234] explicitly is beyond me. Anyone holding any enlightenment?

Function: string-index str char [frm [to]]
C Function: SCM scm_string_index (SCM str, SCM chr, SCM frm, SCM to)
Returns the index of char in str, or #f if the char isn't in str. If frm is given and not #f, it is used as the starting index; if to is given and not #f, it is used as the ending index (exclusive).
(string-index "weiner" #\e)
=> 1

(string-index "weiner" #\e 2)
=> 4

(string-index "weiner" #\e 2 4)
=> #f

Function: string-rindex str char [frm [to]]
C Function: SCM scm_string_rindex (SCM str, SCM chr, SCM frm, SCM to)
The same as string-index, except it gives the rightmost occurance of char in the range [frm, to-1], which defaults to the entire string.
(string-rindex "weiner" #\e)
=> 4

(string-rindex "weiner" #\e 2 4)
=> #f

(string-rindex "weiner" #\e 2 5)
=> 4

Function: substring-move-left! str1 start1 end1 str2 start2
C Function: SCM scm_substring_move_left_x (SCM str1, SCM start1, SCM end1, SCM str2, SCM start2)
[Note: this is only valid if you've applied the strop patch].

Moves a substring of str1, from start1 to end1 (end1 is exclusive), into str2, starting at start2. Allows overlapping strings.

(define x (make-string 10 #\a))
(define y "bcd")
(substring-move-left! x 2 5 y 0)
y
=> "aaa"

x
=> "aaaaaaaaaa"

(define y "bcdefg")
(substring-move-left! x 2 5 y 0)
y
=> "aaaefg"

(define y "abcdefg")
(substring-move-left! y 2 5 y 3)
y
=> "abccccg"

Function: substring-move-right! str1 start1 end1 str2 start2
C Function: SCM scm_substring_move_right_x (SCM str1, SCM start1, SCM end1, SCM str2, SCM start2)
[Note: this is only valid if you've applied the strop patch, if it hasn't made it into the guile tree].

Does much the same thing as substring-move-left!, except it starts moving at the end of the sequence, rather than the beginning.

(define y "abcdefg")
(substring-move-right! y 2 5 y 0)
y
=> "ededefg"

(define y "abcdefg")
(substring-move-right! y 2 5 y 3)
y
=> "abccdeg"

Function: substring-fill! str start end fill
C Function: SCM scm_substring_fill_x (SCM str, SCM start, SCM end, SCM fill)
[Note: this is only valid if you've applied the strop patch, if it hasn't made it into the guile tree].

Destructively fills str, from start to end, with fill.

(define y "abcdefg")
(substring-fill! y 1 3 #\r)
y
=> "arrdefg"

Function: string-null? str
C Function: SCM scm_string_null_p (SCM str)
Returns #t if str is empty, else returns #f
(string-null? "")
=> #t

(string-null? y)
=> #f

Function: string-upcase! str
C Function: SCM scm_string_upcase_x (SCM str)
Converts each element in str to upper case.
(string-upcase! y)
=> "ARRDEFG"

y
=> "ARRDEFG"

Function: string-downcase! str
C Function: SCM scm_string_downcase_x (SCM str)
Converts each element in str to lower case.
y
=> "ARRDEFG"

(string-downcase! y)
=> "arrdefg"

y
=> "arrdefg"


[Contents]   [Back]   [Prev]   [Up]   [Next]   [Forward]