Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mhs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
# windows doesn't quite work yet
os: [ubuntu-latest, macOS-15-intel, macOS-latest]
mhs: [0.15.0.0]
mhs: [0.16.0.0]

steps:

Expand Down
2 changes: 2 additions & 0 deletions System/OsString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module System.OsString

-- * Word construction
, unsafeFromChar
, fromWord

-- * Word deconstruction
, toChar
Expand Down Expand Up @@ -135,6 +136,7 @@ where

import System.OsString.Internal
( unsafeFromChar
, fromWord
, toChar
, encodeUtf
, unsafeEncodeUtf
Expand Down
19 changes: 19 additions & 0 deletions System/OsString/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module System.OsString.MODULE_NAME

-- * Word construction
, unsafeFromChar
, fromWord

-- * Word deconstruction
, toChar
Expand Down Expand Up @@ -210,6 +211,11 @@ import Data.Bifunctor ( bimap )
import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
import qualified System.OsString.Data.ByteString.Short as BS8

#ifdef WINDOWS
import Data.Word (Word16)
#else
import Data.Word (Word8)
#endif


#ifdef WINDOWS_DOC
Expand Down Expand Up @@ -547,6 +553,19 @@ singleton = coerce BSP.singleton
empty :: PLATFORM_STRING
empty = mempty

#ifdef WINDOWS
-- | Convert from 'Word16'.
--
-- @since 2.0.11
fromWord :: Word16 -> PLATFORM_WORD
fromWord = WindowsChar
#else
-- | Convert from 'Word8'.
--
-- @since 2.0.11
fromWord :: Word8 -> PLATFORM_WORD
fromWord = PosixChar
#endif

#ifdef WINDOWS
-- | Truncates to 2 octets.
Expand Down
11 changes: 11 additions & 0 deletions System/OsString/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import qualified System.OsString.Posix as PF
import GHC.Stack (HasCallStack)
import Data.Coerce (coerce)
import Data.Type.Coercion (coerceWith)
import Data.Word (Word8)



Expand Down Expand Up @@ -256,6 +257,16 @@ singleton = coerce PF.singleton
unsafeFromChar :: Char -> OsChar
unsafeFromChar = coerce PF.unsafeFromChar

-- | Convert from 'Word8'.
--
-- @since 2.0.11
fromWord :: Word8 -> OsChar
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
fromWord = OsChar . WindowsChar . fromIntegral
#else
fromWord = OsChar . PosixChar
#endif

-- | Converts back to a unicode codepoint (total).
toChar :: OsChar -> Char
toChar = case coercionToPlatformTypes of
Expand Down
6 changes: 3 additions & 3 deletions System/OsString/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ type PlatformString = PosixString
#endif

newtype WindowsChar = WindowsChar { getWindowsChar :: Word16 }
deriving (Eq, Ord, Typeable, Generic, NFData)
deriving (Eq, Ord, Typeable, Generic, NFData, Lift)

instance Show WindowsChar where
show (WindowsChar wc) = show wc

newtype PosixChar = PosixChar { getPosixChar :: Word8 }
deriving (Eq, Ord, Typeable, Generic, NFData)
deriving (Eq, Ord, Typeable, Generic, NFData, Lift)

instance Show PosixChar where
show (PosixChar pc) = show pc
Expand Down Expand Up @@ -206,7 +206,7 @@ instance Semigroup OsString where
-- On Windows, this is restricted to two-octet codepoints 'Word16',
-- on POSIX one-octet ('Word8').
newtype OsChar = OsChar { getOsChar :: PlatformChar }
deriving (Typeable, Generic, NFData)
deriving (Typeable, Generic, NFData, Lift)

instance Show OsChar where
show (OsChar pc) = show pc
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for [`os-string` package](http://hackage.haskell.org/package/os-string)

## 2.0.11 *Jun 2026*

* Add Lift instance to `OsChar`, `PosixChar` and `WindowsChar`
* Add `fromWord`

## 2.0.10 *Jan 2026*

* fix build on GHC 9.14 wrt [#40](https://github.com/haskell/os-string/issues/40)
Expand Down
15 changes: 6 additions & 9 deletions os-string.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: os-string
version: 2.0.10
version: 2.0.11

-- NOTE: Don't forget to update ./changelog.md
license: BSD-3-Clause
Expand All @@ -16,14 +16,11 @@ category: System
build-type: Simple
synopsis: Library for manipulating Operating system strings.
tested-with:
GHC ==8.6.5
|| ==8.8.4
|| ==8.10.7
|| ==9.0.2
|| ==9.2.8
|| ==9.4.8
|| ==9.6.3
|| ==9.8.1
GHC ==9.6.7
|| ==9.8.4
|| ==9.10.3
|| ==9.12.4
|| ==9.14.1

description:
This package provides functionality for manipulating @OsString@ values, and is shipped with <https://www.haskell.org/ghc/ GHC>.
Expand Down
Loading