Add elasticLength function

pull/123/head
waddlaw 2018-02-26 17:45:09 +09:00
parent b3dc1dff04
commit 1e8d62232c
1 changed files with 12 additions and 0 deletions

View File

@ -32,6 +32,7 @@ module Language.Haskell.Brittany.Internal.BackendUtils
, layoutWritePriorComments
, layoutWritePostComments
, layoutRemoveIndentLevelLinger
, elasticLength
)
where
@ -51,6 +52,7 @@ import Language.Haskell.Brittany.Internal.Utils
import GHC ( Located, GenLocated(L), moduleNameString )
import Text.Ascii (isAscii)
traceLocal
@ -102,6 +104,16 @@ layoutWriteAppend t = do
, _lstate_addSepSpace = Nothing
}
-- |
-- >>> elasticLength "あ"
-- 2
-- >>> elasticLength "abc"
-- 3
-- >>> elasticLength "aあa"
-- 4
elasticLength :: Text -> Int
elasticLength = Text.foldl' (\len c -> if isAscii c then len + 1 else len + 2) 0
layoutWriteAppendSpaces
:: ( MonadMultiWriter Text.Builder.Builder m
, MonadMultiState LayoutState m