summaryrefslogtreecommitdiff
path: root/ghc/runtime/regex/test.hs
blob: 962d32050c22ccaf09e40b6a0ab299c094803a17 (plain)
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
import LibMatchPS

_tailPS' x
 = if _nullPS x then
     error "_tailPS []"
   else
     _substrPS x 1 (_lengthPS x)

subst :: String
      -> String
      -> [Char]
      -> String
      -> String
subst rexp repl flags str 
 = _unpackPS (substPS (_packString rexp)
		      (_packString repl)
		      flags
		      (_packString str))
		

pickFirst :: String
	  -> String
	  -> String
pickFirst str substr
 = let
    str' = _packString str
   in
    case (findPS (_packString str) (_packString substr)) of
	Nothing -> ""
	Just x  -> _unpackPS (_dropPS x str')

pickLast :: String
	 -> String
	 -> String
pickLast str substr
 = let
    str' = _packString str
   in
    case (rfindPS (_packString str) (_packString substr)) of
	Nothing -> ""
	Just x  -> _unpackPS (_dropPS x str')

main 
 = getArgs  >>= \ (pattern:replacement:stuff:xs) ->
   let
    flags
     = case xs of
        [] -> []
	(x:xs) -> x
   in
    (case stuff of
      (':':xs) ->
	     openFile xs ReadMode  >>= \ hndl ->
	     hGetContents hndl
      _ -> return stuff) >>= \ stuff' ->
    putStr (subst pattern replacement flags stuff') >>
    putStr "\n"