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

Commit e743d95

Browse files
committed
add .trim, .trim-leading, .trim-trailing
1 parent 6fa4f7d commit e743d95

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Pugs/Pugs.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ executable pugs
162162

163163
build-depends:
164164
base >= 4 && < 5, filepath, mtl >= 2.0.0.0, parsec >= 3.0.0.0, network,
165-
pretty, time, random, process, containers, bytestring,
165+
pretty, time, random, process, containers, bytestring, text,
166166
array, directory, utf8-string, binary, haskeline >= 0.6.4.7, FindBin,
167167
control-timeout >= 0.1.2,
168168

Pugs/src/Pugs/Prim.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import qualified Data.HashTable as H
5757
import Data.Time.LocalTime
5858
import Data.Time.Calendar.OrdinalDate
5959
import Data.Time.Calendar.MonthDay
60+
import Data.Text (strip, stripStart, stripEnd, pack, unpack)
6061

6162
constMacro :: Exp -> [Val] -> Eval Val
6263
constMacro = const . expToEvalVal
@@ -213,6 +214,15 @@ op1 "sort" = \v -> do
213214
op1 "Scalar::flip" = \v -> do
214215
str <- fromVal v
215216
return (VStr $ reverse str)
217+
op1 "Scalar::trim" = \v -> do
218+
str <- fromVal v
219+
return (VStr $ unpack $ strip $ pack str)
220+
op1 "Scalar::trim-leading" = \v -> do
221+
str <- fromVal v
222+
return (VStr $ unpack $ stripStart $ pack str)
223+
op1 "Scalar::trim-trailing" = \v -> do
224+
str <- fromVal v
225+
return (VStr $ unpack $ stripEnd $ pack str)
216226
op1 "List::reverse" = \v -> do
217227
vlist <- fromVal v
218228
return (VList $ reverse vlist)
@@ -1947,6 +1957,9 @@ initSyms = seq (length syms) $ do
19471957
\\n List pre pair safe (List)\
19481958
\\n Scalar pre item safe (Scalar)\
19491959
\\n Str pre Scalar::flip safe (Scalar)\
1960+
\\n Str pre Scalar::trim safe (Scalar)\
1961+
\\n Str pre Scalar::trim-leading safe (Scalar)\
1962+
\\n Str pre Scalar::trim-trailing safe (Scalar)\
19501963
\\n Any pre List::reverse safe (Array)\
19511964
\\n Any pre reverse safe (Scalar, List)\
19521965
\\n Any pre reverse safe ()\

t/spectest.data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ S32-str/pos.t
379379
S32-str/quotemeta.t
380380
S32-str/rindex.t
381381
S32-str/substr.t
382-
# S32-str/trim.t # trim NYI
382+
S32-str/trim.t
383383
S32-str/ucfirst.t
384384
S32-str/uc.t
385385
# S32-temporal/calendar.t # NYI

0 commit comments

Comments
 (0)