protected function captureCommentAndString($str) { $process = $this->process; $callback = function ($m) use($process) { $fullMatch = $m[0]; if (strpos($fullMatch, '/*') === 0) { // Bail without storing comment if output is minified or a private comment. if ($process->minifyOutput || strpos($fullMatch, '/*$') === 0) { $label = ''; } else { // Fix broken comments as they will break any subsquent // imported files that are inlined. if (!preg_match('~\\*/$~', $fullMatch)) { $fullMatch .= '*/'; } $label = $process->tokens->add($fullMatch, 'c'); } } else { // Fix broken strings as they will break any subsquent // imported files that are inlined. if ($fullMatch[0] !== $fullMatch[strlen($fullMatch) - 1]) { $fullMatch .= $fullMatch[0]; } $label = $process->tokens->add($fullMatch, 's'); } return $process->generateMap ? Tokens::pad($label, $fullMatch) : $label; }; return preg_replace_callback(Regex::$patt->commentAndString, $callback, $str); }
public function captureUrls($str, $add_padding = false) { $count = preg_match_all(Regex::make('~@import \\s+ (?<import>{{s_token}}) | {{LB}} (?<func>url|data-uri) {{parens}}~ixS'), $str, $m, PREG_OFFSET_CAPTURE); while ($count--) { list($full_text, $full_offset) = $m[0][$count]; list($import_text, $import_offset) = $m['import'][$count]; // @import directive. if ($import_offset !== -1) { $label = $this->add(new Url(trim($import_text))); $str = str_replace($import_text, $add_padding ? str_pad($label, strlen($import_text)) : $label, $str); } else { $func_name = strtolower($m['func'][$count][0]); $url = new Url(trim($m['parens_content'][$count][0])); $url->convertToData = 'data-uri' === $func_name; $label = $this->add($url); $str = substr_replace($str, $add_padding ? Tokens::pad($label, $full_text) : $label, $full_offset, strlen($full_text)); } } return $str; }