From 15d014abb825837f0fd7c9e17d5907001135faaf Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Wed, 6 Sep 2017 12:38:42 +0200 Subject: the parser in the C runtime can now detect incomplete sentences just like the parser in the Haskell runtime. This is also reflected in all bindings. --- src/runtime/haskell-bind/PGF2/FFI.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/runtime/haskell-bind/PGF2') diff --git a/src/runtime/haskell-bind/PGF2/FFI.hs b/src/runtime/haskell-bind/PGF2/FFI.hs index a47655d8d..3f30631d8 100644 --- a/src/runtime/haskell-bind/PGF2/FFI.hs +++ b/src/runtime/haskell-bind/PGF2/FFI.hs @@ -2,7 +2,7 @@ module PGF2.FFI where -import Foreign ( alloca, poke ) +import Foreign ( alloca, peek, poke ) import Foreign.C import Foreign.Ptr import Foreign.ForeignPtr @@ -116,6 +116,19 @@ peekUtf8CString ptr = else do cs <- decode pptr return (((toEnum . fromEnum) x) : cs) +peekUtf8CStringLen :: CString -> CInt -> IO String +peekUtf8CStringLen ptr len = + alloca $ \pptr -> + poke pptr ptr >> decode pptr (ptr `plusPtr` fromIntegral len) + where + decode pptr end = do + ptr <- peek pptr + if ptr >= end + then return [] + else do x <- gu_utf8_decode pptr + cs <- decode pptr end + return (((toEnum . fromEnum) x) : cs) + newUtf8CString :: String -> Ptr GuPool -> IO CString newUtf8CString s pool = do -- An UTF8 character takes up to 6 bytes. We allocate enough -- cgit v1.2.3