Skip to content

Commit 7e97adf

Browse files
authored
Merge pull request #76 from Bodigrim/text-2.0
Support text-2.0
2 parents 3377104 + 6418a41 commit 7e97adf

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

Data/Unicode/Internal/NormalizeStream.hs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# OPTIONS_GHC -funbox-strict-fields #-}
22
{-# LANGUAGE BangPatterns #-}
3+
{-# LANGUAGE CPP #-}
34
{-# LANGUAGE LambdaCase #-}
45
{-# LANGUAGE TupleSections #-}
56
-- |
@@ -22,21 +23,28 @@ module Data.Unicode.Internal.NormalizeStream
2223
)
2324
where
2425

25-
import Data.Bits (shiftR)
2626
import Data.Char (chr, ord)
2727
import GHC.ST (ST(..))
2828
import GHC.Types (SPEC(..))
2929

3030
import qualified Data.Text.Array as A
3131
import qualified Unicode.Char as UC
3232

33+
#if MIN_VERSION_text(2,0,0)
34+
import Data.Text.Internal.Fusion (stream)
35+
#else
36+
import Data.Bits (shiftR)
37+
import Data.Text.Internal.Unsafe.Char (unsafeChr)
38+
import Data.Text.Internal.Fusion.Size (betweenSize)
39+
import Data.Text.Internal.Encoding.Utf16 (chr2)
40+
#endif
41+
3342
-- Internal modules
3443
import Data.Text.Internal (Text(..))
35-
import Data.Text.Internal.Fusion.Size (betweenSize, upperBound)
44+
import Data.Text.Internal.Fusion.Size (upperBound)
3645
import Data.Text.Internal.Fusion.Types (Step(..), Stream(..))
3746
import Data.Text.Internal.Private (runText)
38-
import Data.Text.Internal.Unsafe.Char (unsafeChr, unsafeWrite)
39-
import Data.Text.Internal.Encoding.Utf16 (chr2)
47+
import Data.Text.Internal.Unsafe.Char (unsafeWrite)
4048

4149
-------------------------------------------------------------------------------
4250
-- Reorder buffer to hold characters till the next starter boundary
@@ -142,6 +150,7 @@ decomposeChar mode marr index reBuf ch
142150
n <- unsafeWrite arr j c
143151
return (j + n, Empty)
144152

153+
#if !MIN_VERSION_text(2,0,0)
145154
-- | /O(n)/ Convert a 'Text' into a 'Stream Char'.
146155
stream :: Text -> Stream Char
147156
stream (Text arr off len) = Stream next off (betweenSize (len `shiftR` 1) len)
@@ -158,6 +167,7 @@ stream (Text arr off len) = Stream next off (betweenSize (len `shiftR` 1) len)
158167
n = A.unsafeIndex arr i
159168
n2 = A.unsafeIndex arr (i + 1)
160169
{-# INLINE [0] stream #-}
170+
#endif
161171

162172
-- | /O(n)/ Convert a 'Stream Char' into a decompose-normalized 'Text'.
163173
unstream :: UC.DecomposeMode -> Stream Char -> Text

unicode-transforms.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ library
8989

9090
-- We depend on a lot of internal modules in text. We keep the upper bound
9191
-- inclusive of the latest stable version.
92-
, text >= 1.1.1 && <= 1.2.4.1
92+
, text >=1.1.1 && <=1.2.5.0 || >=2.0 && <2.1
9393
if flag(dev)
9494
ghc-options: -O0
9595
else
@@ -110,7 +110,7 @@ test-suite extras
110110
QuickCheck >=2.1 && <2.15
111111
, base >=4.7 && <5
112112
, deepseq >=1.1 && <1.5
113-
, text >=1.1.1 && <1.3
113+
, text
114114
, unicode-transforms
115115
if flag(dev)
116116
ghc-options: -O0
@@ -134,7 +134,7 @@ test-suite quickcheck
134134
, base >=4.7 && <5
135135
, deepseq >=1.1 && <1.5
136136
, hspec >= 2.0 && < 3
137-
, text >=1.1.1 && <1.3
137+
, text
138138
, unicode-transforms
139139
if flag(dev)
140140
ghc-options: -O0
@@ -158,7 +158,7 @@ test-suite ucd
158158
base >=4.7 && <5
159159
, getopt-generics >=0.11 && <0.14
160160
, split >=0.1 && <0.3
161-
, text >=1.1.1 && <1.3
161+
, text
162162
, unicode-transforms
163163
if flag(dev)
164164
ghc-options: -O0
@@ -180,7 +180,7 @@ benchmark bench
180180
, filepath >=1.0 && <2
181181
, path >=0.0.0 && <0.9
182182
, path-io >=0.1.0 && <1.7
183-
, text >=1.1.1 && <1.3
183+
, text
184184
, unicode-transforms
185185
if flag(use-gauge)
186186
build-depends: gauge >=0.2.0 && <0.3

0 commit comments

Comments
 (0)