Created
September 17, 2017 20:00
-
-
Save kermitaner/1d024d1e74e599fe876a3dbab8feebd5 to your computer and use it in GitHub Desktop.
;; utf8 conversion red from win1252 codepage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red[] | |
;; read win1252 textfile , convert to utf8 text string / lines with _myread %filename | |
;;#include %../inc/_utf8.red | |
_m: [] | |
insert/dup _m #{} 255 | |
;----------------------------------------- | |
_ini: function [/extern _m ][ | |
;----------------------------------------- | |
;; erzeugen ut8 map dec -> utf8 | |
bin: debase {4oKswoHigJrGkuKAnuKApuKAoOKAocuG4oCwxaDigLnFksKNxb3Cj8KQ4oCY4oCZ4oCc4oCd4oCi4oCT4oCUy5zihKLFoeKAusWTwp3FvsW4wqDCocKiwqPCpMKlwqbCp8KowqnCqsKrwqzCrcKuwq/CsMKxwrLCs8K0wrXCtsK3wrjCucK6wrvCvMK9wr7Cv8OAw4HDgsODw4TDhcOGw4fDiMOJw4rDi8OMw43DjsOPw5DDkcOSw5PDlMOVw5bDl8OYw5nDmsObw5zDncOew5/DoMOhw6LDo8Okw6XDpsOnw6jDqcOqw6vDrMOtw67Dr8Oww7HDssOzw7TDtcO2w7fDuMO5w7rDu8O8w73DvsO/} | |
ut8: append #{} first bin | |
ind: 128 | |
foreach ele (skip bin 1) [ | |
if (ele >= to-integer #{c0}) [ | |
_m/:ind: copy ut8 | |
ind: ind + 1 | |
clear ut8 | |
] | |
append ut8 ele | |
] | |
_m/:ind: ut8 | |
] | |
;----------------------------------------- | |
_myread: function [fi /lines /extern _m ][ | |
;----------------------------------------- | |
M40: 1024 * 1024 * 40 | |
if M40 < (size? fi) [print "Error: file > 40M !!" halt] | |
bin: read/binary fi | |
bout: #{} | |
foreach ele bin [ either ele < 128 [append bout ele][append bout _m/:ele] ] | |
bin: to-string bout | |
if lines [return split bin newline] | |
return bin | |
] | |
_ini | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment