Moves lconvencoding.pas from the LCL to LazUtils

git-svn-id: trunk@32942 -
This commit is contained in:
sekelsenmat 2011-10-17 11:36:24 +00:00
parent c58e039a73
commit 3ffd9d2af9
10 changed files with 415 additions and 341 deletions

6
.gitattributes vendored
View File

@ -1695,6 +1695,8 @@ components/lazthread/threadoptionsdialog.pas svneol=native#text/plain
components/lazutils/Makefile svneol=native#text/plain
components/lazutils/Makefile.compiled svneol=native#text/plain
components/lazutils/Makefile.fpc svneol=native#text/plain
components/lazutils/asiancodepagefunctions.inc svneol=native#text/pascal
components/lazutils/asiancodepages.inc svneol=native#text/pascal
components/lazutils/fileutil.inc svneol=native#text/pascal
components/lazutils/fileutil.pas svneol=native#text/pascal
components/lazutils/languages/luresstrings.po svneol=native#text/plain
@ -1719,6 +1721,7 @@ components/lazutils/lazutf8classes.pas svneol=native#text/pascal
components/lazutils/lazutils.lpk svneol=native#text/plain
components/lazutils/lazutils.pas svneol=native#text/plain
components/lazutils/lazutilsstrconsts.pas svneol=native#text/pascal
components/lazutils/lconvencoding.pas svneol=native#text/pascal
components/lazutils/luresstrings.pas svneol=native#text/plain
components/lazutils/masks.pas svneol=native#text/pascal
components/lazutils/paswstring.pas svneol=native#text/plain
@ -4992,8 +4995,6 @@ lcl/imglist.pp svneol=native#text/pascal
lcl/include/actionlink.inc svneol=native#text/pascal
lcl/include/application.inc svneol=native#text/pascal
lcl/include/applicationproperties.inc svneol=native#text/pascal
lcl/include/asiancodepagefunctions.inc svneol=native#text/plain
lcl/include/asiancodepages.inc svneol=native#text/plain
lcl/include/bevel.inc svneol=native#text/pascal
lcl/include/bitbtn.inc svneol=native#text/pascal
lcl/include/bitmap.inc svneol=native#text/pascal
@ -5687,7 +5688,6 @@ lcl/lclstrconsts.pas svneol=native#text/pascal
lcl/lcltype.pp svneol=native#text/pascal
lcl/lclunicodedata.pas svneol=native#text/pascal
lcl/lclversion.pas svneol=native#text/pascal
lcl/lconvencoding.pas svneol=native#text/pascal
lcl/ldockctrl.pas svneol=native#text/pascal
lcl/ldockctrledit.lfm svneol=native#text/plain
lcl/ldockctrledit.pas svneol=native#text/pascal

View File

