From ba95497e04b073eea31f0c62dbaf6a57425d13b4 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 14 Dec 2007 13:34:44 +0000 Subject: [PATCH] Added initial utf-8 widestring manager activated by -dUseUTF8WString git-svn-id: trunk@13329 - --- .gitattributes | 1 + lcl/alllclunits.pp | 3 ++- lcl/interfacebase.pp | 3 +++ lcl/utf8wstring.pas | 62 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 lcl/utf8wstring.pas diff --git a/.gitattributes b/.gitattributes index c391a32c3a..18bc0117d5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3272,6 +3272,7 @@ lcl/themes.pas svneol=native#text/pascal lcl/tmschema.pas svneol=native#text/pascal lcl/toolwin.pp svneol=native#text/pascal lcl/translations.pas svneol=native#text/pascal +lcl/utf8wstring.pas -text lcl/utrace.pp svneol=native#text/pascal lcl/widgetset/README.txt svneol=native#text/plain lcl/widgetset/wsactnlist.pp svneol=native#text/pascal diff --git a/lcl/alllclunits.pp b/lcl/alllclunits.pp index af2e62c4fe..91459a2996 100644 --- a/lcl/alllclunits.pp +++ b/lcl/alllclunits.pp @@ -63,7 +63,8 @@ uses WSToolwin, WSProc, WSDesigner, - DefaultTranslator; + // Other units + DefaultTranslator, utf8wstring; implementation diff --git a/lcl/interfacebase.pp b/lcl/interfacebase.pp index 4451f851ea..bb876166d3 100644 --- a/lcl/interfacebase.pp +++ b/lcl/interfacebase.pp @@ -33,6 +33,9 @@ interface {$endif} uses +{$ifdef UseUTF8WString} + utf8wstring, +{$endif} Types, Classes, SysUtils, Math, LCLStrConsts, LCLType, LCLProc, LMessages, GraphType, GraphMath, Themes; diff --git a/lcl/utf8wstring.pas b/lcl/utf8wstring.pas new file mode 100644 index 0000000000..8a39a8c715 --- /dev/null +++ b/lcl/utf8wstring.pas @@ -0,0 +1,62 @@ +{ + /*************************************************************************** + utf8wstring.pas + ----------- + UTF-8 Widestring manager + + + ***************************************************************************/ + + ***************************************************************************** + * * + * This file is part of the Lazarus Component Library (LCL) * + * * + * See the file COPYING.modifiedLGPL, included in this distribution, * + * for details about the copyright. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * * + ***************************************************************************** + + Ensures that we have a reliable encoding for ansistrings (UTF-8 Encoding), + until a new type for utf-8 strings is created. +} +unit utf8wstring; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils; + +procedure UTF8Wide2AnsiMove(source:pwidechar;var dest:ansistring;len:SizeInt); +procedure UTF8Ansi2WideMove(source:pchar;var dest:widestring;len:SizeInt); + +implementation + +procedure UTF8Wide2AnsiMove(source: pwidechar; var dest: ansistring; len: SizeInt); +var + Buffer: WideString; +begin + Buffer := Copy(source, 1, len); + dest := UTF8Encode(Buffer); +end; + +procedure UTF8Ansi2WideMove(source: pchar; var dest: widestring; len: SizeInt); +var + Buffer: ansistring; +begin + Buffer := Copy(source, 1, len); + dest := UTF8Decode(Buffer); +end; + +initialization + + Widestringmanager.Wide2AnsiMoveProc := @UTF8Wide2AnsiMove; + Widestringmanager.Ansi2WideMoveProc := @UTF8Ansi2WideMove; + +end. +