Format Dom.

@param string $input Dom input.

@return string Indented Dom.
422547
public function doIndent($input)
    {
        $subject = $input;

        $output = '';

        $nextLineIndentationLevel = 0;

        do {
            $indentationLevel = $nextLineIndentationLevel;

            $patterns = $this->getTagPatterns();

            $rules = ['NO', 'DECREASE', 'INCREASE', 'DISCARD'];

            $match = [];

            foreach ($patterns as $pattern => $rule) {
                if ($match = preg_match($pattern, $subject, $matches)) {
                    $this->log[] = [
                        'rule' => $rules[$rule],
                        'pattern' => $pattern,
                        'subject' => $subject,
                        'match' => $matches[0],
                    ];

                    $subject = mb_substr($subject, mb_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->options['indentation_character'],
                        $indentationLevel
                    ) . $matches[0] . "\n";

                    break;
                }
            }
        } while ($match);

        $interpretedInput = '';

        foreach ($this->log as $e) {
            $interpretedInput .= $e['match'];
        }

        if ($interpretedInput !== $input) {
            throw new \RuntimeException('Did not reproduce the exact input.');
        }

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

        return $output;
    }
97107
public static function toKey($input)
    {
        // Remove spaces and dashes, then convert to lower case.
        $input = self::toUnderscoreSeparated($input);
        $input = strtolower($input);

        return $input;
    }
60438
public function format($content){
		// Add tcy
		$content = $this->tcyiz($content);
		// Add auto indent
		$dom = $this->getDomFromString($content);
		foreach( $dom->getElementsByTagName('p') as $p ){
			if( !$this->need_indent($p->nodeValue) ){
				$this->add_class($p, 'no-indent');
			}
		}
		// Remove all tt, big, acronym, strike, abbr
		$node_to_remove = array();
		foreach( ['tt', 'big', 'acronym', 'abbr', 'strike'] as $tag){
			foreach( $dom->getElementsByTagName($tag) as $elem ) {
				/** @var \DOMElement $elem */
				$new_elem = $dom->createElement( 'span' );
				// Copy all attributes
				if ( $elem->attributes ) {
					foreach ( $elem->attributes as $attr ) {
						$new_elem->setAttribute( $attr->nodeName, $attr->nodeValue );
					}
				}
				// Add original tag name as class
				$this->add_class($new_elem, $tag);
				// Copy all nodes
				foreach ( $elem->childNodes as $child ) {
					$new_elem->appendChild( $elem->removeChild( $child ) );
				}
				$node_to_remove[] = $elem;
				$elem->parentNode->replaceChild( $new_elem, $elem );
			}
		}
		return $this->retrieveBody($dom);
	}
208161
public function setInput($input)
    {
        if (!(is_string($input) || $input instanceof BasicFormElement)) {
            throw new Exception('Input must be a String or instance of FormElement Contract');
        }

        if (is_string($input)) {
            $input = $this->makeInput($input);
        }

        $this->input = $input;

        return $this;
    }
1057498
protected function convertPositiveTo($input)
    {
        $extraLen = strlen($input) - 5;

        if ($extraLen < 0) {
            return str_pad($input, 4, '0', STR_PAD_LEFT);
        }

        if ($extraLen < 26) {
            return chr(static::ORD_START + $extraLen) . $input;
        }

        $extraLen -= 25;

        $prefix = '';
        $carets = '';

        do {
            $carets .= '^';
            $extraLen--;

            $prefix = chr(static::ORD_START + $extraLen % 26) . $prefix;
            $extraLen = intval($extraLen / 26);
        } while ($extraLen);

        return "${carets}${prefix}${input}";
    }
743493
protected function inputAsFirstNode($input): ?\DOMNode {
        $nodes = $this->inputAsNodeList($input);

        return $nodes->findXPath('self::*')->first();
    }
1342462
public function parse($input)
    {
        $sorting = new Sort();

        foreach (explode('|', $input) as $property) {
            if ($property[0] === '-') {
                $sorting->add(new Sort\Desc(substr($property, 1)));
                continue;
            }
            $sorting->add(new Sort\Asc($property));
        }

        return $sorting;
    }
