Difference between revisions of "Widestrings"

From Free Pascal wiki
 
Line 1: Line 1:
 
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.
 
+
<pre>
 
procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
 
procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
 
var
 
var
Line 35: Line 35:
 
   Wide2AnsiMoveProc:TWide2AnsiMove=@Wide2AnsiMove;
 
   Wide2AnsiMoveProc:TWide2AnsiMove=@Wide2AnsiMove;
 
   Ansi2WideMoveProc:TAnsi2WideMove=@Ansi2WideMove;
 
   Ansi2WideMoveProc:TAnsi2WideMove=@Ansi2WideMove;
 
+
</pre>
 
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.

Revision as of 22:32, 5 January 2005

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.