Difference between revisions of "Character and string types/fr"
Line 129: | Line 129: | ||
== AnsiString == | == AnsiString == | ||
− | Ansistrings | + | Les Ansistrings ou les UTF8Strings sont des chaînes qui n'ont pas de limite de taille. Le [http://en.wikipedia.org/wiki/Reference_counting comptage de référence] s'applique à elle et il est garanti qu'elles soient à [http://en.wikipedia.org/wiki/Null-terminated_string zéro terminal]. En interne, une variable de type '''AnsiString''' est traitée comme un pointeur: le contenu réel de la chaîne se trouve dans le tas, la mémoire nécessaire à son contenu étant allouée. |
{| class="wikitable" style="text-align:center; width:300px" | {| class="wikitable" style="text-align:center; width:300px" | ||
Line 138: | Line 138: | ||
|} | |} | ||
− | ==== | + | ==== Référence ==== |
− | * [http://www.freepascal.org/docs-html/ref/refsu12.html FPC AnsiString | + | * [http://www.freepascal.org/docs-html/ref/refsu12.html Documentation FPC sur les AnsiString] |
== UnicodeString == | == UnicodeString == |
Revision as of 07:52, 10 July 2014
│
Deutsch (de) │
English (en) │
español (es) │
français (fr) │
русский (ru) │
中文(中国大陆) (zh_CN) │
Free Pascal supportes plusieurs types de caractères et de chaînes. Il s'étendent du simple caractère ANSI aux chaînes Unicode et incluent aussi les types pointer. Les différence s'appliquent aussi aux encodages et au comptage de référence.
AnsiChar
Une variable de type AnsiChar, aussi mentionnée comme char, a une taille d'exactement un octet et contient un caractère ANSI.
a |
Référence
WideChar
Une variable du type WideChar, aussi mentionnée commeUnicodeChar, est exactement d'une taille de 2 octets, et contient une partie des caractères Unicode dans l'encodage UTF-16. Note : il est impossible d'encodes tous les points de code Unicode dans 2 octets. En conséquence, 2 WideChars pourraient être nécessaires pour encoder un simple point de code.
a |
Références
Tableau de Char
Les premières implémentations de Pascal, utilisées avant 1978, ne supportaient pas le type chaîne (exception faite des constantes chaînes). La seule possibilité pour stocker des chaînes dans des variables consistaient à utiliser des tableaux de char. Cette approche a de nombreux inconvénients et n'est plus recommandée. C'est néanmoins toujours supporté pour assurer la compatibilité descendante avec l'ancien code.
Tableau de Char statique
type
TOldString4 = array[0..3] of char;
var
aOldString4: TOldString4;
begin
aOldString4[0] := 'a';
aOldString4[1] := 'b';
aOldString4[2] := 'c';
aOldString4[3] := 'd';
end;
Le tableau de char statique contient dorénavant:
a | b | c | d |
Tableau de Char dynamique
var
aOldString: Array of Char; // pas de dimension!!
begin
SetLength(aOldString, 5);
aOldString[0] := 'a';
aOldString[1] := 'b';
aOldString[2] := 'c';
aOldString[3] := 'd';
end;
Le tableau de char dynamique contient dorénavant:
a | b | c | d | #0 |
PChar
Une variable de type PChar est simplement un pointeur vers un type Char, mais permet des opérations supplémentaires. Les PChars peuvent être utilisé pour accéder à des chaînes C à zéro terminal, par exemple en interaction avec certaines API systèmes ou des logiciels tierce partie.
a | b | c | #0 |
^ |
Référence
PWideChar
Une variable de type PWideChar est un pointeur vers une variable WideChar.
a | b | c | #0 | #0 | |||
^ |
Référence
String
Le type String peut faire référence à ShortString or AnsiString, selon la bascule {$H}. Si la bascule est off ({$H-}) alors toute déclaration string va définir une ShortString. Sa taille sera de 255 caractères, si elle n'est pas spécifiée autrement. Si la bascule est on ({$H+}) string sans spécifier la taille va définir une AnsiString, sinon une ShortString avec une taille spécifiée.
Référence
- Usage des String
- Fonctions sur les chaînes
- Référence sur l'unité 'strutils': Procédures et fonctions
ShortString
Les chaînes courtes ont une taille maximale de 255 caractères avec la page de code CP_ACP implicite. La longueur effective de la chaîne est conservée dans le caractère à l'index 0.
#3 | a | b | c |
Référence
AnsiString
Les Ansistrings ou les UTF8Strings sont des chaînes qui n'ont pas de limite de taille. Le comptage de référence s'applique à elle et il est garanti qu'elles soient à zéro terminal. En interne, une variable de type AnsiString est traitée comme un pointeur: le contenu réel de la chaîne se trouve dans le tas, la mémoire nécessaire à son contenu étant allouée.
a | b | c | #0 | ||||||||
RefCount | Length |
Référence
UnicodeString
Like AnsiStrings, UnicodeStrings are reference counted, null-terminated arrays, but they are implemented as arrays of WideChars instead of regular Chars.
a | b | c | #0 | #0 | |||||||||||
RefCount | Length |
Reference
UTF8String
Currently, the type UTF8String is an alias to the type AnsiString. It is meant to contain UTF8 encoded strings (i.e. unicode data ranging from 1..4 bytes per character). UTF8String is the default string in Lazarus and LCL.
Reference
UTF16String
The type UTF16String is an alias to the type WideString. In the LCL unit lclproc it is an alias to UnicodeString.
Reference
WideString
Variables of type WideString (used to represent unicode character strings in COM applications) resemble those of type UnicodeString, but unlike them they are not reference-counted. On Windows they are allocated with a special windows function which allows them to be used for OLE automation.
WideStrings consist of COM compatible UTF16 encoded bytes on Windows machines (UCS2 on Windows 2000), and they are encoded as plain UTF16 on Linux, Mac OS X and iOS.
a | b | c | #0 | #0 | |||||||
Length |
Reference
PShortString
A variable of type PShortString is a pointer that points to the first byte of a ShortString-type variable (which defines the length of the ShortString).
#3 | a | b | c |
^ |
Reference
PAnsiString
Variables of type PAnsiString are pointers to AnsiString-type variables. However, unlike PShortString-type variables they don't point to the first byte of the header, but to the first char of the AnsiString.
a | b | c | #0 | ||||||||
RefCount | Length | ^ |
Reference
PUnicodeString
Variables of type PUnicodeString are pointers to variables of type UnicodeString.
a | b | c | #0 | #0 | |||||||||||
RefCount | Length | ^ |
Reference
PWideString
Variables of type PWideString are pointers. They point to the first char of a WideString-typed variable.
a | b | c | #0 | #0 | |||||||
Length | ^ |