After a short discussion about this with Jeremy, I had another thought and
maybe this is a good solution?
var str = "test [[ my [[funny]]]][[ tag ]] test";
var leftoff= 0;
var read = "";
var result= [];
var sep= /(\[\[|\s+|\]\]|$)/mg;
var match;
var inside= false;
SCAN: while(match = sep.exec(str)) {
console.log("Inside: " + inside);
console.log("Pos: " + str.substring(0, leftoff) + ">" +
str.substring(leftoff, sep.lastIndex) + "<" + str.substring(sep.lastIndex));
console.log("Match: " + match[1]);
console.log("Old: " + leftoff);
console.log("Index: " + sep.lastIndex);
console.log("Read: >" + read+"<");
switch (match[1]) {
case "[[":
if (inside) {
read+= match[1];
} else {
inside = true;
read+= str.substring(leftoff, sep.lastIndex - match[1].length);
}
break;
case "]]":
if (inside) {
inside = false;
read+= str.substring(leftoff, sep.lastIndex - match[1].length);
} else {
read+= match[1];
}
break;
case "":
read+= str.substring(leftoff);
result.push(read);
read = "";
break SCAN;
default:
if (inside) {
read+= str.substring(leftoff, sep.lastIndex);
} else {
read+= str.substring(leftoff, sep.lastIndex - match[1].length);
result.push(read);
read = "";
}
break;
}
leftoff = sep.lastIndex;
console.log("Read: >" + read+"<");
console.log("----------------");
}
result;
I think, the applied logic fits to all our current stringified tags, but
has a little twist to it, which will allow for [[ and ]] to be inside tags!
Stringification of tags or array elements works like this:
elt="my [[funny]] tag";
if (elt.search(/\[\[|\s/) > -1) {
elt=elt.replace(/(\s[^\]]*)/g, "[[$1]]");
}
elt
The most significant difference: Elements, containing spaces are no longer
completely surrounded by [[ and ]], but just from where it's required. So
the above elt gives:
"my[[ [[funny]]]][[ tag]]"
The little twist I use is: A sequence, surrounded by [[ and ]] is treated
as a single unit which is not considered to be whitespace.
If we treat it like this, Elements in such a string are now just seperated
by whitespace. So "test[[ x ]]test" is not the representation of ["test", "
x ", "test"] but ["test x test"]. I have to admit that the stringify regexp
given above will not produce "test[[ x ]]test" but "test[[ x test]]", but
it will work in either case.
I think with this little enhancement we would get a huge benefit, as we
should now be able, to represent any array as a string without dropping the
current compatibility.
I also think it wouldn't cost too much, as the regular expression used in
destringifying is far less complex than before. It's just a bit more
javascript code around it.
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/groups/opt_out.