on master help sign in
Drop a magic number
36e23b5Bryan O'Sullivan
Data/Text/Encoding.hs+4−2
@@ -83,6 +83,8 @@ import qualified Data.Text.Encoding.Utf16 as U16
83import qualified Data.Text.Fusion as F
83import qualified Data.Text.Fusion as F
84import Data.Text.Unsafe (unsafeDupablePerformIO)
84import Data.Text.Unsafe (unsafeDupablePerformIO)
85
85
86+#include "text_cbits.h"
87+
86-- $strict
88-- $strict
87--
89--
88-- All of the single-parameter functions for decoding bytestrings
90-- All of the single-parameter functions for decoding bytestrings
@@ -169,7 +171,7 @@ decodeUtf8With' onErr = decodeChunk (0,0)
169 codepointPtr statePtr
171 codepointPtr statePtr
170 state <- peek statePtr
172 state <- peek statePtr
171 case state of
173 case state of
172− 12 -> do
174+ UTF8_REJECT -> do
173 -- We encountered an encoding error
175 -- We encountered an encoding error
174 x <- peek curPtr'
176 x <- peek curPtr'
175 case onErr desc (Just x) of
177 case onErr desc (Just x) of
@@ -181,7 +183,7 @@ decodeUtf8With' onErr = decodeChunk (0,0)
181 poke destOffPtr (destOff + fromIntegral w)
183 poke destOffPtr (destOff + fromIntegral w)
182 poke statePtr 0
184 poke statePtr 0
183 loop $ curPtr' `plusPtr` 1
185 loop $ curPtr' `plusPtr` 1
184−
186+
185 _ -> do
187 _ -> do
186 -- We encountered the end of the buffer while decoding
188 -- We encountered the end of the buffer while decoding
187 n <- peek destOffPtr
189 n <- peek destOffPtr
cbits/cbits.c+1
@@ -9,6 +9,7 @@
9#include <string.h>
9#include <string.h>
10#include <stdint.h>
10#include <stdint.h>
11#include <stdio.h>
11#include <stdio.h>
12+#include "text_cbits.h"
12
13
13void _hs_text_memcpy(void *dest, size_t doff, const void *src, size_t soff,
14void _hs_text_memcpy(void *dest, size_t doff, const void *src, size_t soff,
14 size_t n)
15 size_t n)
include/text_cbits.hnew file+11
@@ -0,0 +1,11 @@
1+/*
2+ * Copyright (c) 2013 Bryan O'Sullivan <bos@serpentine.com>.
3+ */
4+
5+#ifndef _text_cbits_h
6+#define _text_cbits_h
7+
8+#define UTF8_ACCEPT 0
9+#define UTF8_REJECT 12
10+
11+#endif
text.cabal+3−1
@@ -77,7 +77,8 @@ flag integer-simple
77 default: False
77 default: False
78
78
79library
79library
80− c-sources: cbits/cbits.c
80+ c-sources: cbits/cbits.c
81+ include-dirs: include
81
82
82 exposed-modules:
83 exposed-modules:
83 Data.Text
84 Data.Text
@@ -160,6 +161,7 @@ test-suite tests
160 hs-source-dirs: tests .
161 hs-source-dirs: tests .
161 main-is: Tests.hs
162 main-is: Tests.hs
162 c-sources: cbits/cbits.c
163 c-sources: cbits/cbits.c
164+ include-dirs: include
163
165
164 ghc-options:
166 ghc-options:
165 -Wall -threaded -O0 -rtsopts
167 -Wall -threaded -O0 -rtsopts