mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 09:09:25 +02:00
rtl: move winiconv.inc into general inc directory and rename it to wincodepages.inc, also rename win2iconv, iconv2win to CodePageToCodePageName, CodePageNameToCodePage.
This change is required since CodePage to CodePage name conversions are required in other parts of RTL. Moreover those codepage identifiers are windows codepage identifiers and thus must be compatible with codepage identifiers used by delphi. git-svn-id: trunk@19330 -
This commit is contained in:
parent
c4fcdfce29
commit
a0e7196ae9
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -7314,6 +7314,7 @@ 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
|
||||||
@ -8129,7 +8130,6 @@ 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
|
||||||
|
@ -131,3 +131,7 @@ 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;
|
@ -15,6 +15,7 @@
|
|||||||
**********************************************************************}
|
**********************************************************************}
|
||||||
|
|
||||||
{$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,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
type
|
type
|
||||||
twin2iconv = record
|
twin2codepage = 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
|
||||||
win2iconv_arr: array[0..319] of twin2iconv =
|
win2codepage_arr: array[0..319] of twin2codepage =
|
||||||
((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 win2iconv(cp: word): rawbytestring;
|
function CodePageToCodePageName(cp: TSystemCodePage): rawbytestring;
|
||||||
var
|
var
|
||||||
l, h, i, ccp: longint;
|
l, h, i, ccp: longint;
|
||||||
begin
|
begin
|
||||||
l:=low(win2iconv_arr);
|
l:=low(win2codepage_arr);
|
||||||
h:=high(win2iconv_arr);
|
h:=high(win2codepage_arr);
|
||||||
repeat
|
repeat
|
||||||
i:=(l+h+1) shr 1;
|
i:=(l+h+1) shr 1;
|
||||||
ccp:=win2iconv_arr[i].cp;
|
ccp:=win2codepage_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=win2iconv_arr[i].cp then
|
if cp=win2codepage_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(win2iconv_arr)) and
|
while (i>low(win2codepage_arr)) and
|
||||||
(win2iconv_arr[i-1].cp=cp) do
|
(win2codepage_arr[i-1].cp=cp) do
|
||||||
dec(i);
|
dec(i);
|
||||||
result:=win2iconv_arr[i].name;
|
result:=win2codepage_arr[i].name;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{ or better raise an error? }
|
{ or better raise an error? }
|
||||||
@ -386,7 +386,7 @@
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function iconv2win(cpname: rawbytestring): word;
|
function CodePageNameToCodePage(cpname: rawbytestring): TSystemCodePage;
|
||||||
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(win2iconv_arr) to high(win2iconv_arr) do
|
for i:=low(win2codepage_arr) to high(win2codepage_arr) do
|
||||||
if win2iconv_arr[i].name=cpname then
|
if win2codepage_arr[i].name=cpname then
|
||||||
begin
|
begin
|
||||||
result:=win2iconv_arr[i].cp;
|
result:=win2codepage_arr[i].cp;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{ rawbytestring (or better raise an error?) }
|
{ rawbytestring (or better raise an error?) }
|
@ -167,9 +167,6 @@ 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
|
||||||
@ -178,7 +175,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:=win2iconv(DefaultSystemCodePage);
|
iconvname:=CodePageToCodePageName(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}
|
||||||
@ -251,7 +248,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(win2iconv(cp)),unicode_encoding2);
|
use_iconv:=iconv_open(pchar(CodePageToCodePageName(cp)),unicode_encoding2);
|
||||||
free_iconv:=true;
|
free_iconv:=true;
|
||||||
end;
|
end;
|
||||||
{ unsupported encoding -> default move }
|
{ unsupported encoding -> default move }
|
||||||
@ -344,7 +341,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(win2iconv(cp)));
|
use_iconv:=iconv_open(unicode_encoding2,pchar(CodePageToCodePageName(cp)));
|
||||||
free_iconv:=true;
|
free_iconv:=true;
|
||||||
end;
|
end;
|
||||||
{ unsupported encoding -> default move }
|
{ unsupported encoding -> default move }
|
||||||
@ -889,7 +886,7 @@ initialization
|
|||||||
setlocale(LC_ALL,'');
|
setlocale(LC_ALL,'');
|
||||||
|
|
||||||
{ set the DefaultSystemCodePage }
|
{ set the DefaultSystemCodePage }
|
||||||
DefaultSystemCodePage:=iconv2win(ansistring(nl_langinfo(CODESET)));
|
DefaultSystemCodePage:=CodePageNameToCodePage(ansistring(nl_langinfo(CODESET)));
|
||||||
|
|
||||||
{ init conversion tables for main program }
|
{ init conversion tables for main program }
|
||||||
InitThread;
|
InitThread;
|
||||||
|
Loading…
Reference in New Issue
Block a user