diff --git a/.gitattributes b/.gitattributes
index ea7e83d640..1c122aca41 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -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
diff --git a/lcl/include/asiancodepagefunctions.inc b/components/lazutils/asiancodepagefunctions.inc
similarity index 100%
rename from lcl/include/asiancodepagefunctions.inc
rename to components/lazutils/asiancodepagefunctions.inc
diff --git a/lcl/include/asiancodepages.inc b/components/lazutils/asiancodepages.inc
similarity index 100%
rename from lcl/include/asiancodepages.inc
rename to components/lazutils/asiancodepages.inc
diff --git a/components/lazutils/lazutf8.pas b/components/lazutils/lazutf8.pas
index 037395e375..262dd1a4e3 100644
--- a/components/lazutils/lazutf8.pas
+++ b/components/lazutils/lazutf8.pas
@@ -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
diff --git a/components/lazutils/lazutils.lpk b/components/lazutils/lazutils.lpk
index cbf0723f02..4f4f1df1c5 100644
--- a/components/lazutils/lazutils.lpk
+++ b/components/lazutils/lazutils.lpk
@@ -25,7 +25,7 @@
-
+
@@ -121,8 +121,20 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/lazutils/lazutils.pas b/components/lazutils/lazutils.pas
index 994470b1ac..b86d352eb7 100644
--- a/components/lazutils/lazutils.pas
+++ b/components/lazutils/lazutils.pas
@@ -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
diff --git a/lcl/lconvencoding.pas b/components/lazutils/lconvencoding.pas
similarity index 99%
rename from lcl/lconvencoding.pas
rename to components/lazutils/lconvencoding.pas
index e969fcd215..1645aac858 100644
--- a/lcl/lconvencoding.pas
+++ b/components/lazutils/lconvencoding.pas
@@ -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;
diff --git a/components/lazutils/paswstring.pas b/components/lazutils/paswstring.pas
index 8483b95d5d..3f3302fd8f 100644
--- a/components/lazutils/paswstring.pas
+++ b/components/lazutils/paswstring.pas
@@ -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;
diff --git a/lcl/alllclunits.pp b/lcl/alllclunits.pp
index afef84a15a..a9a4ebf20c 100644
--- a/lcl/alllclunits.pp
+++ b/lcl/alllclunits.pp
@@ -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
diff --git a/lcl/lclbase.lpk b/lcl/lclbase.lpk
index a2abac3e9e..2f7eab14c1 100644
--- a/lcl/lclbase.lpk
+++ b/lcl/lclbase.lpk
@@ -37,7 +37,7 @@
-
+
@@ -275,927 +275,915 @@
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+