<div dir="ltr"><div>I agree with Filippos and think we should model this after std::string.</div><div><br></div><div>Walter</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Op wo 30 jun. 2021 om 09:46 schreef Filippos Karapetis via scummvm-devel <<a href="mailto:scummvm-devel@lists.scummvm.org">scummvm-devel@lists.scummvm.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">IMHO, we should model Common::String's behavior after std::string.<div><br></div><div>In std::string, it is possible to add a \0 character, and it is not treated as a terminator, plus, these characters count towards the string's length. Check here:</div><div><a href="https://akrzemi1.wordpress.com/2014/03/20/strings-length/" target="_blank">https://akrzemi1.wordpress.com/2014/03/20/strings-length/</a><br></div><div><br></div><div>So, the best course of action would be to go with the third option, because that's what std::string behaves like: \0 should be allowed, and it should be part of the string itself (i.e. it should count towards it length, and it should not terminate it).</div><div><br></div><div>Regards</div><div>Filippos</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 29, 2021 at 3:33 PM Torbjörn Andersson via scummvm-devel <<a href="mailto:scummvm-devel@lists.scummvm.org" target="_blank">scummvm-devel@lists.scummvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
A while back, there was some work done on unifying the String classes. <br>
I'm not familiar with the details of that, but apparently as a <br>
consequence of that some subtle behavior changed. The one In know about <br>
is adding a \0 character to a String, both whether it should be allowed <br>
at all and whether it should be counted as part of the String's length.<br>
<br>
This caused some problems (I know I fixed one in Myst), and a workaround <br>
was added so that adding \0 to a String does nothing. Unfortunately, <br>
there is at least one engine (ADL) that absolutely depends on this <br>
feature, and is now broken. This affects at least Hi-Res Adventures #5 <br>
and #6.<br>
<br>
So the question here (and I really have no opinion myself) is, should it <br>
be possible to store \0 as part of a String, and if so exactly what <br>
should happen? The options I can think of are:<br>
<br>
- Nothing should happen. (This is the current behavior.)<br>
- It should be allowed, but it should terminate the string. (I.e. <br>
strings work like in C.)<br>
- It should be allowed, and it should not terminate the string. (I.e. <br>
strings can contain arbitrary binary data.)<br>
<br>
But maybe there is some other even more sensible behavior?<br>
<br>
Of course, whatever behavior we decide on we need to make sure <br>
everything works with it. At sev's suggestion, I've added a warning() to <br>
base-str.cpp to notify when \0 is added to a String. I have also gone <br>
through every game I've added to ScummVM to see whether or not it <br>
triggers the warning just by starting it and walking around for a bit.<br>
<br>
The results of my test can be found in <br>
<a href="http://www.update.uu.se/~d91tan/tmp/string.txt" rel="noreferrer" target="_blank">http://www.update.uu.se/~d91tan/tmp/string.txt</a><br>
<br>
Note that some of the games I started are not even supported, and that <br>
there are some game engines where I don't own a single game. My list is <br>
far from exhaustive.<br>
<br>
Torbjörn Andersson<br>
_______________________________________________<br>
scummvm-devel mailing list<br>
<a href="mailto:scummvm-devel@lists.scummvm.org" target="_blank">scummvm-devel@lists.scummvm.org</a><br>
<a href="https://lists.scummvm.org/listinfo/scummvm-devel" rel="noreferrer" target="_blank">https://lists.scummvm.org/listinfo/scummvm-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr">"Experience is the name every one gives to their mistakes" - Oscar Wilde </div>
_______________________________________________<br>
scummvm-devel mailing list<br>
<a href="mailto:scummvm-devel@lists.scummvm.org" target="_blank">scummvm-devel@lists.scummvm.org</a><br>
<a href="https://lists.scummvm.org/listinfo/scummvm-devel" rel="noreferrer" target="_blank">https://lists.scummvm.org/listinfo/scummvm-devel</a><br>
</blockquote></div>