Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix travis script

  • Loading branch information...
commit d1520a0a9b7f3508feb599a3b6f3f06c32f42421 1 parent f406c10
Tim Baumann authored
2  .travis.yml
... ...
@@ -1,3 +1,3 @@
1 1
 language: haskell
2 2
 after_script:
3  
-  - "cat dist/test/operational-transformation-*-tests.log"
  3
+  - "cat dist/test/ot-*-tests.log"
61  src/Data/Text/Rope.hs
... ...
@@ -0,0 +1,61 @@
  1
+{-# LANGUAGE MultiParamTypeClasses, GeneralizedNewtypeDeriving #-}
  2
+
  3
+module Data.Text.Rope
  4
+  ( CharOffset (..)
  5
+  , Rope
  6
+  , empty
  7
+  , null
  8
+  , splitAt
  9
+  , take
  10
+  , drop
  11
+  , concat
  12
+  , isPrefixOf
  13
+  ) where
  14
+
  15
+import Prelude hiding (splitAt, take, drop, null, concat)
  16
+import Data.FingerTree (viewr, ViewR (..), viewl, ViewL (..), Measured (..), (<|), (|>), split)
  17
+import qualified Data.FingerTree as FT
  18
+import qualified Data.Text as T
  19
+import Data.Monoid
  20
+import Data.Foldable (toList)
  21
+
  22
+newtype CharOffset = CharOffset { getCharOffset :: Int } deriving (Enum, Real, Ord, Eq, Num, Integral)
  23
+
  24
+type Rope = FT.FingerTree CharOffset T.Text
  25
+
  26
+instance Monoid CharOffset where
  27
+  mempty = CharOffset 0
  28
+  mappend = (+)
  29
+
  30
+instance Measured CharOffset T.Text where
  31
+  measure = CharOffset . T.length
  32
+
  33
+empty :: Rope
  34
+empty = FT.empty
  35
+
  36
+null :: Rope -> Bool
  37
+null r = case viewl r of
  38
+  EmptyL -> True
  39
+  x :< xs -> T.null x && null xs
  40
+
  41
+splitAt :: CharOffset -> Rope -> (Rope, Rope)
  42
+splitAt n r = case viewr lr of
  43
+    EmptyR -> (lr, rr)
  44
+    llr :> m -> let (lm, rm) = T.splitAt (fromIntegral $ n - measure lr) m
  45
+                in (llr |> lm, rm <| rr)
  46
+  where
  47
+    (lr, rr) = split (> n) r
  48
+
  49
+take, drop :: CharOffset -> Rope -> Rope
  50
+take n = fst . splitAt n
  51
+drop n = snd . splitAt n
  52
+
  53
+concat :: Rope -> T.Text
  54
+concat = T.concat . toList
  55
+
  56
+isPrefixOf :: T.Text -> Rope -> Bool
  57
+text `isPrefixOf` rope = case viewl rope of
  58
+  EmptyL -> T.null text
  59
+  chunk :< rope' -> if T.length text < T.length chunk
  60
+                      then text `T.isPrefixOf` chunk
  61
+                      else chunk `T.isPrefixOf` text && (T.drop (T.length chunk) text) `isPrefixOf` rope'

0 notes on commit d1520a0

Please sign in to comment.
Something went wrong with that request. Please try again.