on master help sign in
Move Data/String to Internal/Data/Unicode/Stream

rename Data.String to Data.Unicode.Stream

commitab6587ba5942572cb32cc3a91fc17a7de0153b1b authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 3 Nov 2019, 16:22 (7 years ago) parent0b30c6a
9 files changed+99−48
examples/FileSinkServer.hs+1−1 examples/WordClassifier.hs+1−1 examples/WordCount.hs+1−1 src/Streamly/Benchmark/FileIO/Array.hs+1−1 src/Streamly/Benchmark/FileIO/Stream.hs+1−1 src/Streamly/Data/Unicode/Stream.hs+88 src/Streamly/Data/String.hs → src/Streamly/Internal/Data/Unicode/Stream.hs+3−41 streamly.cabal+2−1 test/String.hs+1−1
examples/FileSinkServer.hs+1−1
@@ -10,7 +10,7 @@ import Network.Socket (close)
1010import System.Environment (getArgs)
1111
1212import Streamly
13−import Streamly.Data.String
13+import Streamly.Data.Unicode.Stream
1414import qualified Streamly.FileSystem.Handle as FH
1515import qualified Streamly.Memory.Array as A
1616import qualified Streamly.Network.Socket as NS
examples/WordClassifier.hs+1−1
@@ -16,7 +16,7 @@ import Data.IORef
1616import qualified Data.List as List
1717import qualified Data.Ord as Ord
1818import Foreign.Storable (Storable(..))
19−import qualified Streamly.Data.String as Streamly
19+import qualified Streamly.Data.Unicode.Stream as Streamly
2020import qualified Streamly.FileSystem.Handle as FH
2121import qualified Streamly.Data.Fold as FL
2222import qualified Streamly.Internal.Data.Fold as IFL
examples/WordCount.hs+1−1
@@ -38,7 +38,7 @@ import System.Environment (getArgs)
3838import System.IO (Handle, openFile, IOMode(..))
3939
4040import qualified Streamly as S
41−import qualified Streamly.Data.String as S
41+import qualified Streamly.Data.Unicode.Stream as S
4242import qualified Streamly.FileSystem.Handle as FH
4343import qualified Streamly.Memory.Array as A
4444import qualified Streamly.Prelude as S
src/Streamly/Benchmark/FileIO/Array.hs+1−1
@@ -45,7 +45,7 @@ import Prelude hiding (last)
4545import qualified Streamly.FileSystem.Handle as FH
4646import qualified Streamly.Memory.Array as A
4747import qualified Streamly.Prelude as S
48−import qualified Streamly.Data.String as SS
48+import qualified Streamly.Data.Unicode.Stream as SS
4949
5050import qualified Streamly.Internal.FileSystem.Handle as IFH
5151import qualified Streamly.Internal.Memory.Array as IA
src/Streamly/Benchmark/FileIO/Stream.hs+1−1
@@ -77,7 +77,7 @@ import qualified Streamly.Internal.Memory.Array.Types as AT
7777import qualified Streamly.Prelude as S
7878import qualified Streamly.Data.Fold as FL
7979-- import qualified Streamly.Internal.Data.Fold as IFL
80−import qualified Streamly.Data.String as SS
80+import qualified Streamly.Data.Unicode.Stream as SS
8181import qualified Streamly.Internal.Data.Unfold as IUF
8282import qualified Streamly.Internal.Prelude as IP
8383import qualified Streamly.Streams.StreamD as D
src/Streamly/Data/Unicode/Stream.hsnew file+88
@@ -0,0 +1,88 @@
1+{-# LANGUAGE FlexibleContexts #-}
2+-- |
3+-- Module : Streamly.Data.Unicode.Stream
4+-- Copyright : (c) 2018 Composewell Technologies
5+--
6+-- License : BSD3
7+-- Maintainer : streamly@composewell.com
8+-- Stability : experimental
9+-- Portability : GHC
10+--
11+-- A unicode string can be represented either as a stream of 'Char' e.g.
12+-- 'SerialT' 'Identity' 'Char' or as 'Array' 'Char'. Unicode text processing
13+-- can be done efficiently by applying stream operations and folds on the
14+-- stream of 'Char'. When using 'Array' 'Char' direct array operations can be
15+-- applied where available or the array can be read into a stream and then
16+-- processed using stream operations. Use 'Array' 'Char' when you need to store
17+-- or buffer strings temporarily in memory. Streams in 'Identity' monad and
18+-- 'Array' 'Char' are instances of 'IsString' and 'IsList', therefore,
19+-- 'OverloadedStrings' and 'OverloadedLists' extensions can be used for
20+-- convenience.
21+--
22+-- 'Array' 'Char' is usually perfectly fine to buffer short to medium or even
23+-- large amounts of text in memory. Also, it is computationally efficient as
24+-- there is no encoding/decoding involved. We recommend using true streaming
25+-- operations to avoid buffering large amounts of data as long as possible e.g.
26+-- use `foldLines` instead of `lines`. However, if for some reason you are
27+-- buffering very large amounts of text in memory and are worried about space
28+-- efficiency you can use 'encodeUtf8' on the stream to convert it to a utf8
29+-- encoded 'Array' 'Word8'.
30+--
31+-- Please note the following:
32+--
33+-- * Case conversion: Some unicode characters translate to more than one code
34+-- point on case conversion. The 'toUpper' and 'toLower' functions in @base@
35+-- package do not handle such characters. Therefore, operations like @map
36+-- toUpper@ on a character stream or character array may not always perform
37+-- correct conversion.
38+-- * String comparison: In some cases, visually identical strings may have
39+-- different unicode representations, therefore, a character stream or
40+-- character array cannot be directly compared. A normalized comparison may be
41+-- needed to check string equivalence correctly.
42+
43+module Streamly.Data.Unicode.Stream
44+ (
45+ -- * Construction (Decoding)
46+ decodeChar8
47+ , decodeUtf8
48+ , decodeUtf8Lenient
49+ , D.DecodeError(..)
50+ , D.DecodeState
51+ , D.CodePoint
52+ , decodeUtf8Either
53+ , resumeDecodeUtf8Either
54+ , decodeUtf8Arrays
55+ , decodeUtf8ArraysLenient
56+
57+ -- * Elimination (Encoding)
58+ , encodeChar8
59+ , encodeChar8Unchecked
60+ , encodeUtf8
61+{-
62+ -- * Unicode aware operations
63+ , toCaseFold
64+ , toLower
65+ , toUpper
66+ , toTitle
67+
68+ -- * Operations on character strings
69+ , strip -- (dropAround isSpace)
70+ , stripEnd-}
71+ -- * Transformation
72+ , stripStart
73+ , foldLines
74+ , foldWords
75+ , unfoldLines
76+ , unfoldWords
77+
78+ -- * Streams of Strings
79+ , lines
80+ , words
81+ , unlines
82+ , unwords
83+ )
84+where
85+
86+import Streamly.Internal.Data.Unicode.Stream
87+import Prelude hiding (lines, words, unlines, unwords)
88+import qualified Streamly.Streams.StreamD as D
src/Streamly/Data/String.hs → src/Streamly/Internal/Data/Unicode/Stream.hsrenamed+3−41
@@ -1,52 +1,14 @@
11{-# LANGUAGE FlexibleContexts #-}
22-- |
3−-- Module : Streamly.Data.String
3+-- Module : Streamly.Data.Internal.Unicode.Stream
44-- Copyright : (c) 2018 Composewell Technologies
55--
66-- License : BSD3
7−-- Maintainer : harendra.kumar@gmail.com
7+-- Maintainer : streamly@composewell.com
88-- Stability : experimental
99-- Portability : GHC
1010--
11−-- A unicode string can be represented either as a stream of 'Char' e.g.
12−-- 'SerialT' 'Identity' 'Char' or as 'Array' 'Char'. Unicode text processing
13−-- can be done efficiently by applying stream operations and folds on the
14−-- stream of 'Char'. When using 'Array' 'Char' direct array operations can be
15−-- applied where available or the array can be read into a stream and then
16−-- processed using stream operations. Use 'Array' 'Char' when you need to store
17−-- or buffer strings temporarily in memory. Streams in 'Identity' monad and
18−-- 'Array' 'Char' are instances of 'IsString' and 'IsList', therefore,
19−-- 'OverloadedStrings' and 'OverloadedLists' extensions can be used for
20−-- convenience.
21−--
22−-- 'Array' 'Char' is usually perfectly fine to buffer short to medium or even
23−-- large amounts of text in memory. Also, it is computationally efficient as
24−-- there is no encoding/decoding involved. We recommend using true streaming
25−-- operations to avoid buffering large amounts of data as long as possible e.g.
26−-- use `foldLines` instead of `lines`. However, if for some reason you are
27−-- buffering very large amounts of text in memory and are worried about space
28−-- efficiency you can use 'encodeUtf8' on the stream to convert it to a utf8
29−-- encoded 'Array' 'Word8'.
30−--
31−-- Please note the following:
32−--
33−-- * Case conversion: Some unicode characters translate to more than one code
34−-- point on case conversion. The 'toUpper' and 'toLower' functions in @base@
35−-- package do not handle such characters. Therefore, operations like @map
36−-- toUpper@ on a character stream or character array may not always perform
37−-- correct conversion.
38−-- * String comparison: In some cases, visually identical strings may have
39−-- different unicode representations, therefore, a character stream or
40−-- character array cannot be directly compared. A normalized comparison may be
41−-- needed to check string equivalence correctly.
42−
43−-- See "Streamly.Internal.Data.List", <src/docs/streamly-vs-lists.md> for more details and
44−-- <src/test/PureStreams.hs> for comprehensive usage examples.
45−
46−-- TBD write a note on performance comparison with text, bytestrings, lists and
47−-- vector.
48−--
49−module Streamly.Data.String
11+module Streamly.Internal.Data.Unicode.Stream
5012 (
5113 -- * Construction (Decoding)
5214 decodeChar8
streamly.cabal+2−1
@@ -283,7 +283,7 @@ library
283283 exposed-modules: Streamly.Prelude
284284 , Streamly
285285 , Streamly.Data.Fold
286− , Streamly.Data.String
286+ , Streamly.Data.Unicode.Stream
287287
288288 -- IO devices
289289 , Streamly.Memory.Array
@@ -312,6 +312,7 @@ library
312312 , Streamly.Internal.Data.List
313313 , Streamly.Internal.FileSystem.Handle
314314 , Streamly.Internal.FileSystem.File
315+ , Streamly.Internal.Data.Unicode.Stream
315316 , Streamly.Internal.Prelude
316317 if !impl(ghcjs)
317318 exposed-modules:
test/String.hs+1−1
@@ -15,7 +15,7 @@ import Test.Hspec as H
1515import qualified Streamly.Memory.Array as A
1616import qualified Streamly.Internal.Memory.ArrayStream as AS
1717import qualified Streamly.Prelude as S
18−import qualified Streamly.Data.String as SS
18+import qualified Streamly.Data.Unicode.Stream as SS
1919
2020-- Coverage build takes too long with default number of tests
2121{-