Commits

Bryan O'Sullivan committed 2c0650a

Introduce a special overflow error handling function.

Comments (0)

Files changed (1)

Data/Text/ICU/Error/Internal.hsc

     , isSuccess
     , errorName
     , handleError
+    , handleOverflowError
     , handleParseError
     , throwOnError
     , withError
                        throwOnError =<< peek errPtr
                        return ret
 
+handleOverflowError :: (Ptr UErrorCode -> IO a) -> IO (Either a a)
+{-# INLINE handleOverflowError #-}
+handleOverflowError action =
+    with 0 $ \uerrPtr -> do
+      ret <- action uerrPtr
+      err <- peek uerrPtr
+      if err > 0
+        then if err == #const U_BUFFER_OVERFLOW_ERROR
+             then return (Left ret)
+             else throwIO (ICUError err)
+        else return (Right ret)
+
 handleParseError :: (ICUError -> Bool)
                  -> (Ptr UParseError -> Ptr UErrorCode -> IO a) -> IO a
 handleParseError isParseError action =