Skip to content

Instantly share code, notes, and snippets.

@ayardley
Created May 24, 2012 18:38
Show Gist options
  • Save ayardley/2783372 to your computer and use it in GitHub Desktop.
Save ayardley/2783372 to your computer and use it in GitHub Desktop.
Problem with ResizableStringArray in Winxed
NotFound,
I have been looking at different ways to detect the end of a string. For some reason, I don't understand why, the 'ResizableStringArray' below terminates prematurely. That is, the below does not work:
function main[main] ()
{
string regexp = "";
string text = "Thisisastring.";
var regex = split('', regexp);
regex_loop: {
if (regex[0] == "")
goto regex_end;
else {
say(regex);
regex.shift();
}
goto regex_loop;
}
regex_end: say('regex end!');
//
var tx = split('', text);
int i = 0;
tx_loop: {
if (tx[i] == "") {
goto tx_end;
}
else {
say(tx);
tx.shift();
}
i++;
goto tx_loop;
}
tx_end:
say("i = ", i);
say('tx end!');
}
It prints the following:
regex end!
[ "T", "h", "i", "s", "i", "s", "a", "s", "t", "r", "i", "n", "g", "." ]
[ "h", "i", "s", "i", "s", "a", "s", "t", "r", "i", "n", "g", "." ]
[ "i", "s", "i", "s", "a", "s", "t", "r", "i", "n", "g", "." ]
[ "s", "i", "s", "a", "s", "t", "r", "i", "n", "g", "." ]
[ "i", "s", "a", "s", "t", "r", "i", "n", "g", "." ]
[ "s", "a", "s", "t", "r", "i", "n", "g", "." ]
[ "a", "s", "t", "r", "i", "n", "g", "." ]
i = 7
tx end!
But, of course, the below, more typical usage, *does* work:
function main[main] ()
{
string regexp = "";
string text = "Thisisastring.";
var regex = regexp;
int i = 0;
regex_loop: {
if (regex[i] == "")
goto regex_end;
else {
say(regex[i]);
}
i++;
goto regex_loop;
}
regex_end: say('regex end!');
//
var tx = text;
int j = 0;
tx_loop: {
if (tx[j] == "") {
goto tx_end;
}
else {
say(tx[j]);
}
j++;
goto tx_loop;
}
tx_end:
say('tx end!');
}
It prints out the following:
regex end!
T
h
i
s
i
s
a
s
t
r
i
n
g
.
tx end!
Is this a bug or am I just missing something.
Thank you.
Alvis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment