X11 sample rewritten; now it works again
[k8lst.git] / modules / regexpr.st
blob2a7e21bb4e52a5c7d9dd5b10cef647bb6b27be09
2  coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
3  Understanding is not required. Only obedience.
5  This program is free software. It comes without any warranty, to
6  the extent permitted by applicable law. You can redistribute it
7  and/or modify it under the terms of the Do What The Fuck You Want
8  To Public License, Version 2, as published by Sam Hocevar. See
9  http://sam.zoy.org/wtfpl/COPYING for more details.
11 Package [ RegExp ]
13 class: RegExpr [
14 | rh mstr |
16 ^newREHandle: aStr type: aType [
17   <#RegExpDo 0 aType aStr>.
18   self primitiveFailed
21 ^new [
22   self error: 'use newHS: or newTX: to create RegExpr'
25 ^newWithRH: rh [
26   | obj |
27   (rh class == String) ifTrue: [ ^rh ].
28   obj := self basicNew.
29   self in: obj var: #rh put: rh.
30   ^obj
33 ^newHS: aStr [
34   ^self newWithRH: (self newREHandle: aStr type: 0)
37 ^newTX: aStr [
38   ^self newWithRH: (self newREHandle: aStr type: 1)
41 matchStr [
42   ^mstr
45 match: aStr [
46   mstr := aStr.
47   <#RegExpDo 1 rh aStr>.
48   self primitiveFailed
51 subCount [
52   <#RegExpDo 2 rh>.
53   self primitiveFailed
56 subStart: aIdx [
57   <#RegExpDo 3 rh aIdx>.
58   self primitiveFailed
61 subEnd: aIdx [
62   <#RegExpDo 4 rh aIdx>.
63   self primitiveFailed
66 captureAt: aIdx [
67   | s e |
68   (s := self subStart: aIdx) < 0 ifTrue: [ ^nil ].
69   (e := self subEnd: aIdx) < 0 ifTrue: [ ^nil ].
70   's=' print. s print. '; e=' print. e printNl.
71   ^mstr from: s+1 to: e.