diff options
| author | Krasimir Angelov <kr.angelov@gmail.com> | 2017-09-06 12:38:42 +0200 |
|---|---|---|
| committer | Krasimir Angelov <kr.angelov@gmail.com> | 2017-09-06 12:38:42 +0200 |
| commit | 15d014abb825837f0fd7c9e17d5907001135faaf (patch) | |
| tree | bc569f465432042702dfaa240746b8c6db609588 /src/runtime/haskell-bind/PGF2 | |
| parent | 18f2135785a71a1e93519a060d40b7ba523cf03b (diff) | |
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.
Diffstat (limited to 'src/runtime/haskell-bind/PGF2')
| -rw-r--r-- | src/runtime/haskell-bind/PGF2/FFI.hs | 15 |
1 files changed, 14 insertions, 1 deletions
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 |
