LazUtils: Add encoding ISO-8859-16 to LConvEncoding. Issue #39794, patch by Alexey Torgashin.

This commit is contained in:
Juha 2022-06-12 18:50:23 +03:00
parent f5321043f4
commit 7cd0c6804d
2 changed files with 328 additions and 4 deletions

View File

@ -1050,6 +1050,266 @@ const
#195#190, // #254
#195#191 // #255
);
ArrayISO_8859_16ToUTF8: TCharToUTF8Table = (
#0, // #0
#1, // #1
#2, // #2
#3, // #3
#4, // #4
#5, // #5
#6, // #6
#7, // #7
#8, // #8
#9, // #9
#10, // #10
#11, // #11
#12, // #12
#13, // #13
#14, // #14
#15, // #15
#16, // #16
#17, // #17
#18, // #18
#19, // #19
#20, // #20
#21, // #21
#22, // #22
#23, // #23
#24, // #24
#25, // #25
#26, // #26
#27, // #27
#28, // #28
#29, // #29
#30, // #30
#31, // #31
' ', // ' '
'!', // '!'
'"', // '"'
'#', // '#'
'#$', // '#$'
'%', // '%'
'&', // '&'
'''', // ''''
'(', // '('
')', // ')'
'*', // '*'
'+', // '+'
',', // ','
'-', // '-'
'.', // '.'
'/', // '/'
'0', // '0'
'1', // '1'
'2', // '2'
'3', // '3'
'4', // '4'
'5', // '5'
'6', // '6'
'7', // '7'
'8', // '8'
'9', // '9'
':', // ':'
';', // ';'
'<', // '<'
'=', // '='
'>', // '>'
'?', // '?'
'@', // '@'
'A', // 'A'
'B', // 'B'
'C', // 'C'
'D', // 'D'
'E', // 'E'
'F', // 'F'
'G', // 'G'
'H', // 'H'
'I', // 'I'
'J', // 'J'
'K', // 'K'
'L', // 'L'
'M', // 'M'
'N', // 'N'
'O', // 'O'
'P', // 'P'
'Q', // 'Q'
'R', // 'R'
'S', // 'S'
'T', // 'T'
'U', // 'U'
'V', // 'V'
'W', // 'W'
'X', // 'X'
'Y', // 'Y'
'Z', // 'Z'
'[', // '['
'\', // '\'
']', // ']'
'^', // '^'
'_', // '_'
'`', // '`'
'a', // 'a'
'b', // 'b'
'c', // 'c'
'd', // 'd'
'e', // 'e'
'f', // 'f'
'g', // 'g'
'h', // 'h'
'i', // 'i'
'j', // 'j'
'k', // 'k'
'l', // 'l'
'm', // 'm'
'n', // 'n'
'o', // 'o'
'p', // 'p'
'q', // 'q'
'r', // 'r'
's', // 's'
't', // 't'
'u', // 'u'
'v', // 'v'
'w', // 'w'
'x', // 'x'
'y', // 'y'
'z', // 'z'
'{', // '{'
'|', // '|'
'}', // '}'
'~', // '~'
#127, // #127
#194#128, // #128
#194#129, // #129
#194#130, // #130
#194#131, // #131
#194#132, // #132
#194#133, // #133
#194#134, // #134
#194#135, // #135
#194#136, // #136
#194#137, // #137
#194#138, // #138
#194#139, // #139
#194#140, // #140
#194#141, // #141
#194#142, // #142
#194#143, // #143
#194#144, // #144
#194#145, // #145
#194#146, // #146
#194#147, // #147
#194#148, // #148
#194#149, // #149
#194#150, // #150
#194#151, // #151
#194#152, // #152
#194#153, // #153
#194#154, // #154
#194#155, // #155
#194#156, // #156
#194#157, // #157
#194#158, // #158
#194#159, // #159
#194#160, // #160
#$C4#$84, // #$A1
#$C4#$85, // #$A2
#$C5#$81, // #$A3
#$E2#$82#$AC, // #$A4
#$E2#$80#$9E, // #$A5
#$C5#$A0, // #$A6
#$C2#$A7, // #$A7
#$C5#$A1, // #$A8
#$C2#$A9, // #$A9
#$C8#$98, // #$AA
#$C2#$AB, // #$AB
#$C5#$B9, // #$AC
#$C2#$AD, // #$AD
#$C5#$BA, // #$AE
#$C5#$BB, // #$AF
#$C2#$B0, // #$B0
#$C2#$B1, // #$B1
#$C4#$8C, // #$B2
#$C5#$82, // #$B3
#$C5#$BD, // #$B4
#$E2#$80#$9D, // #$B5
#$C2#$B6, // #$B6
#$C2#$B7, // #$B7
#$C5#$BE, // #$B8
#$C4#$8D, // #$B9
#$C8#$99, // #$BA
#$C2#$BB, // #$BB
#$C5#$92, // #$BC
#$C5#$93, // #$BD
#$C5#$B8, // #$BE
#$C5#$BC, // #$BF
#$C3#$80, // #$C0
#$C3#$81, // #$C1
#$C3#$82, // #$C2
#$C4#$82, // #$C3
#$C3#$84, // #$C4
#$C4#$86, // #$C5
#$C3#$86, // #$C6
#$C3#$87, // #$C7
#$C3#$88, // #$C8
#$C3#$89, // #$C9
#$C3#$8A, // #$CA
#$C3#$8B, // #$CB
#$C3#$8C, // #$CC
#$C3#$8D, // #$CD
#$C3#$8E, // #$CE
#$C3#$8F, // #$CF
#$C4#$90, // #$D0
#$C5#$83, // #$D1
#$C3#$92, // #$D2
#$C3#$93, // #$D3
#$C3#$94, // #$D4
#$C5#$90, // #$D5
#$C3#$96, // #$D6
#$C5#$9A, // #$D7
#$C5#$B0, // #$D8
#$C3#$99, // #$D9
#$C3#$9A, // #$DA
#$C3#$9B, // #$DB
#$C3#$9C, // #$DC
#$C4#$98, // #$DD
#$C8#$9A, // #$DE
#$C3#$9F, // #$DF
#$C3#$A0, // #$E0
#$C3#$A1, // #$E1
#$C3#$A2, // #$E2
#$C4#$83, // #$E3
#$C3#$A4, // #$E4
#$C4#$87, // #$E5
#$C3#$A6, // #$E6
#$C3#$A7, // #$E7
#$C3#$A8, // #$E8
#$C3#$A9, // #$E9
#$C3#$AA, // #$EA
#$C3#$AB, // #$EB
#$C3#$AC, // #$EC
#$C3#$AD, // #$ED
#$C3#$AE, // #$EE
#$C3#$AF, // #$EF
#$C4#$91, // #$F0
#$C5#$84, // #$F1
#$C3#$B2, // #$F2
#$C3#$B3, // #$F3
#$C3#$B4, // #$F4
#$C5#$91, // #$F5
#$C3#$B6, // #$F6
#$C5#$9B, // #$F7
#$C5#$B1, // #$F8
#$C3#$B9, // #$F9
#$C3#$BA, // #$FA
#$C3#$BB, // #$FB
#$C3#$BC, // #$FC
#$C4#$99, // #$FD
#$C8#$9B, // #$FE
#$C3#$BF // #$FF
);
ArrayISO_8859_2ToUTF8: TCharToUTF8Table = (
#0, // #0
#1, // #1

View File

@ -82,6 +82,7 @@ const
EncodingCPIso9 = 'iso88599';
EncodingCPIso14 = 'iso885914';
EncodingCPIso15 = 'iso885915';
EncodingCPIso16 = 'iso885916';
//signatures in ansi
const
@ -129,6 +130,7 @@ function ISO_8859_2ToUTF8(const s: string): string; // eastern europe
function ISO_8859_9ToUTF8(const s: string): string; // Turkish
function ISO_8859_14ToUTF8(const s: string): string;
function ISO_8859_15ToUTF8(const s: string): string; // Western European languages
function ISO_8859_16ToUTF8(const s: string): string;
function CP1250ToUTF8(const s: string): string; // central europe
function CP1251ToUTF8(const s: string): string; // cyrillic
function CP1252ToUTF8(const s: string): string; // latin 1
@ -158,6 +160,7 @@ function UTF8ToISO_8859_2(const s: string; SetTargetCodePage: boolean = false):
function UTF8ToISO_8859_9(const s: string; SetTargetCodePage: boolean = false): RawByteString; // Turkish
function UTF8ToISO_8859_14(const s: string; SetTargetCodePage: boolean = false): RawByteString;
function UTF8ToISO_8859_15(const s: string; SetTargetCodePage: boolean = false): RawByteString; // Western European languages
function UTF8ToISO_8859_16(const s: string; SetTargetCodePage: boolean = false): RawByteString;
function UTF8ToCP1250(const s: string; SetTargetCodePage: boolean = false): RawByteString; // central europe
function UTF8ToCP1251(const s: string; SetTargetCodePage: boolean = false): RawByteString; // cyrillic
function UTF8ToCP1252(const s: string; SetTargetCodePage: boolean = false): RawByteString; // latin 1
@ -362,6 +365,11 @@ begin
Result:=SingleByteToUTF8(s,ArrayISO_8859_15ToUTF8);
end;
function ISO_8859_16ToUTF8(const s: string): string;
begin
Result:=SingleByteToUTF8(s,ArrayISO_8859_16ToUTF8);
end;
function ISO_8859_2ToUTF8(const s: string): string;
begin
Result:=SingleByteToUTF8(s,ArrayISO_8859_2ToUTF8);
@ -1189,6 +1197,54 @@ begin
end;
end;
function UnicodeToISO_8859_16(Unicode: cardinal): integer;
begin
case Unicode of
0..255: Result:=Unicode;
$104: Result:= $A1;
$105: Result:= $A2;
$141: Result:= $A3;
$20AC: Result:= $A4;
$201E: Result:= $A5;
$160: Result:= $A6;
$161: Result:= $A8;
$218: Result:= $AA;
$179: Result:= $AC;
$17A: Result:= $AE;
$17B: Result:= $AF;
$10C: Result:= $B2;
$142: Result:= $B3;
$17D: Result:= $B4;
$201D: Result:= $B5;
$17E: Result:= $B8;
$10D: Result:= $B9;
$219: Result:= $BA;
$152: Result:= $BC;
$153: Result:= $BD;
$178: Result:= $BE;
$17C: Result:= $BF;
$102: Result:= $C3;
$106: Result:= $C5;
$110: Result:= $D0;
$143: Result:= $D1;
$150: Result:= $D5;
$15A: Result:= $D7;
$170: Result:= $D8;
$118: Result:= $DD;
$21A: Result:= $DE;
$103: Result:= $E3;
$107: Result:= $E5;
$111: Result:= $F0;
$144: Result:= $F1;
$151: Result:= $F5;
$15B: Result:= $F7;
$171: Result:= $F8;
$119: Result:= $FD;
$21B: Result:= $FE;
else Result:=-1;
end;
end;
function UnicodeToISO_8859_2(Unicode: cardinal): integer;
begin
case Unicode of
@ -2054,6 +2110,11 @@ begin
InternalUTF8ToCP(s,28605,SetTargetCodePage,{$IfDef UseSystemCPConv}nil{$else}@UnicodeToISO_8859_15{$endif},Result);
end;
function UTF8ToISO_8859_16(const s: string; SetTargetCodePage: boolean): RawByteString;
begin
InternalUTF8ToCP(s,28606,SetTargetCodePage,{$IfDef UseSystemCPConv}nil{$else}@UnicodeToISO_8859_16{$endif},Result);
end;
function UTF8ToCP1250(const s: string; SetTargetCodePage: boolean): RawByteString;
begin
// system conversion fails for character #129 -> using table
@ -2309,6 +2370,7 @@ begin
List.Add('ISO-8859-9');
List.Add('ISO-8859-14');
List.Add('ISO-8859-15');
List.Add('ISO-8859-16');
List.Add('KOI8-R');
List.Add('KOI8-U');
@ -2461,10 +2523,11 @@ begin
if ATo=EncodingUTF8BOM then begin Result:=UTF8ToUTF8BOM(s); exit; end;
if ATo=EncodingCPIso1 then begin Result:=UTF8ToISO_8859_1(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso14 then begin Result:=UTF8ToISO_8859_14(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso15 then begin Result:=UTF8ToISO_8859_15(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso2 then begin Result:=UTF8ToISO_8859_2(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso9 then begin Result:=UTF8ToISO_8859_9(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso14 then begin Result:=UTF8ToISO_8859_14(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso15 then begin Result:=UTF8ToISO_8859_15(s,SetTargetCodePage); exit; end;
if ATo=EncodingCPIso16 then begin Result:=UTF8ToISO_8859_16(s,SetTargetCodePage); exit; end;
if ATo=EncodingCP1250 then begin Result:=UTF8ToCP1250(s,SetTargetCodePage); exit; end;
if ATo=EncodingCP1251 then begin Result:=UTF8ToCP1251(s,SetTargetCodePage); exit; end;
if ATo=EncodingCP1252 then begin Result:=UTF8ToCP1252(s,SetTargetCodePage); exit; end;
@ -2510,10 +2573,11 @@ begin
if AFrom=EncodingUTF8BOM then begin Result:=UTF8BOMToUTF8(s); exit; end;
if AFrom=EncodingCPIso1 then begin Result:=ISO_8859_1ToUTF8(s); exit; end;
if AFrom=EncodingCPIso14 then begin Result:=ISO_8859_14ToUTF8(s); exit; end;
if AFrom=EncodingCPIso15 then begin Result:=ISO_8859_15ToUTF8(s); exit; end;
if AFrom=EncodingCPIso2 then begin Result:=ISO_8859_2ToUTF8(s); exit; end;
if AFrom=EncodingCPIso9 then begin Result:=ISO_8859_9ToUTF8(s); exit; end;
if AFrom=EncodingCPIso14 then begin Result:=ISO_8859_14ToUTF8(s); exit; end;
if AFrom=EncodingCPIso15 then begin Result:=ISO_8859_15ToUTF8(s); exit; end;
if AFrom=EncodingCPIso16 then begin Result:=ISO_8859_16ToUTF8(s); exit; end;
if AFrom=EncodingCP1250 then begin Result:=CP1250ToUTF8(s); exit; end;
if AFrom=EncodingCP1251 then begin Result:=CP1251ToUTF8(s); exit; end;
if AFrom=EncodingCP1252 then begin Result:=CP1252ToUTF8(s); exit; end;