@@ -15,18 +15,27 @@ module ICU.Char
1515 , UGeneralCategory (.. )
1616 , toGeneralCategory
1717 , charType
18+ , UProperty (.. )
19+ , hasBinaryProperty
1820 , isNoncharacter
21+ , isLowerCase
22+ , isUpperCase
23+ , isLower
24+ , isUpper
25+ , isTitle
26+ , toLowerCase
27+ , toUpperCase
1928 ) where
2029
2130#include <unicode/uchar.h>
2231
23- import Data.Char (ord )
32+ import Data.Char (chr , ord )
2433import qualified Data.Char as Char
2534import Data.Int (Int8 )
2635import Data.Version (Version , makeVersion )
2736import Data.Word (Word32 )
2837import Foreign (Ptr )
29- import Foreign.C (CInt )
38+ import Foreign.C (CInt ( .. ) )
3039import Foreign.Marshal.Array (allocaArray , peekArray )
3140import System.IO.Unsafe (unsafePerformIO )
3241
@@ -137,19 +146,56 @@ toGeneralCategory = \case
137146 FinalPunctuation -> Char. FinalQuote
138147
139148{# enum define UProperty {
140- UCHAR_NONCHARACTER_CODE_POINT as NoncharacterCodePoint
149+ UCHAR_NONCHARACTER_CODE_POINT as NoncharacterCodePoint ,
150+ UCHAR_LOWERCASE as LowerCase ,
151+ UCHAR_UPPERCASE as UpperCase
141152 }
142153 deriving (Bounded , Eq , Ord , Show ) # }
143154
144155foreign import ccall safe " icu.h __hs_u_hasBinaryProperty" u_hasBinaryProperty
145- :: UChar32 -> Int -> Bool
156+ :: UChar32 -> CInt -> Bool
146157
147- -- hasBinaryProperty :: UChar32 -> Int -> Bool
148- -- hasBinaryProperty = {#call pure u_hasBinaryProperty as __hs_u_hasBinaryProperty#}
149- -- {#fun pure u_hasBinaryProperty as hasBinaryProperty
150- -- {`UChar32', `Int'} -> `Bool' #}
158+ hasBinaryProperty :: Char -> UProperty -> Bool
159+ hasBinaryProperty c
160+ = u_hasBinaryProperty (fromIntegral (ord c))
161+ . fromIntegral
162+ . fromEnum
151163
152164isNoncharacter :: Char -> Bool
153- isNoncharacter c = u_hasBinaryProperty
154- (fromIntegral (ord c))
155- (fromEnum NoncharacterCodePoint )
165+ isNoncharacter = (`hasBinaryProperty` NoncharacterCodePoint )
166+
167+ isLowerCase :: Char -> Bool
168+ isLowerCase = (`hasBinaryProperty` LowerCase )
169+
170+ isUpperCase :: Char -> Bool
171+ isUpperCase = (`hasBinaryProperty` UpperCase )
172+
173+ foreign import ccall safe " icu.h __hs_u_islower" u_islower
174+ :: UChar32 -> Bool
175+
176+ isLower :: Char -> Bool
177+ isLower = u_islower . fromIntegral . ord
178+
179+ foreign import ccall safe " icu.h __hs_u_isupper" u_isupper
180+ :: UChar32 -> Bool
181+
182+ isUpper :: Char -> Bool
183+ isUpper = u_isupper . fromIntegral . ord
184+
185+ foreign import ccall safe " icu.h __hs_u_istitle" u_istitle
186+ :: UChar32 -> Bool
187+
188+ isTitle :: Char -> Bool
189+ isTitle = u_istitle . fromIntegral . ord
190+
191+ foreign import ccall safe " icu.h __hs_u_tolower" u_tolower
192+ :: UChar32 -> UChar32
193+
194+ toLowerCase :: Char -> Char
195+ toLowerCase = chr . fromIntegral . u_tolower . fromIntegral . ord
196+
197+ foreign import ccall safe " icu.h __hs_u_toupper" u_toupper
198+ :: UChar32 -> UChar32
199+
200+ toUpperCase :: Char -> Char
201+ toUpperCase = chr . fromIntegral . u_toupper . fromIntegral . ord
0 commit comments