Filters each non-comment part through a callable.

@param string   $content  The CSS
@param callable $callback A PHP callable

@return string The filtered CSS
553149
public static function filterCommentless($content, $callback)
    {
        $result = '';
        foreach (preg_split(static::REGEX_COMMENTS, $content, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) {
            if (!preg_match(static::REGEX_COMMENTS, $part, $match) || $part != $match[0]) {
                $part = call_user_func($callback, $part);
            }

            $result .= $part;
        }

        return $result;
    }
924028
public function getCustomHTMLBody($callback = false) {
        $body = $this->getHtmlBody();
        if($body === null) return null;

        if ($callback !== false) {
            $aAttachment = $this->parent->getAttachments();
            $aAttachment->each(function($oAttachment) use(&$body, $callback) {
                /** @var Attachment $oAttachment */
                if(is_callable($callback)) {
                    $body = $callback($body, $oAttachment);
                }elseif(is_string($callback)) {
                    call_user_func($callback, [$body, $oAttachment]);
                }
            });
        }

        return $body;
    }
726560
private function makeCallbackHumanReadable( Callable $callback )
    {
        if( is_string($callback) ) {
            return $callback;
        } elseif( is_array($callback) ) {
            return sprintf(
                "%s::%s",
                is_object( $callback[0] ) ? get_class($callback[0]) : $callback[0],
                $callback[1]
            );
        } elseif( !($callback instanceof \Closure) ) {
            return "<closure>";
        }
        throw new \Exception("Wow. I didn't know php could define a callable of this type. Pete __definately__ wants to know all about this.");
    }
571505
protected function shortenBools($content)
    {
        /*
         * 'true' or 'false' could be used as property names (which may be
         * followed by whitespace) - we must not replace those!
         * Since PHP doesn't allow variable-length (to account for the
         * whitespace) lookbehind assertions, I need to capture the leading
         * character and check if it's a `.`
         */
        $callback = function ($match) {
            if (trim($match[1]) === '.') {
                return $match[0];
            }

            return $match[1].($match[2] === 'true' ? '!0' : '!1');
        };
        $content = preg_replace_callback('/(^|.\s*)\b(true|false)\b(?!:)/', $callback, $content);

        // for(;;) is exactly the same as while(true), but shorter :)
        $content = preg_replace('/\bwhile\(!0\){/', 'for(;;){', $content);

        // now make sure we didn't turn any do ... while(true) into do ... for(;;)
        preg_match_all('/\bdo\b/', $content, $dos, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);

        // go backward to make sure positional offsets aren't altered when $content changes
        $dos = array_reverse($dos);
        foreach ($dos as $do) {
            $offsetDo = $do[0][1];

            // find all `while` (now `for`) following `do`: one of those must be
            // associated with the `do` and be turned back into `while`
            preg_match_all('/\bfor\(;;\)/', $content, $whiles, PREG_OFFSET_CAPTURE | PREG_SET_ORDER, $offsetDo);
            foreach ($whiles as $while) {
                $offsetWhile = $while[0][1];

                $open = substr_count($content, '{', $offsetDo, $offsetWhile - $offsetDo);
                $close = substr_count($content, '}', $offsetDo, $offsetWhile - $offsetDo);
                if ($open === $close) {
                    // only restore `while` if amount of `{` and `}` are the same;
                    // otherwise, that `for` isn't associated with this `do`
                    $content = substr_replace($content, 'while(!0)', $offsetWhile, strlen('for(;;)'));
                    break;
                }
            }
        }

        return $content;
    }
67991
public function filter(\Closure $callback, $reindex = true) {
		$result = array_filter($this->annotations, $callback);
		
		if ($reindex) {
			$result = array_values($result);
		}
		
		return $result;
	}
153582
protected function _filterAll($regex, $content, $i = 1, $key = '') {
		if (@preg_match_all($regex, $content, $matches) === false) {
			return false;
		}
		$result = isset($matches[$i]) ? $matches[$i] : $matches[0];
		if (isset($this->_callback['_all_'])) {
			foreach ($this->_callback['_all_'] as $filter) {
				$result = array_map($filter, $result);
			}
		}
		if ($key != '' && isset($this->_callback[$key])) {
			foreach ($this->_callback[$key] as $filter) {
				$result = array_map($filter, $result);
			}
		}
		return $result;
	}
577191
public static function filterImports($content, $callback, $includeUrl = true)
    {
        $pattern = $includeUrl ? static::REGEX_IMPORTS : static::REGEX_IMPORTS_NO_URLS;

        return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
            return preg_replace_callback($pattern, $callback, $part);
        });
    }
