From ae9f49e0a6e7d5a0c906d8e4fd153ad553cdecf1 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 7 Mar 2026 23:28:58 +0100 Subject: use mono-traversable --- src/Blessings/String/WCWidth.hs | 66 ----------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/Blessings/String/WCWidth.hs (limited to 'src/Blessings/String') diff --git a/src/Blessings/String/WCWidth.hs b/src/Blessings/String/WCWidth.hs deleted file mode 100644 index 16ab853..0000000 --- a/src/Blessings/String/WCWidth.hs +++ /dev/null @@ -1,66 +0,0 @@ -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE ImportQualifiedPost #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE PatternGuards #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} -module Blessings.String.WCWidth - ( module Blessings - ) where - -import Blessings -import Blessings.Internal -import Data.Char.WCWidth qualified as WCWidth -import Data.List qualified as List - - -instance Blessable String where - length = length' - drop = drop' - take = take' - splitAt = splitAt' - break = List.break - intercalate = List.intercalate - fromWord8 = Prelude.show - show = Prelude.show - - -length' :: String -> Int -length' = foldr ((+) . wcwidth') 0 - -drop' :: Int -> String -> String -drop' k t = - if k <= 0 - then t - else - case t of - c : t' -> - drop' (k - wcwidth' c) t' - [] -> mempty - -take' :: Int -> String -> String -take' k0 = - rec k0 - where - rec k t = - if | (c : t') <- t, nc <- wcwidth' c, nc <= k -> - c : rec (k - nc) t' - - | otherwise -> - [] - -splitAt' :: Int -> String -> (String, String) -splitAt' k0 = - rec k0 [] - where - rec k a t = - if | (c : t') <- t, nc <- wcwidth' c, nc <= k -> - rec (k - nc) (c : a) t' - - | otherwise -> - (reverse a, t) - --- TODO this breaks when WCWidth.wcwidth returns -1, which happens for --- non-printable characters like '\n'. --- Following wcwidth' isn't entirely correct because WCWidth.wcwidth '\0' == 0 -wcwidth' :: Char -> Int -wcwidth' = max 1 . WCWidth.wcwidth -- cgit v1.2.3