View Single Post
Old 2005-12-20, 23:24   Link #86
phib
Junior Member
 
Join Date: Oct 2004
Quote:
Originally Posted by shinjipierre
Well, I've released my ssa to after effects script.
I'm still looking at the source, but there are things that can be done more elegant using regexps.

For example:

Code:
	//Function which transforms the line into an after effects text by removing the { } things
	function transLigne (ligne) {
		var new_ligne = "";

		for($i=0;$i < (ligne.length);$i++) {
			if(ligne[$i] != '{') {															//if it's not a {, I copy it.
				new_ligne += ligne[$i];
			} else {
				if($i != 0 && new_ligne[$i-1] != ' ') {						//if it's a {, I add a space 
					new_ligne += ' ';
				}//if
				while(ligne[$i] != '}') {													//I remove the things in {...}
					$i++;
				}//while
			}//else
		}//for

		return(new_ligne);																		// I return the result
	}//function
Using regexp's (just pay attention to the 2 lines in the function, ignore the rest ):

Code:
CAssEvent.prototype.getPlainText = function getPlainText()
{
	var sTmp = new String(this.Text);
	return sTmp.replace(/\{[^\{]*\}/g, ""); //looking at your source here should be " " instead of ""
}


Code:
options_ligne[9] = ligne.substring(num_option,100000000);
Instead of putting a large number as end, u can just put the start, because if the end is undefined, it will take the text till the end (as specified in the ecma-262).
phib is offline   Reply With Quote