102801
public function filter($content, array $options = array())
	{
		$wrap = '<div id="content_%s_%s" class="su-content-inline su-input-html-inline-content">%s</div>';
		
		return sprintf(
					$wrap,
					$this->blockProperty->getBlock()->getId(),
					str_replace('.', '_', $this->blockProperty->getHierarchicalName()),
					parent::filter($content)
		);
	}
1017520
public function render(Closure $callback = null)
    {
        try {
            $contents = $this->renderContents();

            $response = isset($callback) ? $callback($this, $contents) : null;

            // Once we have the contents of the view, we will flush the sections if we are
            // done rendering all views so that there is nothing left hanging over when
            // another view gets rendered in the future by the application developer.
            $this->factory->flushSectionsIfDoneRendering();

            return $response ?: $contents;
        } catch (Exception $e) {
            $this->factory->flushSections();

            throw $e;
        }
    }
911806
public function parseShortcode(string $content, array $tags, Closure $callback = null)
    {
        if (strpos($content, '[') === false && empty($tags)) {
            return is_null($callback) ? [] : $content;
        }

        $regex = $this->getRegex($tags);

        preg_match_all("/$regex/", $content, $matches, PREG_SET_ORDER);

        if (is_null($callback)) {
            return iterator_to_array($this->generateResults($matches));
        }

        return preg_replace_callback("/$regex/", $this->generateCallback($callback), $content);
    }
1117642
public function removeFilter( $filter, $callback )
    {
        $i = 0;

        foreach( $this->filters as $key => $value )
        {
            if ( $filter === $key )
            {
                foreach( $value as $f => $call )
                {
                    if ( get_class( $callback[ 0 ] ) === get_class( $call[ 'callback' ][ 0 ] ) )
                    {
                        if ( $callback[ 1 ] === $call[ 'callback' ][ 1 ] )
                        {
                            unset( $this->filters[ $key ][ $i ] );

                            if ( $this->debug )
                            {
                                echo PHP_EOL . '-FILTER: ' . $filter . ' -> '
                                        . $this->_serializeCallback( $callback )
                                        . ' + Priority: ' . $call[ 'priority' ]
                                        . PHP_EOL;
                            }

                            return TRUE;
                        }
                    }
                }
            }

            $i++;
        }

        return FALSE;
    }
950471
protected function filterContent($key, $callback)
    {
        if ($this->contentFilter) {
            return $this->contentFilter->getContent($key, $callback);
        } else {
            return call_user_func($callback);
        }
    }
1144027
public function filter($callback = null)
    {
        if (is_null($callback)) {
            return new static(array_filter($this->array)); 
        }
        return new static(array_filter($this->array, $callback));
    }
86190
public function mapSpread(callable $callback)
    {
        return $this->map(function ($chunk, $key) use ($callback) {
            $chunk[] = $key;

            return $callback(...$chunk);
        });
    }
665640
public function coreScriptFilter($content) {

        $attributes = [];

        $attributes["type"] = "text/javascript";

        $innerHTML = null !== $content ? implode("", ["\n", $content, "\n"]) : "";

        return static::coreHTMLElement("script", $innerHTML, $attributes);
    }
1101669
public function replaceCallback(callable $callback, $subject, $limit = -1, & $count = null)
	{
		$this->clean();
		return preg_replace_callback($this->pattern, $callback, $subject, $limit, $count);
	}
875414
public function filterByCallback($callback)
    {
        if (!is_callable($callback)) {
            throw new LogicException(sprintf(
                "SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
                gettype($callback)
            ));
        }

        $output = static::create();

        foreach ($this as $item) {
            if (call_user_func($callback, $item, $this)) {
                $output->push($item);
            }
        }

        return $output;
    }