Difference between revisions of "Widestrings"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; deleted category included in page template)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{Widestrings}}
 +
 
== Widestring ==
 
== Widestring ==
 
A widestring holds string data but the contents of that string are stored differently depending on operating system and FPC version.
 
A widestring holds string data but the contents of that string are stored differently depending on operating system and FPC version.
Non-Windows
+
Non-Windows:
(FPC 2.2-, 2.4, 2.6): Plain UTF16 (aka Kylix widestring).
+
* (FPC 2.2-, 2.4, 2.6): Plain UTF16 (aka Kylix widestring).
  
 
Windows:
 
Windows:
FPC 2.2- plain UTF16 (aka Kylix widestring).
+
* FPC 2.2- plain UTF16 (aka Kylix widestring).
FPC 2.4+ contains COM compatible UTF16 (UCS2 on Windows 2000) encoded bytes.
+
* FPC 2.4+ COM compatible UTF16 (UCS2 on Windows 2000) encoded bytes.
  
 
See [[LCL Unicode Support]]
 
See [[LCL Unicode Support]]
Line 14: Line 16:
 
--[[User:BigChimp|BigChimp]] 07:59, 23 June 2012 (UTC)
 
--[[User:BigChimp|BigChimp]] 07:59, 23 June 2012 (UTC)
 
the following code from rtl/inc/wstrings.inc is used for assignments between ansistrings and widestrings.
 
the following code from rtl/inc/wstrings.inc is used for assignments between ansistrings and widestrings.
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
 
procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
 
var
 
var
Line 52: Line 54:
 
the procvars are supposed to allow you to replace theese with a converter more suited to the local charset. Unfortunately they do not allow for the "ansi" charset to be multibyte as they assume the number of ansichars in the ansistring will equal the number of widechars in the widestring.
 
the procvars are supposed to allow you to replace theese with a converter more suited to the local charset. Unfortunately they do not allow for the "ansi" charset to be multibyte as they assume the number of ansichars in the ansistring will equal the number of widechars in the widestring.
  
[[Category:Unicode]]
+
== See also ==
[[Category:FPC]]
+
* [[Character and string types]]

Latest revision as of 10:34, 4 March 2020

English (en) français (fr)

Widestring

A widestring holds string data but the contents of that string are stored differently depending on operating system and FPC version. Non-Windows:

  • (FPC 2.2-, 2.4, 2.6): Plain UTF16 (aka Kylix widestring).

Windows:

  • FPC 2.2- plain UTF16 (aka Kylix widestring).
  • FPC 2.4+ COM compatible UTF16 (UCS2 on Windows 2000) encoded bytes.

See LCL Unicode Support

Old content

Is this still relevant? --BigChimp 07:59, 23 June 2012 (UTC) the following code from rtl/inc/wstrings.inc is used for assignments between ansistrings and widestrings.

procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
var
  i : SizeInt;
begin
  for i:=1 to len do
   begin
     if word(source^)<128 then
      dest^:=char(word(source^))
     else
      dest^:=' ';
     inc(dest);
     inc(source);
   end;
end;


procedure Ansi2WideMove(source:pchar;dest:pwidechar;len:SizeInt);
var
  i : SizeInt;
begin
  for i:=1 to len do
   begin
     if byte(source^)<128 then
      dest^:=widechar(byte(source^))
     else
      dest^:=' ';
     inc(dest);
     inc(source);
   end;
end;

Const
  Wide2AnsiMoveProc:TWide2AnsiMove=@Wide2AnsiMove;
  Ansi2WideMoveProc:TAnsi2WideMove=@Ansi2WideMove;

the procvars are supposed to allow you to replace theese with a converter more suited to the local charset. Unfortunately they do not allow for the "ansi" charset to be multibyte as they assume the number of ansichars in the ansistring will equal the number of widechars in the widestring.

See also