File: match-split.sgm

package info (click to toggle)
docbook-dsssl-doc 1.75-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,672 kB
  • ctags: 8
  • sloc: makefile: 37
file content (91 lines) | stat: -rw-r--r-- 2,281 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<RefEntry id="match-split">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename match-split.html>

<RefMeta>
  <RefEntryTitle>match-split</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>match-split</RefName>
  <RefPurpose>Splits string at target and returns the resulting list of tokens</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(match-split string target)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Splits string at every occurance of target and returns the result
as a list.  Note that <literal>match-split</literal> returns the occurances of <literal>target</literal>
in the list of tokens.
</para>
<variablelist>
<varlistentry><term><literal>string</literal></term>
<listitem>
<para>
The string to split.
</para>
</listitem>
</varlistentry>
<varlistentry><term><literal>target</literal></term>
<listitem>
<para>
The string which is a delimiter between tokens
</para>
</listitem>
</varlistentry>
</variablelist>

</RefSect1>

<RefSect1><Title>Example</Title>

<para>
<literal>"this is a test"</literal> split at <literal>"is"</literal> returns
<literal>("th" "is" " " "is" " a test")</literal>
</para>


</RefSect1>

<RefSect1><Title>Author</Title>

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

<ProgramListing>
(define (match-split string target)
  ;; Splits string at target and returns the resulting list of tokens
  (if (string? string)
      (let loop ((result '()) (current "") (rest string))
	(if (< (string-length rest) (string-length target))
	    (append result (if (equal? (string-append current rest) "")
			       '()
			       (list (string-append current rest))))
	    (if (equal? target (substring rest 0 (string-length target)))
		(loop (append result 
			      (if (equal? current "")
				  '()
				  (list current))
			      (list target))
		      ""
		      (substring rest (string-length target) 
				 (string-length rest)))
		(loop result
		      (string-append current (substring rest 0 1))
		      (substring rest 1 (string-length rest))))))
      (list string)))
</ProgramListing>
</RefSect1>

</RefEntry>