Minor tidy up of Tiddler.unescapeLineBreaks and Tiddler.prototype.escapeLineBreaks

1 view
Skip to first unread message

Martin Budden

unread,
May 31, 2006, 2:12:36 PM5/31/06
to TiddlyWikiDev
Both these functions would benefit in terms of readability, size and
performance by changing their RegExp strings into regular expression
literals. (Unlike in the matchers there is no strong case for retaining
the RegExp string form.)

// Static method to Convert "\n" to newlines, "\s" to "\", CR to ""
Tiddler.unescapeLineBreaks = function(text)
{
if(text && text != "")
return
text.replace(/\\n/mg,"\n").replace(/\\s/mg,"\\").replace(/\r/mg,"");
else
return "";
}

// Convert newlines to "\n", "\" to "\s", CR to ""
Tiddler.prototype.escapeLineBreaks = function()
{
return
this.text.replace(/\n/mg,"\\n").replace(/\\/mg,"\\s").replace(/\r/mg,"");
}

Martin

Jeremy Ruston

unread,
Jun 8, 2006, 8:34:02 AM6/8/06
to Tiddly...@googlegroups.com
OK, I've created a ticket for the more general issue:

http://trac.tiddlywiki.org/tiddlywiki/ticket/55

I'd like to switch them all over together. I'm worried that it's going
to be fiddly and error prone for the more complex regular expressions
though - it would be nice to be able to automatically convert them...
hmmm a TextMate macro would be nice.

Cheers

Jeremy


--
Jeremy Ruston
mailto:jer...@osmosoft.com
http://www.tiddlywiki.com

Martin Budden

unread,
Jun 8, 2006, 5:17:06 PM6/8/06
to TiddlyWikiDev
I've got the code ready to go. And I'm using it in my day-to-day
TiddlyWiki, so it's all safe.

Martin

Reply all
Reply to author
Forward
0 new messages