continue conversion

Add Utility.OsString, with a special case for length.
This commit is contained in:
Joey Hess 2025-01-23 11:46:35 -04:00
parent c3c8870752
commit 12660314f1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 69 additions and 37 deletions

32
Utility/OsString.hs Normal file
View file

@ -0,0 +1,32 @@
{- OsString manipulation. Or ByteString when not built with OsString.
- Import qualified.
-
- Copyright 2025 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
module Utility.OsString (
module X,
length
) where
#ifdef WITH_OSPATH
import System.OsString as X hiding (length)
import qualified System.OsString
import qualified Data.ByteString as B
import Utility.OsPath
{- Avoid System.OsString.length, which returns the number of code points on
- windows. This is the number of bytes. -}
length :: System.OsString.OsString -> Int
length = B.length . fromOsString
#else
import Data.ByteString as X hiding (length)
import Data.ByteString (length)
#endif