<p>Use the text library instead? </p>
<p>On Jan 5, 2011 2:09 AM, "Tony Morris" <<a href="mailto:tonymorris@gmail.com">tonymorris@gmail.com</a>> wrote:<br>
><br>
> I am reading files with System.IO.readFile. Some of these files start<br>
> with a UTF-8 Byte Order Marker (0xef 0xbb 0xbf). For some functions that<br>
> process this String, this causes choking so I drop the BOM as shown<br>
> below. This feels particularly hacky, but I am not in control of many of<br>
> these functions (that perhaps could use ByteString with a better solution).<br>
><br>
> I'm wondering if there is a better way of achieving this goal. Thanks<br>
> for any tips.<br>
><br>
><br>
> dropBOM ::<br>
> String<br>
> -> String<br>
> dropBOM [] =<br>
> []<br>
> dropBOM s@(x:xs) =<br>
> let unicodeMarker = '\65279' -- UTF-8 BOM<br>
> in if x == unicodeMarker then xs else s<br>
><br>
> readBOMFile ::<br>
> FilePath<br>
> -> IO String<br>
> readBOMFile p =<br>
> dropBOM `fmap` readFile p<br>
><br>
><br>
><br>
><br>
> --<br>
> Tony Morris<br>
> <a href="http://tmorris.net/">http://tmorris.net/</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</p>