fay-text 0.3.1 → 0.3.2
raw patch · 4 files changed
+46/−206 lines, 4 filesdep ~faydep ~fay-basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: fay, fay-base
API changes (from Hackage documentation)
- Fay.Text.Type: type Text = Text
+ Fay.Text: data Text :: *
+ Fay.Text: drop :: Int -> Text -> Text
+ Fay.Text: fromString :: String -> Text
+ Fay.Text: isPrefixOf :: Text -> Text -> Bool
+ Fay.Text: lines :: Text -> [Text]
+ Fay.Text: pack :: String -> Text
+ Fay.Text: splitOn :: Text -> Text -> [Text]
+ Fay.Text: stripSuffix :: Text -> Text -> Maybe Text
+ Fay.Text: take :: Int -> Text -> Text
+ Fay.Text: unlines :: [Text] -> Text
+ Fay.Text: unpack :: Text -> String
+ Fay.Text.Type: data Text :: *
Files
- CHANGELOG.md +4/−0
- fay-text.cabal +3/−3
- src/Fay/Text.hs +36/−179
- src/Fay/Text/Type.hs +3/−24
CHANGELOG.md view
@@ -1,5 +1,9 @@ ## Changelog +### 0.3.2 (2014-10-21)++* fay-text is now purely a compatibility layer between Fay and GHC. For Fay we reexport `Data.Text` from fay-base.+ ### 0.3.1 (2014-10-11) * Allow `fay 0.21`
fay-text.cabal view
@@ -1,5 +1,5 @@ name: fay-text-version: 0.3.1+version: 0.3.2 synopsis: Fay Text type represented as JavaScript strings description: Text type represented as JavaScript strings for Fay and Data.Text for GHC. Use with OverloadedStrings and RebindableSyntax to have Fay treat string literals as Text. homepage: https://github.com/faylang/fay-text@@ -27,5 +27,5 @@ exposed-modules: Fay.Text, Fay.Text.Type ghc-options: -Wall build-depends: text < 1.3- , fay >= 0.19 && < 0.22- , fay-base == 0.19.*+ , fay >= 0.21.2 && < 0.22+ , fay-base >= 0.19.4 && < 0.20
src/Fay/Text.hs view
@@ -1,5 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE PackageImports #-}+{-# LANGUAGE NoImplicitPrelude #-} -- | Module to be shared between server and client. --@@ -9,201 +11,56 @@ -- module Fay.Text- ( module Fay.Text.Type+ -- Only export what's defined in fay-base's Data.Text for both Fay and GHC+ ( Text+ -- * Creation and elimination+ , pack+ , unpack+ , fromString , empty+ -- * Breaking into many substrings+ , splitOn+ , stripSuffix+ -- * Basic interface , cons , snoc , append , uncons , head+ , init , last , tail- , init , null , length+ -- * Special folds+ , maximum+ , all+ , any+ , concatMap+ , concat+ , minimum+ -- * Case conversion+ , toLower+ , toUpper+ -- * Transformations , map , intercalate , intersperse , reverse- , toLower- , toUpper- , concat- , concatMap- , any- , all- , maximum- , minimum+ -- * Predicates+ , isPrefixOf+ -- * Substrings+ , drop+ , take+ -- * Breaking into lines and words+ , unlines+ , lines ) where -import Fay.Text.Type-import Prelude (Bool, Char, Int, Maybe)- #ifdef FAY-import Data.Data-import FFI--empty :: Text-empty = ffi "''"--cons :: Char -> Text -> Text-cons = ffi "%1 + %2"--snoc :: Text -> Char -> Text-snoc = ffi "%1 + %2"--append :: Text -> Text -> Text-append = ffi "%1 + %2"--uncons :: Text -> Maybe (Char, Text)-uncons = ffi "%1[0] ? { instance: 'Just', slot1 : [%1[0],%1.slice(1)] } : { instance : 'Nothing' }"--head :: Text -> Char-head = ffi "%1[0] || (function () {throw new Error('Fay.Text.head: empty Text'); }())"--last :: Text -> Char-last = ffi "%1.length ? %1[%1.length-1] : (function() { throw new Error('Fay.Text.last: empty Text') })()"--tail :: Text -> Text-tail = ffi "%1.length ? %1.slice(1) : (function () { throw new Error('Fay.Text.tail: empty Text') })()"--init :: Text -> Text-init = ffi "%1.length ? %1.slice(0,-1) : (function () { throw new Error('Fay.Text.init: empty Text') })()"--null :: Text -> Bool-null = ffi "!(%1.length)"--length :: Text -> Int-length = ffi "%1.length"--map :: (Char -> Char) -> Text -> Text-map = ffi "[].map.call(%2, %1).join('')"--intercalate :: Text -> [Text] -> Text-intercalate = ffi "%2.join(%1)"--intersperse :: Char -> Text -> Text-intersperse = ffi "%2.split('').join(%1)"---- TODO transpose--reverse :: Text -> Text-reverse = ffi "%1.split('').reverse().join('')"----- TODO replace: Can't use String:replace.---- TODO toCaseFold--toLower :: Text -> Text-toLower = ffi "%1.toLowerCase()"--toUpper :: Text -> Text-toUpper = ffi "%1.toUpperCase()"---- TODO justifyLeft, justifyRight, center---- TODO foldl, foldl' foldl1', foldr, foldr1--concat :: [Text] -> Text-concat = ffi "%1.join('')"--concatMap :: (Char -> Text) -> Text -> Text-concatMap = ffi "[].map.call(%2, %1).join('')"--any :: (Char -> Bool) -> Text -> Bool-any = ffi "[].filter.call(%2, %1).length > 0"--all :: (Char -> Bool) -> Text -> Bool-all = ffi "[].filter.call(%2, %1).length == %1.length"--maximum :: Text -> Char-maximum = ffi "(function (s) { \- \ if (s === '') { throw new Error('Fay.Text.maximum: empty string'); } \- \ var max = s[0]; \- \ for (var i = 1; i < s.length; s++) { \- \ if (s[i] > max) { max = s[i]; } \- \ } \- \ return max; \- \ })(%1)"--minimum :: Text -> Char-minimum = ffi "(function (s) { \- \ if (s === '') { throw new Error('Fay.Text.maximum: empty string'); } \- \ var min = s[0]; \- \ for (var i = 1; i < s.length; s++) { \- \ if (s[i] < min) { min = s[i]; } \- \ } \- \ return min; \- \ })(%1)"---- TODO scanl, scanl1, scanr, scanr1--- TODO mapAccumL, mapAccumR---- TODO replicate, unfoldr, unforldrN, take, drop, takeWhile, dropWhile, dropWhileEnd, dropAround, strip, stripStart, stripEnd, splitAt, breakOn, breakOnEnd, break, span, group, groupBy, inits, tails---- TODO splitOn, split, chunksOf---- TODO lines, words, unlines, unwords---- TODO isPrefixOf, isSuffixOf, isInfixOf---- TODO stripPrefix, stripSuffix, commonPrefixes---- TODO filter, breakOnAll, find, partition---- TODO index, findIndex, count---- TODO zip, zipWith-+import "fay-base" Data.Text #else--import qualified Data.Text as T--empty :: Text-empty = T.empty-cons :: Char -> Text -> Text-cons = T.cons-snoc :: Text -> Char -> Text-snoc = T.snoc-append :: Text -> Text -> Text-append = T.append-uncons :: Text -> Maybe (Char, Text)-uncons = T.uncons-head :: Text -> Char-head = T.head-last :: Text -> Char-last = T.last-tail :: Text -> Text-tail = T.tail-init :: Text -> Text-init = T.init-null :: Text -> Bool-null = T.null-length :: Text -> Int-length = T.length-map :: (Char -> Char) -> Text -> Text-map = T.map-intercalate :: Text -> [Text] -> Text-intercalate = T.intercalate-intersperse :: Char -> Text -> Text-intersperse = T.intersperse-reverse :: Text -> Text-reverse = T.reverse-toLower :: Text -> Text-toLower = T.toLower-toUpper :: Text -> Text-toUpper = T.toUpper-concat :: [Text] -> Text-concat = T.concat-concatMap :: (Char -> Text) -> Text -> Text-concatMap = T.concatMap-any :: (Char -> Bool) -> Text -> Bool-any = T.any-all :: (Char -> Bool) -> Text -> Bool-all = T.all-maximum :: Text -> Char-maximum = T.maximum-minimum :: Text -> Char-minimum = T.minimum-+import "text" Data.Text #endif++import Fay.Text.Type (fromString)
src/Fay/Text/Type.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE PackageImports #-} -- | Module to be shared between server and client. --@@ -18,31 +19,9 @@ import Prelude #ifdef FAY--import Data.Data-import FFI--data Text- deriving (Data, Eq, Ord, Read, Show, Typeable)--pack :: String -> Text-pack = ffi "%1"--unpack :: Text -> String-unpack = ffi "%1"-+import "fay-base" Data.Text (Text, pack, unpack) #else--import qualified Data.Text as T--type Text = T.Text--pack :: String -> Text-pack = T.pack--unpack :: Text -> String-unpack = T.unpack-+import "text" Data.Text (Text, pack, unpack) #endif -- | Have this in scope with the OverloadedStrings and BindableSyntax extensions