Permalink
Browse files

add .trim, .trim-leading, .trim-trailing

  • Loading branch information...
1 parent 6fa4f7d commit e743d95641939acd362b6260d7e26e067c8c12f2 @coke coke committed Jul 18, 2012
Showing with 15 additions and 2 deletions.
  1. +1 −1 Pugs/Pugs.cabal
  2. +13 −0 Pugs/src/Pugs/Prim.hs
  3. +1 −1 t/spectest.data
View
@@ -162,7 +162,7 @@ executable pugs
build-depends:
base >= 4 && < 5, filepath, mtl >= 2.0.0.0, parsec >= 3.0.0.0, network,
- pretty, time, random, process, containers, bytestring,
+ pretty, time, random, process, containers, bytestring, text,
array, directory, utf8-string, binary, haskeline >= 0.6.4.7, FindBin,
control-timeout >= 0.1.2,
View
@@ -57,6 +57,7 @@ import qualified Data.HashTable as H
import Data.Time.LocalTime
import Data.Time.Calendar.OrdinalDate
import Data.Time.Calendar.MonthDay
+import Data.Text (strip, stripStart, stripEnd, pack, unpack)
constMacro :: Exp -> [Val] -> Eval Val
constMacro = const . expToEvalVal
@@ -213,6 +214,15 @@ op1 "sort" = \v -> do
op1 "Scalar::flip" = \v -> do
str <- fromVal v
return (VStr $ reverse str)
+op1 "Scalar::trim" = \v -> do
+ str <- fromVal v
+ return (VStr $ unpack $ strip $ pack str)
+op1 "Scalar::trim-leading" = \v -> do
+ str <- fromVal v
+ return (VStr $ unpack $ stripStart $ pack str)
+op1 "Scalar::trim-trailing" = \v -> do
+ str <- fromVal v
+ return (VStr $ unpack $ stripEnd $ pack str)
op1 "List::reverse" = \v -> do
vlist <- fromVal v
return (VList $ reverse vlist)
@@ -1947,6 +1957,9 @@ initSyms = seq (length syms) $ do
\\n List pre pair safe (List)\
\\n Scalar pre item safe (Scalar)\
\\n Str pre Scalar::flip safe (Scalar)\
+\\n Str pre Scalar::trim safe (Scalar)\
+\\n Str pre Scalar::trim-leading safe (Scalar)\
+\\n Str pre Scalar::trim-trailing safe (Scalar)\
\\n Any pre List::reverse safe (Array)\
\\n Any pre reverse safe (Scalar, List)\
\\n Any pre reverse safe ()\
View
@@ -379,7 +379,7 @@ S32-str/pos.t
S32-str/quotemeta.t
S32-str/rindex.t
S32-str/substr.t
-# S32-str/trim.t # trim NYI
+S32-str/trim.t
S32-str/ucfirst.t
S32-str/uc.t
# S32-temporal/calendar.t # NYI

1 comment on commit e743d95

+1

It would be nice to have VStr actually use Text (now we start to dep on Data.Text) so we don't have to pack+unpack -- although this is a good start.

Please sign in to comment.