854563
public static function convert(string $input, int $to) : string
    {
        $string = self::normalize($input);
        $parts = explode(' ', $string);
        array_walk($parts, function (&$part) {
            $part = ucfirst($part);
        });
        switch ($to) {
            case self::TYPE_NAMESPACE:
                return implode('\\', $parts);
            case self::TYPE_TABLE:
                return strtolower(implode('_', $parts));
            case self::TYPE_VARIABLE:
            case self::TYPE_ANGULAR_COMPONENT:
                return lcfirst(implode('', $parts));
            case self::TYPE_PATH:
                return implode('/', $parts);
            case self::TYPE_URL:
                return strtolower(implode('/', $parts));
            case self::TYPE_CSS_IDENTIFIER:
            case self::TYPE_ANGULAR_TAG:
                return strtolower(implode('-', $parts));
            case self::TYPE_ANGULAR_MODULE:
                return strtolower(implode('.', $parts));
            default:
                throw new DomainException("Please use one of the `TYPE_` constants on the `Codger\Generate\Language` class as 2nd parameter.");
        }
    }
661556
public function prepare($input)
    {
        $form = $this->buildEmbeddedForm();

        return $form->setOriginal($this->original)->prepare($input);
    }
861846
public static function parseToIndex($input) {
        if (($input[0] == '{' || $input[0] == '[')) {
            return Arc2JsonLdConverter::jsonLdToIndex($input);
        } else {
            $parser = \ARC2::getRDFParser();
		    $parser->parse('', $input);
            return $parser->getSimpleIndex(false);
        }
    }
616635
public function normalize(string $input): string
    {
        $output = preg_replace_callback(self::$pattern,
            function($matches) {
                $int = $matches['int'];
                switch ($matches['time']) {
                    case 's':
                        $t = ($int == 1) ? ' second ' : ' seconds ';
                        break;
                    case 'm':
                        $t = ($int == 1) ? ' minute ' : ' minutes ';
                        break;
                    case 'h':
                        $t = ($int == 1) ? ' hour ' : ' hours ';
                        break;
                    case 'd':
                        $t = ($int == 1) ? ' day ' : ' days ';
                        break;
                    case 'w':
                        $t = ($int == 1) ? ' week ' : ' weeks ';
                        break;
                    case 'mon':
                        $t = ($int == 1) ? ' month ' : ' months ';
                        break;
                    case 'y':
                        $t = ($int == 1) ? ' year ' : ' years ';
                        break;
                }

                $t = $t ?? '';
                # rebuild the interval string
                $time = $int . $t;

                if (isset($matches['text'])) {
                    $time .= trim($matches['text']);
                }

                return $time;

            }, $input);

        return trim($output);
    }
1165661
private static function parseFromFormat(string $input, string $format)
    {
        $parsedOrNull = null;

        if (($value = DateTimeImmutable::createFromFormat($format, $input)) !== false) {
            $parsedOrNull = $value;
        }

        return $parsedOrNull;
    }
624064
public function indent($input)
    {
        $this->log = [];

        $input = $this->removeDoubleWhiteSpace($input);

        $output = $this->doIndent($input);

        return trim($output);
    }
1245427
public static function formatStringToMethodName(string $input) : string
    {
        $methodName = implode('', array_map('ucfirst', explode('_', strtolower($input))));

        return $methodName;
    }
328751
public function denormalize($input)
    {
        $lcPropertyName = lcfirst($input);
        $snakeCasedName = '';

        $len = strlen($lcPropertyName);
        for ($i = 0; $i < $len; ++$i) {
            if (ctype_upper($lcPropertyName[$i])) {
                $snakeCasedName .= '_' . strtolower($lcPropertyName[$i]);
            } else {
                $snakeCasedName .= strtolower($lcPropertyName[$i]);
            }
        }

        return $snakeCasedName;
    }
1332027
public function formatString($input)
    {
        if (is_array($input)) {
            $input = join(', ', $input);
        }
        $output = strip_tags($input);
        $output = str_replace(array("\r", "\n"), array(' ', ' '), $output);
        
        $output = $this->filterCsvInjection($output);
        
        return $output;
    }
1185663
public function canonicalize($input)
    {
        $filtered = preg_replace('/\D+/', '', $input) ?? '';
        if (strlen($filtered) !== $this->digitLength) {
            return $input;
        }

        return $filtered;
    }