[fpc-pascal] Generic String Functions

Marco van de Voort marcov at stack.nl
Fri Feb 28 15:09:23 CET 2014


In our previous episode, Michael Schnell said:
> > Moreover, will operations that use character access make sense at all 
> > if you don't know what the actual encoding is? 
> The administrative record of each "New Delphi string" contains the 
> encoding type and the byte-count for each code. So "you" (the compiler 
> and the RTL) do know it.

Yes, but the point is that the programmer that writes the index into the
delete() might not oversee all cases. (codepaths that can bring a string to
the current point).

Keeping in mind that these functions generally work at the encoding
granularity level. So something that works with unicode (utf16) will fail
with ansi (utf8) if it contains values that utf8 can't encode in one byte.
 
>   - If using any statically encoded type for same, it is close to 
> impossible to create decently fast programs for string manipulation 
> (unless they by chance use the correct encoding type), as 
> auto-conversion to and fro is invisibly introduced.

Well, the trick is not to leave that to chance. 




More information about the fpc-pascal mailing list