@ -46,8 +46,8 @@ function UTF8Length(p: PChar; ByteCount: PtrInt): PtrInt;
function UTF8CharacterToUnicode(p: PChar; out CharLen: integer): Cardinal;
function UnicodeToUTF8(u: cardinal; Buf: PChar): integer; inline;
function UnicodeToUTF8SkipErrors(u: cardinal; Buf: PChar): integer;
{function UnicodeToUTF8(u: cardinal): shortstring; inline;
function UTF8ToDoubleByteString(const s: string): string;
function UnicodeToUTF8(u: cardinal): shortstring; inline;
{function UTF8ToDoubleByteString(const s: string): string;
function UTF8ToDoubleByte(UTF8Str: PChar; Len: PtrInt; DBStr: PByte): PtrInt;
function UTF8FindNearestCharStart(UTF8Str: PChar; Len: integer;
BytePos: integer): integer;
@ -55,9 +55,9 @@ function UTF8FindNearestCharStart(UTF8Str: PChar; Len: integer;
function UTF8CharStart(UTF8Str: PChar; Len, CharIndex: PtrInt): PChar;
// find the byte index of the n-th UTF8 character, ignoring BIDI (byte len of substr)
function UTF8CharToByteIndex(UTF8Str: PChar; Len, CharIndex: PtrInt): PtrInt;
procedure UTF8FixBroken(P: PChar);
procedure UTF8FixBroken(P: PChar);}
function UTF8CharacterStrictLength(P: PChar): integer;
function UTF8CStringToUTF8String(SourceStart: PChar; SourceLen: PtrInt) : string;
{function UTF8CStringToUTF8String(SourceStart: PChar; SourceLen: PtrInt) : string;
function UTF8Pos(const SearchForText, SearchInText: string): PtrInt;
function UTF8Copy(const s: string; StartCharIndex, CharCount: PtrInt): string;
procedure UTF8Delete(var s: String; StartCharIndex, CharCount: PtrInt);
@ -1045,6 +1045,49 @@ begin
end;
end;
function UnicodeToUTF8(u: cardinal): shortstring;
begin
Result[0]:=chr(UnicodeToUTF8(u,@Result[1]));
end;
function UTF8CharacterStrictLength(P: PChar): integer;
begin
if p=nil then exit(0);
if ord(p^)<%10000000 then begin
// regular single byte character
exit(1);
end
else if ord(p^)<%11000000 then begin
// invalid single byte character
exit(0);
end
else if ((ord(p^) and %11100000) = %11000000) then begin
// should be 2 byte character
if (ord(p[1]) and %11000000) = %10000000 then
exit(2)
else
exit(0);
end
else if ((ord(p^) and %11110000) = %11100000) then begin
// should be 3 byte character
if ((ord(p[1]) and %11000000) = %10000000)
and ((ord(p[2]) and %11000000) = %10000000) then
exit(3)
else
exit(0);
end
else if ((ord(p^) and %11111000) = %11110000) then begin
// should be 4 byte character
if ((ord(p[1]) and %11000000) = %10000000)
and ((ord(p[2]) and %11000000) = %10000000)
and ((ord(p[3]) and %11000000) = %10000000) then
exit(4)
else
exit(0);
end else
exit(0);
end;
{$ifdef LAZUTF8_USE_TABLES}
function UnicodeLowercase(u: cardinal): cardinal;
begin

View File

@ -25,7 +25,7 @@
<Description Value="Useful units for Lazarus packages."/>
<License Value="Modified LGPL-2"/>
<Version Major="1"/>
<Files Count="24">
<Files Count="27">
<Item1>
<Filename Value="laz2_dom.pas"/>
<UnitName Value="laz2_DOM"/>
@ -121,8 +121,20 @@
</Item23>
<Item24>
<Filename Value="lazutilsstrconsts.pas"/>
<UnitName Value="LCLStrConsts"/>
<UnitName Value="LazUtilsStrConsts"/>
</Item24>
<Item25>
<Filename Value="lconvencoding.pas"/>
<UnitName Value="LConvEncoding"/>
</Item25>
<Item26>
<Filename Value="asiancodepages.inc"/>
<Type Value="Include"/>
</Item26>
<Item27>
<Filename Value="asiancodepagefunctions.inc"/>
<Type Value="Include"/>
</Item27>
</Files>
<LazDoc Paths="docs"/>
<i18n>

View File

@ -10,7 +10,7 @@ uses
laz2_DOM, Laz2_XMLCfg, laz2_XMLRead, laz2_xmlutils, laz2_XMLWrite, Laz_DOM,
Laz_XMLCfg, Laz_XMLRead, Laz_XMLStreaming, Laz_XMLWrite, LazFileUtils,
LazFileCache, LUResStrings, LazUTF8, LazDbgLog, FileUtil, lazutf8classes,
Masks, LazUtilsStrConsts, LazarusPackageIntf;
Masks, LazUtilsStrConsts, LConvEncoding, LazarusPackageIntf;
implementation

View File

@ -15,16 +15,17 @@
unit LConvEncoding;
{$mode objfpc}{$H+}
{$include include/lcl_defines.inc}
interface
{$DEFINE DisableIconv}
{$IFNDEF DisableIconv}
{$IFDEF UNIX}{$IF not defined(VER2_2_0) and not defined(VER2_2_2)}{$DEFINE HasIconvEnc}{$ENDIF}{$ENDIF}
{$ENDIF}
uses
SysUtils, Classes, dos, LCLProc
SysUtils, Classes, dos, LazUTF8
{$IFDEF HasIconvEnc},iconvenc{$ENDIF};
const
EncodingUTF8 = 'utf8';
@ -127,8 +128,8 @@ uses Windows;
var EncodingValid: boolean = false;
DefaultTextEncoding: string = EncodingAnsi;
{$include include/asiancodepages.inc}
{$include include/asiancodepagefunctions.inc}
{$include asiancodepages.inc}
{$include asiancodepagefunctions.inc}
{$IFDEF Windows}
function GetWindowsEncoding: string;
@ -4766,7 +4767,7 @@ begin
end;
len:=PtrUInt(Dest)-PtrUInt(Result);
if len>length(Result) then
RaiseGDBException('');
raise Exception.Create('');
SetLength(Result,len);
end;
@ -4798,7 +4799,7 @@ begin
end;
len:=PtrUInt(Dest)-PtrUInt(Result);
if len>length(Result) then
RaiseGDBException('');
raise Exception.Create('');
SetLength(Result,len);
end;
@ -6121,7 +6122,7 @@ begin
end;
len:=PtrUInt(Dest)-PtrUInt(Result);
if len>length(Result) then
RaiseGDBException('');
raise Exception.Create('');
SetLength(Result,len);
end;
@ -6161,7 +6162,7 @@ begin
end;
len:=PtrUInt(Dest)-PtrUInt(Result);
if len>length(Result) then
RaiseGDBException('');
raise Exception.Create('');
SetLength(Result,len);
end;

View File

@ -19,7 +19,7 @@ unit paswstring;
interface
uses SysUtils, lazutf8;
uses SysUtils, lazutf8, lconvencoding;
procedure SetPasWidestringManager;
@ -53,6 +53,19 @@ begin
dest := UTF8ToUTF16(ansistr);
end;
procedure Ansi2UnicodeMove(source:pchar;var dest:UnicodeString;len:SizeInt);
var
ansistr: ansistring;
begin
// Copy the originating string taking into account the specified length
SetLength(ansistr, len+1);
System.Move(source^, ansistr, len);
ansistr[len+1] := #0;
// Now convert it, using UTF-16 -> UTF-8
dest := UTF8ToUTF16(ansistr);
end;
function LowerWideString(const s : WideString) : WideString;
var
str: utf8string;
@ -71,6 +84,23 @@ begin
Result := UTF8ToUTF16(str);
end;
function LowerUnicodeString(const s : UnicodeString) : UnicodeString;
var
str: utf8string;
begin
str := UTF16ToUTF8(s);
str := UTF8LowerCase(str);
Result := UTF8ToUTF16(str);
end;
function UpperUnicodeString(const s : UnicodeString) : UnicodeString;
var
str: utf8string;
begin
str := UTF16ToUTF8(s);
str := UTF8UpperCase(str);
Result := UTF8ToUTF16(str);
end;
procedure EnsureAnsiLen(var S: AnsiString; const len: SizeInt); inline;
begin
@ -289,9 +319,9 @@ begin
{ Unicode }
PasWideStringManager.Unicode2AnsiMoveProc:=@Wide2AnsiMove;
PasWideStringManager.Ansi2UnicodeMoveProc:=@Ansi2WideMove;
PasWideStringManager.UpperUnicodeStringProc:=@UpperWideString;
PasWideStringManager.LowerUnicodeStringProc:=@LowerWideString;
PasWideStringManager.Ansi2UnicodeMoveProc:=@Ansi2UnicodeMove;
PasWideStringManager.UpperUnicodeStringProc:=@UpperUnicodeString;
PasWideStringManager.LowerUnicodeStringProc:=@LowerUnicodeString;
SetUnicodeStringManager(PasWideStringManager);
end;

View File

@ -15,17 +15,17 @@ uses
IniPropStorage, InterfaceBase, IntfGraphics, LazConfigStorage, LazHelpHTML,
LazHelpIntf, LazLinkedList, LCLClasses, LCLIntf, LCLMemManager,
LCLMessageGlue, LCLProc, LCLResCache, LCLStrConsts, LCLType, Menus,
LCLUnicodeData, LCLVersion, LConvEncoding, LDockCtrl, LDockCtrlEdit,
LDockTree, LMessages, LResources, maps, MaskEdit, PairSplitter,
PopupNotifier, PostScriptCanvas, PostScriptPrinter, postscriptunicode,
Printers, PropertyStorage, RubberBand, ShellCtrls, Spin, StdActns, StdCtrls,
StringHashList, TextStrings, Themes, TmSchema, Toolwin, Translations,
UTF8Process, UTrace, XMLPropStorage, Messages, WSArrow, WSButtons,
WSCalendar, WSCheckLst, WSComCtrls, WSControls, WSDesigner, WSDialogs,
WSExtCtrls, WSExtDlgs, WSFactory, WSForms, WSGrids, WSImgList, WSLCLClasses,
WSMenus, WSPairSplitter, WSProc, WSReferences, WSSpin, WSStdCtrls,
WSToolwin, ActnList, Arrow, AsyncProcess, AvgLvlTree, ButtonPanel, Buttons,
Calendar, RegisterLCL, ValEdit, LazarusPackageIntf;
LCLUnicodeData, LCLVersion, LDockCtrl, LDockCtrlEdit, LDockTree, LMessages,
LResources, maps, MaskEdit, PairSplitter, PopupNotifier, PostScriptCanvas,
PostScriptPrinter, postscriptunicode, Printers, PropertyStorage, RubberBand,
ShellCtrls, Spin, StdActns, StdCtrls, StringHashList, TextStrings, Themes,
TmSchema, Toolwin, Translations, UTF8Process, UTrace, XMLPropStorage,
Messages, WSArrow, WSButtons, WSCalendar, WSCheckLst, WSComCtrls,
WSControls, WSDesigner, WSDialogs, WSExtCtrls, WSExtDlgs, WSFactory,
WSForms, WSGrids, WSImgList, WSLCLClasses, WSMenus, WSPairSplitter, WSProc,
WSReferences, WSSpin, WSStdCtrls, WSToolwin, ActnList, Arrow, AsyncProcess,
AvgLvlTree, ButtonPanel, Buttons, Calendar, RegisterLCL, ValEdit,
LazarusPackageIntf;
implementation

File diff suppressed because it is too large Load Diff