Useful to indent the output of a template.
@param string $code Output code of template.
@param int $spaces Amount of spaces to indent the code.
@return string Code indented.
190813
public function Indent($code, $spaces)
    {
        $indent = "";
        
        for($i=0; $i<$spaces; $i++)
        {
            $indent .= " ";
        }
        
        if(substr_count($code, "\n") <= 1)
            return $indent . $code;
        
        $code = str_replace("\n", "\n$indent", $code);
        
        return $code;
    }
273949
public static function objectToMarkup($object, $key, $spaces = 0, $indent = 2)
    {
        $spacesStr = str_repeat(' ', $spaces);
        $markup = $spacesStr . self::DIV_START_NOTRANSLATE;
        $markup .= self::toHtml(
            $object,
            SerializationHelper::toSnakeCase($key),
            $spaces + $indent,
            $indent,
            self::STYLE_DISPLAY_NONE
        );
        $markup .= $spacesStr . self::DIV_END;
        return $markup;
    }
976296
public function _prepend($code)
    {
        if (is_array($code)) {
            $code = implode(';', $code);
        }
        $this->prepend = $code.';'.$this->prepend;

        return $this;
    }
918912
static function compressCSS($code) {
        $code = self::clearWhitespaces($code);
        $code = preg_replace('/ ?\{ ?/', "{", $code);
        $code = preg_replace('/ ?\} ?/', "}", $code);
        $code = preg_replace('/ ?\; ?/', ";", $code);
        $code = preg_replace('/ ?\> ?/', ">", $code);
        $code = preg_replace('/ ?\, ?/', ",", $code);
        $code = preg_replace('/ ?\: ?/', ":", $code);
        $code = str_replace(";}", "}", $code);
        return $code;
    }
94791
protected function addIndent(string $string, int $indent = 0): string
    {
        return str_repeat(self::INDENT, max($indent, 0)) . $string;
    }
1222905
private function buildIndent($base, $indent, $depth)
    {
        $base = \is_int($base) ? str_repeat(' ', $base) : (string) $base;

        return $depth === 0 ? $base : $base . str_repeat(
            \is_int($indent) ? str_repeat(' ', $indent) : (string) $indent,
            $depth
        );
    }
813951
public function generate()
    {
        $code = array();

        if ($this->namespace !== null) {
            $code[] = $this->getIndentation() . 'namespace ' . $this->namespace;
            $code[] = '{';
            $code[] = null;

            // Temporarily add one more level of indentation.
            $this->addIndentationLevel(1);
        }

        $code = array_merge($code, $this->renderUsesLines());

        $indentation = $this->getIndentation();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $line = $indentation;
        if ($this->isFinal() === true) {
            $line .= 'final ';
        } elseif ($this->isAbstract() === true) {
            $line .= 'abstract ';
        }

        $line .= 'class ' . $this->name;

        if ($this->extends !== null) {
            $line .= ' extends ' . $this->extends;
        }

        if (count($this->implements) > 0) {
            $line .= ' implements ' . implode(', ', $this->implements);
        }

        $code[] = $line;
        $code[] = $indentation . '{';

        // Class uses.
        $classElements = $this->generateTraitUsesLines();

        // Class constants.
        $classElements = array_merge($classElements, $this->generateConstantsLines());

        // Class properties.
        $classElements = array_merge($classElements, $this->generatePropertiesLines());

        // Class methods.
        $classElements = array_merge($classElements, $this->generateMethodsLines());

        if (count($classElements) > 0) {
            $code[] = null;
            $code = array_merge($code, $classElements);
            // Remove last empty line.
            array_pop($code);
        }

        $code[] = $indentation . '}';

        if ($this->namespace !== null) {
            // Set back the indentation.
            $this->addIndentationLevel(-1);

            $code[] = $this->getIndentation() . '}';
        }

        return implode($this->getLineFeed(), $code);
    }
1243575
def should_indent(code):
    """"""
    last = rem_comment(code.splitlines()[-1])
    return last.endswith(":") or last.endswith("\\") or paren_change(last) < 0
496583
public static function clearQueryArg($code)
  {
    if (StringTools::left($code, 1) == '/') {
      $code = StringTools::right($code, StringTools::len($code)-1);
    }
    if (StringTools::right($code, 1) == '/') {
      $code = StringTools::left($code, StringTools::len($code)-1);
    }

    return $code;
  }
1022468
public function formatCode($code, $checked = false, $noTransformation = false)
    {
        return $this->getFormatInstance()->formatCode($code, $checked, $noTransformation);
    }
949110
public static function indent($str, $spaces = 4, $level = 1){
        return str_repeat(" ", $spaces * $level)
            . str_replace("\n", "\n" . str_repeat(" ", $spaces * $level), $str);
    }
