LazUtils: Support for iso8859_15 character encoding. Issue #23856, patch from DCelso

git-svn-id: trunk@40210 -
This commit is contained in:
juha 2013-02-08 21:11:04 +00:00
parent 938dfb12e9
commit bee75f597a

View File

@ -57,6 +57,7 @@ var
function UTF8BOMToUTF8(const s: string): string; // UTF8 with BOM
function ISO_8859_1ToUTF8(const s: string): string; // central europe
function ISO_8859_15ToUTF8(const s: string): string; // Western European languages
function ISO_8859_2ToUTF8(const s: string): string; // eastern europe
function CP1250ToUTF8(const s: string): string; // central europe
function CP1251ToUTF8(const s: string): string; // cyrillic
@ -80,6 +81,7 @@ function UCS2BEToUTF8(const s: string): string; // UCS2-BE 2byte big endian
function UTF8ToUTF8BOM(const s: string): string; // UTF8 with BOM
function UTF8ToISO_8859_1(const s: string): string; // central europe
function UTF8ToISO_8859_15(const s: string): string; // Western European languages
function UTF8ToISO_8859_2(const s: string): string; // eastern europe
function UTF8ToCP1250(const s: string): string; // central europe
function UTF8ToCP1251(const s: string): string; // cyrillic
@ -483,6 +485,264 @@ const
#195#191 // #255
);
ArrayISO_8859_15ToUTF8: 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
#194#161, // #161
#194#162, // #162
#194#163, // #163
#226#130#172, // #164
#194#165, // #165
#197#160, // #166
#194#167, // #167
#197#161, // #168
#194#169, // #169
#194#170, // #170
#194#171, // #171
#194#172, // #172
#194#173, // #173
#194#174, // #174
#194#175, // #175
#194#176, // #176
#194#177, // #177
#194#178, // #178
#194#179, // #179
#197#189, // #180
#194#181, // #181
#194#182, // #182
#194#183, // #183
#197#190, // #184
#194#185, // #185
#194#186, // #186
#194#187, // #187
#197#146, // #188
#197#147, // #189
#197#187, // #190
#194#191, // #191
#195#128, // #192
#195#129, // #193
#195#130, // #194
#195#131, // #195
#195#132, // #196
#195#133, // #197
#195#134, // #198
#195#135, // #199
#195#136, // #200
#195#137, // #201
#195#138, // #202
#195#139, // #203
#195#140, // #204
#195#141, // #205
#195#142, // #206
#195#143, // #207
#195#144, // #208
#195#145, // #209
#195#146, // #210
#195#147, // #211
#195#148, // #212
#195#149, // #213
#195#150, // #214
#195#151, // #215
#195#152, // #216
#195#153, // #217
#195#154, // #218
#195#155, // #219
#195#156, // #220
#195#157, // #221
#195#158, // #222
#195#159, // #223
#195#160, // #224
#195#161, // #225
#195#162, // #226
#195#163, // #227
#195#164, // #228
#195#165, // #229
#195#166, // #230
#195#167, // #231
#195#168, // #232
#195#169, // #233
#195#170, // #234
#195#171, // #235
#195#172, // #236
#195#173, // #237
#195#174, // #238
#195#175, // #239
#195#176, // #240
#195#177, // #241
#195#178, // #242
#195#179, // #243
#195#180, // #244
#195#181, // #245
#195#182, // #246
#195#183, // #247
#195#184, // #248
#195#185, // #249
#195#186, // #250
#195#187, // #251
#195#188, // #252
#195#189, // #253
#195#190, // #254
#195#191 // #255
);
ArrayISO_8859_2ToUTF8: TCharToUTF8Table = (
#0, // #0
#1, // #1
@ -4639,6 +4899,11 @@ begin
Result:=SingleByteToUTF8(s,ArrayISO_8859_1ToUTF8);
end;
function ISO_8859_15ToUTF8(const s: string): string;
begin
Result:=SingleByteToUTF8(s,ArrayISO_8859_15ToUTF8);
end;
function ISO_8859_2ToUTF8(const s: string): string;
begin
Result:=SingleByteToUTF8(s,ArrayISO_8859_2ToUTF8);
@ -5881,6 +6146,14 @@ begin
end;
end;
function UnicodeToISO_8859_15(Unicode: cardinal): integer;
begin
case Unicode of
0..255: Result:=Unicode;
else Result:=-1;
end;
end;
function UnicodeToISO_8859_2(Unicode: cardinal): integer;
begin
case Unicode of
@ -5984,6 +6257,11 @@ begin
Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_1);
end;
function UTF8ToISO_8859_15(const s: string): string;
begin
Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_15);
end;
function UTF8ToISO_8859_2(const s: string): string;
begin
Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_2);
@ -6373,6 +6651,7 @@ begin
if (AFrom=EncodingUTF8) then begin
if ATo=EncodingUTF8BOM then begin Result:=UTF8ToUTF8BOM(s); exit; end;
if ATo='iso88591' then begin Result:=UTF8ToISO_8859_1(s); exit; end;
if ATo='iso885915' then begin Result:=UTF8ToISO_8859_15(s); exit; end;
if ATo='iso88592' then begin Result:=UTF8ToISO_8859_2(s); exit; end;
if ATo='cp1250' then begin Result:=UTF8ToCP1250(s); exit; end;
if ATo='cp1251' then begin Result:=UTF8ToCP1251(s); exit; end;
@ -6405,6 +6684,7 @@ begin
end else if ATo=EncodingUTF8 then begin
if AFrom=EncodingUTF8BOM then begin Result:=UTF8BOMToUTF8(s); exit; end;
if AFrom='iso88591' then begin Result:=ISO_8859_1ToUTF8(s); exit; end;
if AFrom='iso885915' then begin Result:=ISO_8859_15ToUTF8(s); exit; end;
if AFrom='iso88592' then begin Result:=ISO_8859_2ToUTF8(s); exit; end;
if AFrom='cp1250' then begin Result:=CP1250ToUTF8(s); exit; end;
if AFrom='cp1251' then begin Result:=CP1251ToUTF8(s); exit; end;
@ -6445,6 +6725,10 @@ begin
Result:=ISO_8859_1ToUTF8(s);
Encoded := true;
end
else if AFrom='iso885915' then begin
Result:=ISO_8859_15ToUTF8(s);
Encoded := true;
end
else if AFrom='iso88592' then begin
Result:=ISO_8859_2ToUTF8(s);
Encoded := true;
@ -6547,6 +6831,10 @@ begin
Result:=UTF8ToISO_8859_1(Result);
Encoded := true;
end
else if ATo='iso885915' then begin
Result:=UTF8ToISO_8859_15(Result);
Encoded := true;
end
else if ATo='iso88592' then begin
Result:=UTF8ToISO_8859_2(Result);
Encoded := true;