[Lazarus] Feature Request: Insert {codepage UTF8} per default

Michael W. Vogel m-w-vogel at gmx.de
Tue Mar 29 22:44:56 CEST 2016


Hi,

I'm thinking about the thread here 
http://forum.lazarus.freepascal.org/index.php/topic,31939.msg206688.html#msg206688 
where Bart wrote "... and adding explicit codepage identifiers to 
sourcecode that has string constants with characters that er not ASCII 
(or ad -FcUTF8 to your default compiler options to achieve the same) ..."

I think he is right.

Since Lazarus makes per default the switch to UTF-8 encoded strings, it 
would be good to hint the developer, that they use such encoded strings.

In the most cases the string magic works without a defined {$codepage 
utf8}, but not if you want to assign a const to a Predefined String or 
Unicodestring.

I add a project that demonstrate, that the assigning of strings with 
{$codepage utf8} works better than without it.

I would prefer to set {$codepage utf8} per default, if a new 
unit/project is created. I like it more than the general switch -FcUTF8, 
cause each developer see the current codepage and you can use units with 
other codepages too (what in reality probably nobody would do).

I add a possible patch, how I think, it could be.


Offtopic: In the added project: Why is a const 'abc' with {$codepage 
UTF8} a Unicodestring (Windows7, 64bit, Lazarus 1.7 r52077M FPC 3.1.1 
i386-win32-win32/win64 on FPC 3.1.1 r33371)?


Regards

Michl

-------------- next part --------------
Index: components/codetools/h2pastool.pas
===================================================================
--- components/codetools/h2pastool.pas	(revision 52077)
+++ components/codetools/h2pastool.pas	(working copy)
@@ -2370,6 +2370,7 @@
     W('unit '+SourceName+';');
     W('');
     W('{$mode objfpc}{$H+}');
+    W('{$codepage UTF8}');
     W('');
     W('interface');
     W('');
Index: components/fpcunit/ide/fpcunitlazideintf.pas
===================================================================
--- components/fpcunit/ide/fpcunitlazideintf.pas	(revision 52077)
+++ components/fpcunit/ide/fpcunitlazideintf.pas	(working copy)
@@ -155,6 +155,7 @@
   NewSource:='program FPCUnitProject1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'uses'+le
     +'  Interfaces, Forms, GuiTestRunner;'+le
@@ -224,6 +225,7 @@
      'unit '+SourceName+';'+LE
     +LE
     +'{$mode objfpc}{$H+}'+LE
+    +'{$codepage UTF8}'+LE
     +LE
     +'interface'+LE
     +LE
Index: components/fpcunit/ide/fpcunitproject1.inc
===================================================================
--- components/fpcunit/ide/fpcunitproject1.inc	(revision 52077)
+++ components/fpcunit/ide/fpcunitproject1.inc	(working copy)
@@ -2,6 +2,7 @@
     'program FPCUnitProject1;' + sLineBreak
   + sLineBreak
   + '{$mode objfpc}{$H+}' + sLineBreak
+  + '{$codepage UTF8}' + sLineBreak
   + sLineBreak
   + 'uses' + sLineBreak
   + '  Classes, consoletestrunner;' + sLineBreak
Index: components/fpweb/weblazideintf.pp
===================================================================
--- components/fpweb/weblazideintf.pp	(revision 52077)
+++ components/fpweb/weblazideintf.pp	(working copy)
@@ -386,6 +386,7 @@
   NewSource:='program cgiproject1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'uses'+le
     +'  fpCGI;'+le
@@ -452,6 +453,7 @@
   NewSource:='program cgiproject1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'uses'+le
     +'  Classes, SysUtils, httpDefs, fpweb,'
@@ -615,6 +617,7 @@
   NewSource:='Library mod_apache1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'Uses'+le
     +'{$ifdef unix}'+le
@@ -707,6 +710,7 @@
   NewSource:='program fcgiproject1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'uses'+le
     +'  Classes,SysUtils,httpDefs,custfcgi;'+le
@@ -790,6 +794,7 @@
   NewSource:='program fcgiproject1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'uses'+le
     +'  fpFCGI;'+le
@@ -888,6 +893,7 @@
   NewSource:='program httpproject1;'+le
     +le
     +'{$mode objfpc}{$H+}'+le
+    +'{$codepage UTF8}'+le
     +le
     +'uses'+le;
   if FReg then
Index: components/ideintf/projectintf.pas
===================================================================
--- components/ideintf/projectintf.pas	(revision 52077)
+++ components/ideintf/projectintf.pas	(working copy)
@@ -948,7 +948,8 @@
 
 function TFileDescPascalUnit.GetUnitDirectives: string;
 begin
-  Result:='{$mode objfpc}{$H+}';
+  Result:='{$mode objfpc}{$H+}'+LineEnding
+    +'{$codepage utf8}';
   if Owner is TLazProject then
     Result:=CompilerOptionsToUnitDirectives(Owner.LazCompilerOptions);
 end;
@@ -985,7 +986,7 @@
 var
   SyntaxMode: String;
 begin
-  Result:='{$mode objfpc}{$H+}';
+  Result:='{$mode objfpc}{$H+}'+LineEnding+'{$codepage UTF8}';
   if CompOpts=nil then exit;
   SyntaxMode:=CompOpts.SyntaxMode;
   if SyntaxMode<>'' then begin
@@ -992,7 +993,7 @@
     Result:='{$mode '+lowercase(SyntaxMode)+'}';
     if CompOpts.UseAnsiStrings
     and (SysUtils.CompareText(SyntaxMode,'Delphi')<>0) then
