Commit Graph

11 Commits

Author SHA1 Message Date
Ivan Gromakovskii
8b4d41a6bd
Deprecate Data.Text.IO.Utf8
Problem: text-2.1 has Data.Text.IO.Utf8 whose name conflicts with
our module with the same name.

Solution: our module contains 2 functions: `readFile` and `writeFile`.
They are implemented differently from `text` versions, but look
semantically equivalent. Our functions are also polymorphic in the
monad type, but that's orthogonal to the purpose of this package,
so we can sacrifice this polymorphism.
So it looks like our module doesn't add much value anymore and should
be deleted.
However, it's a good practice to deprecate something before deleting,
so we deprecate this module instead. It will be deleted in a future
version.
Note that the same module for lazy Text remains intact, since there
are apparently no such functions for lazy Text in text-2.1.
2024-01-16 22:00:20 +01:00
Sergey Gulin
2629e86f7b
[Chore] Use new flake template
Problem: We have introduced a new template for Haskell libraries and
need to update this package according to this template.

Solution: Use new template, bump dependencies, remove unused license,
apply formatting and hlint suggestions.
2023-03-20 23:46:53 +03:00
Kirill Elagin
57b6845f5e doc: Clarify a bit 2020-06-11 15:58:50 +03:00
Kirill Elagin
d0c01c253c Fix a typo 2020-05-20 01:13:02 +03:00
Kirill Elagin
0744864fd0 Fixup documentation 2020-02-17 19:39:55 -05:00
Kirill Elagin
40069d4b2b Allow not changing file handles to UTF-8
The old interface only allowed one to perform terminal detection on a
handle and change it to UTF-8 if it was not a terminal. Turns our, it
makes sense to sometimes leave the original encoding on a handle even if
it does not point to a terminal.

* Change the interface to separate these two use-cases.
* Extract main-wrappers to a new `Main` module.
2020-02-17 19:39:40 -05:00
Kirill Elagin
f6bc3fc0ca Add correctness tests
* Split out the actual encoding choice logic into a separate Internal
  module to make it possible to cover it with tests.
* Make this function a little more efficient compared to the previous
  purely pure function.
* Keep a completely pure function as a specficiation for ease of reading
  and for testing by comparing the actualy function to the pure one.

* Add tests that check that the pure function makes sense.
* Add tests that compare the output of the real function to the output
  of the pure function on some real handles.
* Add tests that check that functions that are supposed to actually
  modify the encoding of a handle actually do modify it.
2020-02-17 17:58:29 -05:00
Kirill Elagin
83f7b5967e Add lazy versions of Text functions
We had `readFile` and `writeFile` fot strict `Text`, but not for
lazy.

Add lazy versions of the same functions, basically, by copy-pasting.
2020-02-17 17:53:04 -05:00
Kirill Elagin
5b98b490bc Implement hWithEncoding
This function allows one to not only safely set the best encoding on a
file descriptor, but also restore the previous one. The idea is that it
will be used on file descriptors that come from the outside and so we
don’t know how they were used and will be used after us.
2020-02-16 21:49:07 -05:00
Kirill Elagin
934251c90c Change hSetEncoding to choose best encoding
The previous version of hSetEncoding would always set UTF-8.
This can screw things up if it is accidentally called, for example,
on a terminal handle or a handle in binary mode.

Change it to use `hSetBestUtf8Enc` internally so that it now follows the
same loginc in determining the encoding to set.
2020-02-16 21:46:33 -05:00
Kirill Elagin
08407bbe4d First version 2020-02-15 19:15:52 -05:00