Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
add .trim, .trim-leading, .trim-trailing
  • Loading branch information
coke committed Jul 18, 2012
1 parent 6fa4f7d commit e743d95
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Pugs/Pugs.cabal
Expand Up @@ -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,

Expand Down
13 changes: 13 additions & 0 deletions Pugs/src/Pugs/Prim.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ()\
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -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
Expand Down

1 comment on commit e743d95

@audreyt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+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.