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:
paul 2011-10-03 03:35:45 +00:00
parent c4fcdfce29
commit a0e7196ae9
5 changed files with 24 additions and 22 deletions

2
.gitattributes vendored
View File

@ -7314,6 +7314,7 @@ 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
@ -8129,7 +8130,6 @@ 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

View File

@ -131,3 +131,7 @@ 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;

View File

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

View File

@ -3,7 +3,7 @@
}
type
twin2iconv = record
twin2codepage = record
cp: word;
name: rawbytestring; { for null-termination }
end;
@ -12,7 +12,7 @@
* http://msdn2.microsoft.com/en-us/library/ms776446.aspx
*)
const
win2iconv_arr: array[0..319] of twin2iconv =
win2codepage_arr: array[0..319] of twin2codepage =
((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 win2iconv(cp: word): rawbytestring;
function CodePageToCodePageName(cp: TSystemCodePage): rawbytestring;
var
l, h, i, ccp: longint;
begin
l:=low(win2iconv_arr);
h:=high(win2iconv_arr);
l:=low(win2codepage_arr);
h:=high(win2codepage_arr);
repeat
i:=(l+h+1) shr 1;
ccp:=win2iconv_arr[i].cp;
ccp:=win2codepage_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=win2iconv_arr[i].cp then
if cp=win2codepage_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(win2iconv_arr)) and
(win2iconv_arr[i-1].cp=cp) do
while (i>low(win2codepage_arr)) and
(win2codepage_arr[i-1].cp=cp) do
dec(i);
result:=win2iconv_arr[i].name;
result:=win2codepage_arr[i].name;
end
else
{ or better raise an error? }
@ -386,7 +386,7 @@
end;
function iconv2win(cpname: rawbytestring): word;
function CodePageNameToCodePage(cpname: rawbytestring): TSystemCodePage;
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(win2iconv_arr) to high(win2iconv_arr) do
if win2iconv_arr[i].name=cpname then
for i:=low(win2codepage_arr) to high(win2codepage_arr) do
if win2codepage_arr[i].name=cpname then
begin
result:=win2iconv_arr[i].cp;
result:=win2codepage_arr[i].cp;
exit;
end;
{ rawbytestring (or better raise an error?) }

View File

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