Changeset 4865
- Timestamp:
- 06/20/05 06:39:30 (4 years ago)
- svk:copy_cache_prev:
- 6641
- Files:
-
- 3 modified
-
src/Pugs/Prim.hs (modified) (3 diffs)
-
src/Pugs/Prim/Match.hs (modified) (2 diffs)
-
t/builtins/strings/split.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim.hs
r4785 r4865 964 964 op3 "splice" = \x y z -> do 965 965 op4 "splice" x y z (VList []) 966 op3 "split" = op3Split 966 967 op3 "Any::new" = \t n _ -> do 967 968 typ <- fromVal t … … 982 983 return obj 983 984 op3 other = \_ _ _ -> fail ("Unimplemented 3-ary op: " ++ other) 985 986 op3Split :: Val -> Val -> Val -> Eval Val 987 op3Split x y z = do 988 val <- fromVal x 989 str <- fromVal y 990 limit <- fromVal z 991 case val of 992 VRule rx -> do 993 chunks <- rxSplit_n rx str limit 994 return $ VList chunks 995 _ -> do 996 delim <- fromVal val 997 return $ split' delim str 998 where 999 split' :: VStr -> VStr -> Val 1000 split' [] xs = VList $ map (VStr . (:[])) xs 1001 split' glue xs = VList $ map VStr $ split glue xs 984 1002 985 1003 -- |Implementation of 4-arity primitive operators and functions. … … 1435 1453 \\n List pre split safe (Str, Str)\ 1436 1454 \\n List pre split safe (Rule, Str)\ 1455 \\n List pre split safe (Rule, Str, Int)\ 1437 1456 \\n Str spre = safe (Any)\ 1438 1457 \\n List spre = safe (Any)\ -
src/Pugs/Prim/Match.hs
r4114 r4865 3 3 4 4 module Pugs.Prim.Match ( 5 op2Match, rxSplit, matchFromMR5 op2Match, rxSplit, rxSplit_n, matchFromMR 6 6 ) where 7 7 import Pugs.Internals … … 175 175 rest <- rxSplit rx after 176 176 return $ (VStr before:matchSubPos match) ++ rest 177 178 -- duplicated for now, pending über-Haskell-fu 179 180 rxSplit_n :: VRule -> String -> Int -> Eval [Val] 181 rxSplit_n _ [] n = return [] 182 rxSplit_n rx str n = do 183 match <- str `doMatch` rx 184 if or [ ( n == 1 ), ( not (matchOk match) ) ] then return [VStr str] else do 185 if matchFrom match == matchTo match 186 then do 187 let (c:cs) = str 188 rest <- rxSplit_n rx (cs) (n-1) 189 return (VStr [c]:rest) 190 else do 191 let before = genericTake (matchFrom match) str 192 after = genericDrop (matchTo match) str 193 rest <- rxSplit_n rx after (n-1) 194 return $ (VStr before:matchSubPos match) ++ rest -
t/builtins/strings/split.t
r4864 r4865 5 5 6 6 # XXX - this needs to be updated when Str.split(Str) works again 7 plan 54;7 plan 64; 8 8 9 9 # split on an empty string … … 80 80 try { 81 81 split_test split(rx:perl5{\s+}, "Hello World Goodbye Mars", 3), 82 [ qw/Hello World/, "Goodbye Mars" ],82 ( qw/Hello World/, "Goodbye Mars" ), 83 83 q(split rx:perl5{\s+}, Str, limit); 84 84 }; … … 89 89 try { 90 90 split_test split(" ", "Hello World Goodbye Mars", 3), 91 [ qw/Hello World/, " Goodbye Mars" ],91 ( qw/Hello World/, " Goodbye Mars" ), 92 92 q(split " ", Str, limit); 93 93 };
