Sign in Join
Wiki copytemporary

Widestrings: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Widestrings

OldNewLine
1+## Widestring
2+
3+A widestring holds string data but the contents of that string are stored differently depending on operating system and FPC version. Non-Windows:
4+
5+- (FPC 2.2-, 2.4, 2.6): Plain UTF16 (aka Kylix widestring).
6+
7+Windows:
8+
9+- FPC 2.2- plain UTF16 (aka Kylix widestring).
10+- FPC 2.4+ COM compatible UTF16 (UCS2 on Windows 2000) encoded bytes.
11+
12+See [[LCL Unicode Support]]
13+
14+## Old content
15+
16+*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.
17+
18+``` pascal
19+procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
20+var
21+ i : SizeInt;
22+begin
23+ for i:=1 to len do
24+ begin
25+ if word(source^)<128 then
26+ dest^:=char(word(source^))
27+ else
28+ dest^:=' ';
29+ inc(dest);
30+ inc(source);
31+ end;
32+end;
33+
34+procedure Ansi2WideMove(source:pchar;dest:pwidechar;len:SizeInt);
35+var
36+ i : SizeInt;
37+begin
38+ for i:=1 to len do
39+ begin
40+ if byte(source^)<128 then
41+ dest^:=widechar(byte(source^))
42+ else
43+ dest^:=' ';
44+ inc(dest);
45+ inc(source);
46+ end;
47+end;
48+
49+Const
50+ Wide2AnsiMoveProc:TWide2AnsiMove=@Wide2AnsiMove;
51+ Ansi2WideMoveProc:TAnsi2WideMove=@Ansi2WideMove;
52+```
53+
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.
55+
56+## See also
57+
58+- [[Character and string types]]
59+
60+---
61+*From the Free Pascal wiki, page "Widestrings", as it stood on 2020-03-04 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history