-      Result:=Result+'{$H+}';
+      Result:=Result+'{$H+}'+LineEnding+'{$codepage UTF8}';
   end;
 end;
 
Index: components/instantfpc/instantfpcregisterlaz.pas
===================================================================
--- components/instantfpc/instantfpcregisterlaz.pas	(revision 52077)
+++ components/instantfpc/instantfpcregisterlaz.pas	(working copy)
@@ -97,6 +97,7 @@
   NewSource:=TStringList.Create;
   NewSource.Add('#!/usr/bin/env instantfpc');
   NewSource.Add('{$mode objfpc}{$H+}');
+  NewSource.Add('{$codepage UTF8}');
   NewSource.Add('uses');
   NewSource.Add('  Classes, SysUtils;');
   NewSource.Add('');
@@ -144,6 +145,7 @@
 begin
   Result:='#!/usr/bin/instantfpc'+LineEnding
     +'{$mode objfpc}{$H+}'+LineEnding
+    +'{$codepage UTF8}'+LineEnding
     +LineEnding
     +'uses Classes, SysUtils;'+LineEnding
     +LineEnding
Index: components/synedit/test/testmarkupifdef.pas
===================================================================
--- components/synedit/test/testmarkupifdef.pas	(revision 52077)
+++ components/synedit/test/testmarkupifdef.pas	(working copy)
@@ -772,6 +772,7 @@
   AddLine('program project1;');
   AddLine('');
   AddLine('{$mode objfpc}{$H+}');
+  AddLine('{$codepage UTF8}');
   AddLine('');
   // 5
   AddLine('uses {$IFDEF UNIX} {$IFDEF UseCThreads}');
Index: examples/synedit1.pas
===================================================================
--- examples/synedit1.pas	(revision 52077)
+++ examples/synedit1.pas	(working copy)
@@ -58,6 +58,7 @@
     'program synedit1;'+e+
     ''+e+
     '{$mode objfpc}{$H+}'+e+
+    '{$codepage UTF8}'+e+
     ''+e+
     'uses'+e+
     '  Interfaces, Classes, SysUtils, Forms, Controls, GraphType, Graphics, SynEdit,'+e+
Index: ide/projectdefs.pas
===================================================================
--- ide/projectdefs.pas	(revision 52077)
+++ ide/projectdefs.pas	(working copy)
@@ -1279,6 +1279,7 @@
   NewSource:='program Project1;'+LineEnding
     +LineEnding
     +'{$mode objfpc}{$H+}'+LineEnding
+    +'{$codepage UTF8}'+LineEnding
     +LineEnding
     +'uses'+LineEnding
     +'  {$IFDEF UNIX}{$IFDEF UseCThreads}'+LineEnding
@@ -1396,6 +1397,7 @@
   NewSource:='program Project1;'+LineEnding
     +LineEnding
     +'{$mode objfpc}{$H+}'+LineEnding
+    +'{$codepage UTF8}'+LineEnding
     +LineEnding
     +'uses'+LineEnding
     +'  {$IFDEF UNIX}{$IFDEF UseCThreads}'+LineEnding
@@ -1461,6 +1463,7 @@
     NewSource:='program Project1;'+LineEnding
       +LineEnding
       +'{$mode objfpc}{$H+}'+LineEnding
+      +'{$codepage UTF8}'+LineEnding
       +LineEnding
       +'uses'+LineEnding
       +'  Classes, SysUtils'+LineEnding
@@ -1553,6 +1556,7 @@
   NewSource.Add('program Project1;');
   NewSource.Add('');
   NewSource.Add('{$mode objfpc}{$H+}');
+  NewSource.Add('{$codepage UTF8}');
   NewSource.Add('');
   NewSource.Add('uses');
   NewSource.Add('  {$IFDEF UNIX}{$IFDEF UseCThreads}');
@@ -1699,6 +1703,7 @@
   NewSource:='library Project1;'+LineEnding
     +LineEnding
     +'{$mode objfpc}{$H+}'+LineEnding
+    +'{$codepage UTF8}'+LineEnding
     +LineEnding
     +'uses'+LineEnding
     +'  Classes'+LineEnding
Index: packager/oldcustomcompdlg.pas
===================================================================
--- packager/oldcustomcompdlg.pas	(revision 52077)
+++ packager/oldcustomcompdlg.pas	(working copy)
@@ -348,6 +348,7 @@
     Add('unit CustomIDEComps;');
     Add('');
     Add('{$mode objfpc}{$H+}');
+    Add('{$codepage UTF8}');
     Add('');
     Add('interface');
     Add('');
Index: packager/pkgmanager.pas
===================================================================
--- packager/pkgmanager.pas	(revision 52077)
+++ packager/pkgmanager.pas	(working copy)
@@ -787,7 +787,7 @@
   if (System.Pos(Params.UsedUnitname,UsesLine)<1)
   and (Params.UsedUnitname<>'') then
     UsesLine:=UsesLine+', '+Params.UsedUnitname;
-  UnitDirectives:='{$mode objfpc}{$H+}';
+  UnitDirectives:='{$mode objfpc}{$H+}'+LE+'{$codepage UTF8}';
   if Params.Pkg<>nil then
     UnitDirectives:=TFileDescPascalUnit.CompilerOptionsToUnitDirectives(
                                                     Params.Pkg.CompilerOptions);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StringAssignTest.zip
Type: application/x-zip-compressed
Size: 7364 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160329/a5941647/attachment-0003.bin>


More information about the Lazarus mailing list