Autore Topic: Non è possibile lo Split() nei confronti del byte ASCII NUL  (Letto 393 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Riporto questo messaggio apparso nella M.L.I.:


" the Split() function seems to have problems splitting against the ASCII NUL
(aka "\0") byte. In the attached project, there are four test cases from
whose results I assume that Split() stops working on the separator when it
encounters a NUL just if it was a C string. Look especially at the last
test.

I currently work around this issue by using the "tr" program.

Regards,
Tobi
"


" This will always occur in any language, as a string is terminated by the
null character internally.

Jim Provan
"


" Bzzzt! Wrong. In Gambas a string is a structure containing a pointer and a
length so that the data can contain as much NUL as you want. Look at
http://gambasdoc.org/help/lang/type/string?v3
and especially at
http://sourceforge.net/mailarchive/message.php?msg_id=29289747
where I was told the same thing.

Split() may be one of the functions mentioned there which by design (not by
bug) do not support "\0" but in my imagination - without knowing the code -
it should be as easy as using memmem() instead of strstr() to find a Gambas
string (Separator) in another Gambas string (Text) and to split accordingly.

Regards,
Tobi
"


" Not in real Basic languages. Basic traditionally does NOT use a Null terminator
for String types.

Tom
"


" I stand corrected. Thank you.

Jim Provan
"
« Ultima modifica: 05 Agosto 2013, 23:40:52 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »