String type with specified length and without codepage

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

String type with specified length and without codepage

Gabor Boros-2
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: String type with specified length and without codepage

Jonas Maebe-3
On 18/08/2019 11:57, Gabor Boros wrote:
> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: String type with specified length and without codepage

dmitry boyarintsev
In reply to this post by Gabor Boros-2
RawByteString?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: String type with specified length and without codepage

Jonas Maebe-3
On 18/08/2019 15:47, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal