rtl: revert r19330. We probably need to create a separate encoding<->codepage table.

git-svn-id: trunk@19332 -
This commit is contained in:
paul 2011-10-03 10:28:14 +00:00
parent 24d489f7f7
commit 6384fa2a19
5 changed files with 22 additions and 24 deletions

2
.gitattributes vendored
View File

@ -7314,7 +7314,6 @@ rtl/inc/varianth.inc svneol=native#text/plain
rtl/inc/variants.pp svneol=native#text/plain rtl/inc/variants.pp svneol=native#text/plain
rtl/inc/video.inc svneol=native#text/plain rtl/inc/video.inc svneol=native#text/plain
rtl/inc/videoh.inc svneol=native#text/plain rtl/inc/videoh.inc svneol=native#text/plain
rtl/inc/wincodepages.inc svneol=native#text/plain
rtl/inc/wstringh.inc svneol=native#text/plain rtl/inc/wstringh.inc svneol=native#text/plain
rtl/inc/wstrings.inc svneol=native#text/plain rtl/inc/wstrings.inc svneol=native#text/plain
rtl/inc/wustrings.inc svneol=native#text/plain rtl/inc/wustrings.inc svneol=native#text/plain
@ -8130,6 +8129,7 @@ rtl/unix/unxovl.inc svneol=native#text/plain
rtl/unix/unxovlh.inc svneol=native#text/plain rtl/unix/unxovlh.inc svneol=native#text/plain
rtl/unix/varutils.pp svneol=native#text/plain rtl/unix/varutils.pp svneol=native#text/plain
rtl/unix/video.pp svneol=native#text/plain rtl/unix/video.pp svneol=native#text/plain
rtl/unix/winiconv.inc svneol=native#text/plain
rtl/unix/x86.pp svneol=native#text/plain rtl/unix/x86.pp svneol=native#text/plain
rtl/watcom/Makefile svneol=native#text/plain rtl/watcom/Makefile svneol=native#text/plain
rtl/watcom/Makefile.fpc svneol=native#text/plain rtl/watcom/Makefile.fpc svneol=native#text/plain

View File

@ -131,7 +131,3 @@ Procedure SetUnicodeStringManager (Const New : TUnicodeStringManager; Var Old: T
function StringElementSize(const S : UnicodeString): Word; overload; function StringElementSize(const S : UnicodeString): Word; overload;
function StringRefCount(const S : UnicodeString): SizeInt; overload; function StringRefCount(const S : UnicodeString): SizeInt; overload;
function StringCodePage(const S : UnicodeString): TSystemCodePage; overload; function StringCodePage(const S : UnicodeString): TSystemCodePage; overload;
// codepage to codepage name conversion functions
function CodePageToCodePageName(cp: TSystemCodePage): rawbytestring;
function CodePageNameToCodePage(cpname: rawbytestring): TSystemCodePage;

View File

@ -15,7 +15,6 @@
**********************************************************************} **********************************************************************}
{$i wustrings.inc} {$i wustrings.inc}
{$i wincodepages.inc}
{ {
This file contains the implementation of the UnicodeString type, This file contains the implementation of the UnicodeString type,

View File

@ -167,6 +167,9 @@ threadvar
current_DefaultSystemCodePage: TSystemCodePage; current_DefaultSystemCodePage: TSystemCodePage;
function win2iconv(cp: word): rawbytestring; forward;
procedure InitThread; procedure InitThread;
{$if not(defined(darwin) and defined(arm))} {$if not(defined(darwin) and defined(arm))}
var var
@ -175,7 +178,7 @@ var
begin begin
current_DefaultSystemCodePage:=DefaultSystemCodePage; current_DefaultSystemCodePage:=DefaultSystemCodePage;
{$if not(defined(darwin) and defined(arm))} {$if not(defined(darwin) and defined(arm))}
iconvname:=CodePageToCodePageName(DefaultSystemCodePage); iconvname:=win2iconv(DefaultSystemCodePage);
iconv_wide2ansi:=iconv_open(pchar(iconvname),unicode_encoding2); iconv_wide2ansi:=iconv_open(pchar(iconvname),unicode_encoding2);
iconv_ansi2wide:=iconv_open(unicode_encoding2,pchar(iconvname)); iconv_ansi2wide:=iconv_open(unicode_encoding2,pchar(iconvname));
{$else} {$else}
@ -248,7 +251,7 @@ procedure Wide2AnsiMove(source:pwidechar; var dest:RawByteString; cp:TSystemCode
-- typecasting an ansistring function result to pchar is -- typecasting an ansistring function result to pchar is
unsafe normally, but these are constant strings -> no unsafe normally, but these are constant strings -> no
problem } problem }
use_iconv:=iconv_open(pchar(CodePageToCodePageName(cp)),unicode_encoding2); use_iconv:=iconv_open(pchar(win2iconv(cp)),unicode_encoding2);
free_iconv:=true; free_iconv:=true;
end; end;
{ unsupported encoding -> default move } { unsupported encoding -> default move }
@ -341,7 +344,7 @@ procedure Ansi2WideMove(source:pchar; cp:TSystemCodePage; var dest:widestring; l
-- typecasting an ansistring function result to pchar is -- typecasting an ansistring function result to pchar is
unsafe normally, but these are constant strings -> no unsafe normally, but these are constant strings -> no
problem } problem }
use_iconv:=iconv_open(unicode_encoding2,pchar(CodePageToCodePageName(cp))); use_iconv:=iconv_open(unicode_encoding2,pchar(win2iconv(cp)));
free_iconv:=true; free_iconv:=true;
end; end;
{ unsupported encoding -> default move } { unsupported encoding -> default move }
@ -886,7 +889,7 @@ initialization
setlocale(LC_ALL,''); setlocale(LC_ALL,'');
{ set the DefaultSystemCodePage } { set the DefaultSystemCodePage }
DefaultSystemCodePage:=CodePageNameToCodePage(ansistring(nl_langinfo(CODESET))); DefaultSystemCodePage:=iconv2win(ansistring(nl_langinfo(CODESET)));
{ init conversion tables for main program } { init conversion tables for main program }
InitThread; InitThread;

