String functions with #

Posted By: Lukas

String functions with # - 10/08/11 18:48

I don't know if you consider the following as a bug or not, but for me it's either that or bad design and definately must be fixed!

"#n" is suppsed to create a string with n spaces. To create just a "#" at the beginning, I am supposed to write "##". That sounds not that bad in theory.

But now try running this code:
Code:
STRING* s1 = str_create("");
	STRING* s2 = str_create("");
	str_cpy(s1,"##"); // s1 is now "#"
	str_cpy(s2,s1); // s2 should be "#" but it's ""!
	error(s1);
	error(s2); // error ignores an emtpy error message
	error("end");


You will first get the "#" error message, the second is skipped because s2 is empty, then you get the "end" message.

When ever a string with a single "#" at the beginning is copied into an other string, it is being interpreted just like a char array that begins with a single "#". That makes it pretty much impossible tp work with strings that begin with a single "#", because you can't copy them!

In LBGUI, this has the effect, that you can't type in a # into an empty editbox. If it isn't empty, but the cursor is at the beginning, it's buggy.

So please change ALL string functions so that only in char arrays, not in STRINGs, "#n" is interpreted as n spaces, because "#n" is really only used inside a script to save space for strings with many spaces.
Posted By: jcl

Re: String functions with # - 10/10/11 07:38

Thanks, we'll look into that. The '#n' makes not much sense anyway in lite-C.
Posted By: FBL

Re: String functions with # - 10/23/11 10:03

I thought str_create(""); creates variable length strings anyway?
I've never used #n and hopefully didn't run into any problems due to pure memory luck...
Posted By: Lukas

Re: String functions with # - 10/23/11 17:02

Well, in Lite-C strings have a variable length, but in C-Script, a string couldn't get longer than its original length. That's why the "#n" is there, so you can create long empty strings you can fill with text. Even in Lite-C, you still need to do that for inkey(). Frankly, I never used the "#n" either, because when I needed a string like this for inkey() I always just put in the spaces directly, because it didn't need to be so long that "#n" would ever be necessary.
© 2024 lite-C Forums