Add elasticLength function
parent
b3dc1dff04
commit
1e8d62232c
|
@ -32,6 +32,7 @@ module Language.Haskell.Brittany.Internal.BackendUtils
|
||||||
, layoutWritePriorComments
|
, layoutWritePriorComments
|
||||||
, layoutWritePostComments
|
, layoutWritePostComments
|
||||||
, layoutRemoveIndentLevelLinger
|
, layoutRemoveIndentLevelLinger
|
||||||
|
, elasticLength
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ import Language.Haskell.Brittany.Internal.Utils
|
||||||
|
|
||||||
import GHC ( Located, GenLocated(L), moduleNameString )
|
import GHC ( Located, GenLocated(L), moduleNameString )
|
||||||
|
|
||||||
|
import Text.Ascii (isAscii)
|
||||||
|
|
||||||
|
|
||||||
traceLocal
|
traceLocal
|
||||||
|
@ -102,6 +104,16 @@ layoutWriteAppend t = do
|
||||||
, _lstate_addSepSpace = Nothing
|
, _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
|
layoutWriteAppendSpaces
|
||||||
:: ( MonadMultiWriter Text.Builder.Builder m
|
:: ( MonadMultiWriter Text.Builder.Builder m
|
||||||
, MonadMultiState LayoutState m
|
, MonadMultiState LayoutState m
|
||||||
|
|
Loading…
Reference in New Issue