Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-08

String type with specified length and without codepage

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi All,

I try to rewrite some C/C++ code with FPC. I don't know which is the best string handling technique in this case. The original code for example:

char  b_l[b_list_len][bn_len+1];
char  s_n[sn_len+1];

I do not want to fight with "char"s or "byte"s. Just want to use the easier way which have the best performance. (The original code use strncpy.) I can use "s_n:String[sn_len]", but "String" is ShortString and it's have CP_ACP codepage if I understand the wiki correctly. So I need a string type with explicit defined length and with CP_NONE codepage for a Linux/Windows multi platform application. Any idea?

Gabor

Reply by email

Jonas Maebe
to Gabor Boros
Gabor Boros wrote 6 lines
I do not want to fight with "char"s or "byte"s. Just want to use the easier way which have the best performance. (The original code use strncpy.) I can use "s_n:String[sn_len]", but "String" is ShortString and it's have CP_ACP codepage if I understand the wiki correctly. So I need a string type with explicit defined length and with CP_NONE codepage for a Linux/Windows multi platform application. Any idea?

That does not exist/is not supported. All strings have an associated code page, because strings are data + interpretation of that data, rather than just data. If you only want data, you have to use an array instead (or a custom record with overloaded operators that uses an array of char internally).

Jonas

Reply by email

Jonas Maebe
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote
RawByteString?

RawByteString still has a dynamic code page. Additionally, operations on RawByteString are not very well defined by Embarcadero. In general, it should only be used as a function result or parameter type, and never as a variable on which you perform operations.

Again: strings are data + metadata, arrays are just data. Do not use strings for raw data.

Jonas

Reply by email