View File

@ -3,7 +3,7 @@
} }
type type
twin2codepage = record twin2iconv = record
cp: word; cp: word;
name: rawbytestring; { for null-termination } name: rawbytestring; { for null-termination }
end; end;
@ -12,7 +12,7 @@
* http://msdn2.microsoft.com/en-us/library/ms776446.aspx * http://msdn2.microsoft.com/en-us/library/ms776446.aspx
*) *)
const const
win2codepage_arr: array[0..319] of twin2codepage = win2iconv_arr: array[0..319] of twin2iconv =
((cp:37; name:'IBM037'), (* IBM EBCDIC US-Canada *) ((cp:37; name:'IBM037'), (* IBM EBCDIC US-Canada *)
(cp:154; name:'CP154'), (cp:154; name:'CP154'),
(cp:154; name:'CYRILLIC-ASIAN'), (cp:154; name:'CYRILLIC-ASIAN'),
@ -353,15 +353,15 @@
(cp:65001; name:'UTF8')); (cp:65001; name:'UTF8'));
function CodePageToCodePageName(cp: TSystemCodePage): rawbytestring; function win2iconv(cp: word): rawbytestring;
var var
l, h, i, ccp: longint; l, h, i, ccp: longint;
begin begin
l:=low(win2codepage_arr); l:=low(win2iconv_arr);
h:=high(win2codepage_arr); h:=high(win2iconv_arr);
repeat repeat
i:=(l+h+1) shr 1; i:=(l+h+1) shr 1;
ccp:=win2codepage_arr[i].cp; ccp:=win2iconv_arr[i].cp;
if cp=ccp then if cp=ccp then
break; break;
if cp>=ccp then if cp>=ccp then
@ -369,16 +369,16 @@
else else
h:=i-1; h:=i-1;
until l>=h; until l>=h;
if cp=win2codepage_arr[i].cp then if cp=win2iconv_arr[i].cp then
begin begin
{ the array has been ordered so that in case multiple alias names { the array has been ordered so that in case multiple alias names
exist, the first entry for the cp is the most commonly supported exist, the first entry for the cp is the most commonly supported
one one
} }
while (i>low(win2codepage_arr)) and while (i>low(win2iconv_arr)) and
(win2codepage_arr[i-1].cp=cp) do (win2iconv_arr[i-1].cp=cp) do
dec(i); dec(i);
result:=win2codepage_arr[i].name; result:=win2iconv_arr[i].name;
end end
else else
{ or better raise an error? } { or better raise an error? }
@ -386,7 +386,7 @@
end; end;
function CodePageNameToCodePage(cpname: rawbytestring): TSystemCodePage; function iconv2win(cpname: rawbytestring): word;
var var
i: longint; i: longint;
begin begin
@ -396,10 +396,10 @@
{ simple linear scan, not a common operation and hence not worth { simple linear scan, not a common operation and hence not worth
building a separate array for } building a separate array for }
for i:=low(win2codepage_arr) to high(win2codepage_arr) do for i:=low(win2iconv_arr) to high(win2iconv_arr) do
if win2codepage_arr[i].name=cpname then if win2iconv_arr[i].name=cpname then
begin begin
result:=win2codepage_arr[i].cp; result:=win2iconv_arr[i].cp;
exit; exit;
end; end;
{ rawbytestring (or better raise an error?) } { rawbytestring (or better raise an error?) }