mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 04:39:10 +02:00
rtl: revert r19330. We probably need to create a separate encoding<->codepage table.
git-svn-id: trunk@19332 -
This commit is contained in:
parent
24d489f7f7
commit
6384fa2a19
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -7314,7 +7314,6 @@ rtl/inc/varianth.inc svneol=native#text/plain
|
||||
rtl/inc/variants.pp svneol=native#text/plain
|
||||
rtl/inc/video.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/wstrings.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/varutils.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/watcom/Makefile svneol=native#text/plain
|
||||
rtl/watcom/Makefile.fpc svneol=native#text/plain
|
||||
|
@ -131,7 +131,3 @@ Procedure SetUnicodeStringManager (Const New : TUnicodeStringManager; Var Old: T
|
||||
function StringElementSize(const S : UnicodeString): Word; overload;
|
||||
function StringRefCount(const S : UnicodeString): SizeInt; overload;
|
||||
function StringCodePage(const S : UnicodeString): TSystemCodePage; overload;
|
||||
|
||||
// codepage to codepage name conversion functions
|
||||
function CodePageToCodePageName(cp: TSystemCodePage): rawbytestring;
|
||||
function CodePageNameToCodePage(cpname: rawbytestring): TSystemCodePage;
|
@ -15,7 +15,6 @@
|
||||
**********************************************************************}
|
||||
|
||||
{$i wustrings.inc}
|
||||
{$i wincodepages.inc}
|
||||
|
||||
{
|
||||
This file contains the implementation of the UnicodeString type,
|
||||
|
@ -167,6 +167,9 @@ threadvar
|
||||
current_DefaultSystemCodePage: TSystemCodePage;
|
||||
|
||||
|
||||
function win2iconv(cp: word): rawbytestring; forward;
|
||||
|
||||
|
||||
procedure InitThread;
|
||||
{$if not(defined(darwin) and defined(arm))}
|
||||
var
|
||||
@ -175,7 +178,7 @@ var
|
||||
begin
|
||||
current_DefaultSystemCodePage:=DefaultSystemCodePage;
|
||||
{$if not(defined(darwin) and defined(arm))}
|
||||
iconvname:=CodePageToCodePageName(DefaultSystemCodePage);
|
||||
iconvname:=win2iconv(DefaultSystemCodePage);
|
||||
iconv_wide2ansi:=iconv_open(pchar(iconvname),unicode_encoding2);
|
||||
iconv_ansi2wide:=iconv_open(unicode_encoding2,pchar(iconvname));
|
||||
{$else}
|
||||
@ -248,7 +251,7 @@ procedure Wide2AnsiMove(source:pwidechar; var dest:RawByteString; cp:TSystemCode
|
||||
-- typecasting an ansistring function result to pchar is
|
||||
unsafe normally, but these are constant strings -> no
|
||||
problem }
|
||||
use_iconv:=iconv_open(pchar(CodePageToCodePageName(cp)),unicode_encoding2);
|
||||
use_iconv:=iconv_open(pchar(win2iconv(cp)),unicode_encoding2);
|
||||
free_iconv:=true;
|
||||
end;
|
||||
{ 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
|
||||
unsafe normally, but these are constant strings -> no
|
||||
problem }
|
||||
use_iconv:=iconv_open(unicode_encoding2,pchar(CodePageToCodePageName(cp)));
|
||||
use_iconv:=iconv_open(unicode_encoding2,pchar(win2iconv(cp)));
|
||||
free_iconv:=true;
|
||||
end;
|
||||
{ unsupported encoding -> default move }
|
||||
@ -886,7 +889,7 @@ initialization
|
||||
setlocale(LC_ALL,'');
|
||||
|
||||
{ set the DefaultSystemCodePage }
|
||||
DefaultSystemCodePage:=CodePageNameToCodePage(ansistring(nl_langinfo(CODESET)));
|
||||
DefaultSystemCodePage:=iconv2win(ansistring(nl_langinfo(CODESET)));
|
||||
|
||||
{ init conversion tables for main program }
|
||||
InitThread;
|
||||
|
@ -3,7 +3,7 @@
|
||||
}
|
||||
|
||||
type
|
||||
twin2codepage = record
|
||||
twin2iconv = record
|
||||
cp: word;
|
||||
name: rawbytestring; { for null-termination }
|
||||
end;
|
||||
@ -12,7 +12,7 @@
|
||||
* http://msdn2.microsoft.com/en-us/library/ms776446.aspx
|
||||
*)
|
||||
const
|
||||
win2codepage_arr: array[0..319] of twin2codepage =
|
||||
win2iconv_arr: array[0..319] of twin2iconv =
|
||||
((cp:37; name:'IBM037'), (* IBM EBCDIC US-Canada *)
|
||||
(cp:154; name:'CP154'),
|
||||
(cp:154; name:'CYRILLIC-ASIAN'),
|
||||
@ -353,15 +353,15 @@
|
||||
(cp:65001; name:'UTF8'));
|
||||
|
||||
|
||||
function CodePageToCodePageName(cp: TSystemCodePage): rawbytestring;
|
||||
function win2iconv(cp: word): rawbytestring;
|
||||
var
|
||||
l, h, i, ccp: longint;
|
||||
begin
|
||||
l:=low(win2codepage_arr);
|
||||
h:=high(win2codepage_arr);
|
||||
l:=low(win2iconv_arr);
|
||||
h:=high(win2iconv_arr);
|
||||
repeat
|
||||
i:=(l+h+1) shr 1;
|
||||
ccp:=win2codepage_arr[i].cp;
|
||||
ccp:=win2iconv_arr[i].cp;
|
||||
if cp=ccp then
|
||||
break;
|
||||
if cp>=ccp then
|
||||
@ -369,16 +369,16 @@
|
||||
else
|
||||
h:=i-1;
|
||||
until l>=h;
|
||||
if cp=win2codepage_arr[i].cp then
|
||||
if cp=win2iconv_arr[i].cp then
|
||||
begin
|
||||
{ the array has been ordered so that in case multiple alias names
|
||||
exist, the first entry for the cp is the most commonly supported
|
||||
one
|
||||
}
|
||||
while (i>low(win2codepage_arr)) and
|
||||
(win2codepage_arr[i-1].cp=cp) do
|
||||
while (i>low(win2iconv_arr)) and
|
||||
(win2iconv_arr[i-1].cp=cp) do
|
||||
dec(i);
|
||||
result:=win2codepage_arr[i].name;
|
||||
result:=win2iconv_arr[i].name;
|
||||
end
|
||||
else
|
||||
{ or better raise an error? }
|
||||
@ -386,7 +386,7 @@
|
||||
end;
|
||||
|
||||
|
||||
function CodePageNameToCodePage(cpname: rawbytestring): TSystemCodePage;
|
||||
function iconv2win(cpname: rawbytestring): word;
|
||||
var
|
||||
i: longint;
|
||||
begin
|
||||
@ -396,10 +396,10 @@
|
||||
|
||||
{ simple linear scan, not a common operation and hence not worth
|
||||
building a separate array for }
|
||||
for i:=low(win2codepage_arr) to high(win2codepage_arr) do
|
||||
if win2codepage_arr[i].name=cpname then
|
||||
for i:=low(win2iconv_arr) to high(win2iconv_arr) do
|
||||
if win2iconv_arr[i].name=cpname then
|
||||
begin
|
||||
result:=win2codepage_arr[i].cp;
|
||||
result:=win2iconv_arr[i].cp;
|
||||
exit;
|
||||
end;
|
||||
{ rawbytestring (or better raise an error?) }
|
Loading…
Reference in New Issue
Block a user