1367248
public function format($source)
    {
        // We does not indent <script> body. Instead, it temporary removes it from the code, indents the input, and restores the script body.
        $tempScriptElements = [];

        if (preg_match_all('/<script\b[^>]*>([\s\S]*?)<\/script>/mi', $source, $matches)) {
            $tempScriptElements = $matches[ 0 ];

            foreach ($matches[ 0 ] as $i => $match) {
                $source = str_replace($match, '<script>' . ($i + 1) . '</script>', $source);
            }
        }

        // Removing double whitespaces to make the source code easier to read.
        // With exception of <pre>/ CSS white-space changing the default behaviour, double whitespace is meaningless in HTML output.
        // This reason alone is sufficient not to use indentation in production.
        $source = str_replace("\t", '', $source);
        $source = preg_replace('/\s{2,}/', ' ', $source);

        // Remove inline elements and replace them with text entities.
        $tempInlineElements = [];

        if (preg_match_all(
            '/<(' . implode('|', $this->inlineElements) . ')[^>]*>(?:[^<]*)<\/\1>/',
            $source,
            $matches
        )) {
            $tempInlineElements = $matches[ 0 ];

            foreach ($matches[ 0 ] as $i => $match) {
                $source = str_replace($match, 'ᐃ' . ($i + 1) . 'ᐃ', $source);
            }
        }

        $output = '';

        $nextLineIndentationLevel = 0;

        do {
            $indentationLevel = $nextLineIndentationLevel;

            $patterns = [
                // block tag
                '/^(<([a-z]+)(?:[^>]*)>(?:[^<]*)<\/(?:\2)>)/'  => static::MATCH_INDENT_NO,
                // DOCTYPE
                '/^<!([^>]*)>/'                                => static::MATCH_INDENT_NO,
                // tag with implied closing
                '/^<(input|link|meta|base|br|img|hr)([^>]*)>/' => static::MATCH_INDENT_NO,
                // opening tag
                '/^<[^\/]([^>]*)>/'                            => static::MATCH_INDENT_INCREASE,
                // closing tag
                '/^<\/([^>]*)>/'                               => static::MATCH_INDENT_DECREASE,
                // self-closing tag
                '/^<(.+)\/>/'                                  => static::MATCH_INDENT_DECREASE,
                // whitespace
                '/^(\s+)/'                                     => static::MATCH_DISCARD,
                // text node
                '/([^<]+)/'                                    => static::MATCH_INDENT_NO,
            ];

            foreach ($patterns as $pattern => $rule) {
                if ($match = preg_match($pattern, $source, $matches)) {
                    if (function_exists('mb_substr')) {
                        $source = mb_substr($source, mb_strlen($matches[ 0 ]));
                    } else {
                        $source = substr($source, strlen($matches[ 0 ]));
                    }

                    if ($rule === static::MATCH_DISCARD) {
                        break;
                    }

                    if ($rule === static::MATCH_INDENT_NO) {

                    } else {
                        if ($rule === static::MATCH_INDENT_DECREASE) {
                            $nextLineIndentationLevel--;
                            $indentationLevel--;
                        } else {
                            $nextLineIndentationLevel++;
                        }
                    }

                    if ($indentationLevel < 0) {
                        $indentationLevel = 0;
                    }

                    $output .= str_repeat($this->indentCharacter, $indentationLevel) . $matches[ 0 ] . "\n";

                    break;
                }
            }
        } while ($match);

        $output = preg_replace('/(<(\w+)[^>]*>)\s*(<\/\2>)/', '\\1\\3', $output);

        foreach ($tempScriptElements as $i => $original) {
            $output = str_replace('<script>' . ($i + 1) . '</script>', $original, $output);
        }

        foreach ($tempInlineElements as $i => $original) {
            $output = str_replace('ᐃ' . ($i + 1) . 'ᐃ', $original, $output);
        }

        return trim($output);
    }
490644
public function tokenize($code)
    {
        $code = trim((string) $code);
        if (empty($code)) {
            throw new \InvalidArgumentException('Cannot tokenize empty string.');
        }

        $this->code = $code;
        $this->tokens = array();

        $tokenArray = explode(' ', $this->code);

        if (!is_array($tokenArray) || empty($tokenArray)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot tokenize string: %s, please use " "(empty space for delimeter betwwen tokens)', $this->code)
            );
        }

        foreach ($tokenArray as $t) {
            if (array_key_exists($t, static::$operatorsMap)) {
                $token = new Operator(
                        $t,
                        static::$operatorsMap[$t]['priority'],
                        static::$operatorsMap[$t]['associativity']
                );
            } elseif (is_numeric($t)) {
                $token = new Token((float) $t, Token::T_OPERAND);
            }elseif('(' === $t) {
                $token = new Token($t, Token::T_LEFT_BRACKET);
            }elseif(')' === $t) {
                $token = new Token($t, Token::T_RIGHT_BRACKET);
            }elseif('' === $t) {
                continue;
            }else {
                throw new \InvalidArgumentException(sprintf('Syntax error: unknown token "%s"', $t));
            }

            $this->tokens[] = $token;
        }

        return $this->tokens;
    }
650586
public static function indent(string $s, int $level = 1, string $chars = "\t"): string
    {
        if ($level > 0) {
            $s = static::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . \str_repeat($chars, $level));
        }

        return $s;
    }
677346
public function render($indent = "\t")
    {
        $html = '';
        foreach(self::$storage as $meta) {
            $html .= $indent . $meta->render() . PHP_EOL;
        }
        
        return $html;
    }
319730
private function replaceTabs($code)
    {
        if ($this->options['tabReplace'] !== null) {
            return str_replace("\t", $this->options['tabReplace'], $code);
        }

        return $code;
    }
1071647
public function Render ($indent = 0) {
		$actualGroupItems = & $this->_getScriptsGroupContainer($this->actualGroupName);
		if (count($actualGroupItems) === 0) return '';
		$minify = (bool)self::$globalOptions['jsMinify'];
		$joinTogether = (bool)self::$globalOptions['jsJoin'];
		if ($joinTogether) {
			$result = $this->_renderItemsTogether(
				$this->actualGroupName,
				$actualGroupItems,
				$indent,
				$minify
			);
		} else {
			$result = $this->_renderItemsSeparated(
				$this->actualGroupName,
				$actualGroupItems,
				$indent,
				$minify
			);
		}
		return $result;
	}