Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 6b3585ea67ce3e79c9049b5b33294cdd > files > 641

docbook-style-dsssl-doc-1.79-16.mga7.noarch.rpm

<RefEntry id="find-first-char">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename find-first-char.html>

<RefMeta>
  <RefEntryTitle>find-first-char</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>find-first-char</RefName>
  <RefPurpose>Find the first occurance of a character in a string</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(find-first-char string skipchars findchars #!optional (pos 0))
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Finds first character in <literal>string</literal> that is in <literal>findchars</literal>, skipping all
occurances of characters in <literal>skipchars</literal>.  Search begins at <literal>pos</literal>.  If
no such characters are found, returns -1.
</para>
<para>
If skipchars is empty, skip anything not in findchars
If skipchars is #f, skip nothing
If findchars is empty, the first character not in skipchars is matched
It is an error if findchars is not a string.
It is an error if findchars is empty and skipchars is not a non-empty
string.</para>


</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(define (find-first-char string skipchars findchars #!optional (pos 0))
  ;; Find the first occurance of a character in a string
  (let ((skiplist (if (string? skipchars)
		      (string->list skipchars)
		      '()))
	(findlist (string->list findchars)))
    (if (and (null? skiplist) (null? findlist))
	;; this is an error
	-2
	(if (or (>= pos (string-length string)) (< pos 0))
	    -1
	    (let ((ch (string-ref string pos)))
	      (if (null? skiplist) 
		  ;; try to find first
		  (if (member ch findlist)
		      pos
		      (if (string? skipchars)
			  (find-first-char string 
					   skipchars findchars (+ 1 pos))
			  -1))
		  ;; try to skip first
		  (if (member ch skiplist)
		      (find-first-char string skipchars findchars (+ 1 pos))
		      (if (or (member ch findlist) (null? findlist))
			  pos
			  -1))))))))
</ProgramListing>
</RefSect1>

</RefEntry>