_Function = $function ; $this->_Parameters = $isGlobal ? NULL : $parameters ; $this->_VarPrefix = $isGlobal ? '_' : '' ; $this->_IsGlobal = $isGlobal ; $this->_LastCharIndex = 0; $this->_NextPrefixIndex = 0; $this->_VarCharsLastIndex = count( $this->_VarChars ) - 1 ; } function Process() { $processed = $this->_Function ; if ( !$this->_IsGlobal ) $processed = $this->_ProcessVars( $processed, $this->_Parameters ) ; // Match "var" declarations. $numVarMatches = preg_match_all( '/\bvar\b\s+((?:({(?:(?>[^{}]*)|(?2))*})|[^;])+?)(?=(?:\bin\b)|;)/', $processed, $varsMatches ) ; if ( $numVarMatches > 0 ) { $vars = array() ; for ( $i = 0 ; $i < $numVarMatches ; $i++ ) { $varsMatch = $varsMatches[1][$i]; // Removed all (...), [...] and {...} blocks from the var // statement to avoid problems with commas inside them. $varsMatch = preg_replace( '/(\((?:(?>[^\(\)]*)|(?1))*\))+/', '', $varsMatch ) ; $varsMatch = preg_replace( '/(\[(?:(?>[^\[\]]*)|(?1))*\])+/', '', $varsMatch ) ; $varsMatch = preg_replace( '/({(?:(?>[^{}]*)|(?1))*})+/', '', $varsMatch ) ; $numVarNameMatches = preg_match_all( '/(?:^|,)\s*([^\s=,]+)/', $varsMatch, $varNameMatches ) ; for ( $j = 0 ; $j < $numVarNameMatches ; $j++ ) { $vars[] = $varNameMatches[1][$j] ; } } $processed = $this->_ProcessVars( $processed, $vars ) ; } return $processed ; } function _ProcessVars( $source, $vars ) { foreach ( $vars as $var ) { if ( strlen( $var) > 1 ) { $varName = $this->_GetVarName(); $source = preg_replace( '/(?_LastCharIndex == $this->_VarCharsLastIndex ) { $this->_RenewPrefix() ; $this->_LastCharIndex = 0 ; } $var = $this->_VarPrefix . $this->_VarChars[ $this->_LastCharIndex++ ] ; if ( preg_match( '/(?_Function ) ) return $this->_GetVarName() ; else return $var ; } function _RenewPrefix() { if ( strlen( $this->_VarPrefix) > 0 && $this->_VarPrefix != "_" ) { if ( $this->_NextPrefixIndex > $this->_VarCharsLastIndex ) $this->_NextPrefixIndex = 0 ; else $this->_VarPrefix = substr_replace( $this->_VarPrefix, '', strlen( $this->_VarPrefix ) - 1, 1 ) ; } $this->_VarPrefix .= $this->_VarChars[ $this->_NextPrefixIndex ] ; $this->_NextPrefixIndex++; } } ?>