Get string rendering strategies for given chunks

@param  string $php
@return array
486763
protected static function getStringRenderings($php)
	{
		$chunks = explode('$this->at($node);', $php);
		if (count($chunks) > 2)
		{
			// Can't use string replacements if there are more than one xsl:apply-templates
			return [];
		}

		$renderings = [];
		foreach ($chunks as $k => $chunk)
		{
			// Try a static replacement first
			$rendering = self::getStaticRendering($chunk);
			if ($rendering !== false)
			{
				$renderings[$k] = ['static', $rendering];
			}
			elseif ($k === 0)
			{
				// If this is the first chunk, we can try a dynamic replacement. This wouldn't work
				// for the second chunk because we wouldn't have access to the attribute values
				$rendering = self::getDynamicRendering($chunk);
				if ($rendering !== false)
				{
					$renderings[$k] = ['dynamic', $rendering];
				}
			}
		}

		return $renderings;
	}
1308814
public function tokenize($string)
    {
        if(!$this->length) {
            return array(substr($string, $this->startPosition));
        } else {
            return array(substr($string, $this->startPosition, $this->length));
        }
    }
595074
private function getAnyType($string)
    {
        $anyString = '';

        do {
            $anyString .= $string[0];
            $string = substr($string, 1);

            $typeInfo = $this->scanNextType($string);

            // ignore all until markup reached
            if ($typeInfo['type'] !== self::T_MARKUP_OPEN && $typeInfo['type'] !== self::T_MARKUP_OPEN_ESCAPED) {
                $typeInfo = null;
            }
        } while ($typeInfo === null && $string);

        return [
            'type'   => self::T_ANY,
            'match'  => $anyString,
            'length' => strlen($anyString),
        ];
    }
786215
public function strip_php_tags($data)
    {
        if (is_array($data)) {
            foreach ($data as $key=>$value) {
                $data[$key] = $this->strip_php_tags($value);
            }
            return $data;
        }
        return addslashes(htmlspecialchars(strip_tags($data)));
    }
1227816
public function get_chunks($type) {
        if (!isset($this->_chunks[$type]) || $this->_chunks[$type] === null)
            return null;

        $chunks = array ();

        foreach ($this->_chunks[$type] as $chunk) {
            if ($chunk['size'] > 0) {
                fseek($this->_fp, $chunk['offset'], SEEK_SET);
                $chunks[] = fread($this->_fp, $chunk['size']);
            } else {
                $chunks[] = '';
            }
        }

        return $chunks;
    }
825054
public static function get($string)
    {
        $vars = func_get_args();

        if (array_key_exists($string, self::$strings)) {
            $vars[0] = self::$strings[$string];
            return call_user_func_array('sprintf', $vars);
        }

        return '%%MISSING STRING: ' . $string . '%%';
    }
1225779
public function getCurrentFormatting($string)
    {
        $stack = [];
        foreach ($this->getStyleStack($string) as $style) {
            if (preg_match(static::REGEX_FIRST_KEY, $style, $matches)) {
                $key = $matches[0];

                // if this is a valid setting style, add it to the stack
                if (array_key_exists($key, $this->formats)) {
                    $stack[] = ['key' => $key, 'style' => $style];
                } else {
                    // otherwise remove all elements that this turns off from the current stack
                    if ($key === static::STYLE_RESET) {
                        $stack = [];
                    } else {
                        $stack = array_filter($stack, function ($item) use ($key) {
                            return !in_array($key, $this->formats[$item['key']]);
                        });
                    }
                }
            }
        }

        if (count($stack) === 0) {
            return '';
        }

        $items = array_map(function ($item) {
            return $item['style'];
        }, $stack);
        return sprintf(static::ESCAPE . '[%sm', implode(';', $items));
    }
1270338
protected function _renderAttributes($keys) 
    {
        $html = '';
        foreach( $keys as $key ) {
            if( $val = $this->$key ) {
                if( is_array($val) ) {

                    // check if the array is an indexed array, check keys of 
                    // array[0..cnt] 
                    //
                    // if it's an indexed array
                    // for attributes key like "class", the value can be 
                    //
                    //     array('class1','class2')
                    //
                    // this renders the attribute as "class1 class2"
                    //
                    // if it's an associative array
                    // for attribute key like "style", the value can be 
                    //
                    //      array( 'border' => '1px solid #ccc' )
                    //
                    // this renders the attribute as 
                    //
                    //      "border: 1px solid #ccc;"
                    //
                    if( array_keys($val) === range(0, count($val)-1) ) {
                        $val = join(' ', $val);
                    } else {
                        $val0 = $val;
                        $val = '';
                        foreach( $val0 as $name => $data ) {
                            $val .= "$name:$data;";
                        }
                    }
                }
                // for boolean type values like readonly attribute, 
                // we render it as readonly="readonly".
                elseif ( is_bool($val) ) {
                    $val = $key;
                }

                // Convert camalcase name to dash-separated name
                //
                // for dataUrl attributes, render these attributes like data-url
                // ( use dash separator)
                $html .= sprintf(' %s="%s"', 
                        strtolower(preg_replace('/[A-Z]/', '-$0', $key)),
                        htmlspecialchars( $val )
                );
            }
        }
        return $html;
    }
728942
private function formatToParameters($array)
    {
        if (empty($array)) {
            return [];
        }

        $defaultDirection = config('columnsortable.default_direction', 'asc');

        if (is_string($array)) {
            return ['sort' => $array, 'direction' => $defaultDirection];
        }

        return (key($array) === 0) ? ['sort' => $array[0], 'direction' => $defaultDirection] : [
            'sort'      => key($array),
            'direction' => reset($array),
        ];
    }
669357
protected function validate_php( $php ) {
		$result = $required = array();

		foreach ( $php as $type => $data ) {
			switch ( $type ) {
				case 'version':
					$result[ $type ]   = version_compare( phpversion(), $data, $this->version_compare_operator );
					$required[ $type ] = $data;
					break;

				case 'extensions':
					// Check that all required PHP extensions are loaded.
					foreach ( (array) $data as $extension ) {
						if ( $extension && is_string( $extension ) ) {
							$result[ $type ][ $extension ] = extension_loaded( $extension );
							$required[ $type ][]           = $extension;
						}
					}

					break;
			}
		}

		$this->results['php']  = $result;
		$this->required['php'] = $required;
	}
417542
private static function _getCharMap(): array
    {
        // Keep local copy
        static $map = [];

        if (empty($map)) {
            // This will replace accented chars with non-accented chars
            foreach (StringHelper::asciiCharMap() as $asciiChar => $charsArray) {
                foreach ($charsArray as $char) {
                    $map[$char] = $asciiChar;
                }
            }

            // Replace punctuation with a space
            foreach (self::_getPunctuation() as $value) {
                $map[$value] = ' ';
            }
        }

        // Return the char map
        return $map;
    }
1227176
protected function _formatNewlines($str) {
		if ($str === '') {
			return $str;
		}

		if (strpos($str, "\n") === false && !in_array($this->lastBlockElement, $this->innerBlockRequired)) {
			return $str;
		}

		// Convert two consecutive newlines to paragraphs
		$str = str_replace("\n\n", "</p>\n\n<p>", $str);

		// Convert single spaces to <br /> tags
		$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);

		// Wrap the whole enchilada in enclosing paragraphs
		if ($str !== "\n") {
			// We trim off the right-side new line so that the closing </p> tag
			// will be positioned immediately following the string, matching
			// the behavior of the opening <p> tag
			$str = '<p>' . rtrim($str) . '</p>';
		}

		// Remove empty paragraphs if they are on the first line, as this
		// is a potential unintended consequence of the previous code
		$str = preg_replace("/<p><\/p>(.*)/", '\\1', $str, 1);

		return $str;
	}
917758
public function formatAnsi($string) {
        $styleStack = [];

        // match all tags like <tag> and </tag>
        $groups = $this->formatParser->parseFormat($string);

        foreach ($groups as $group) {
            $tag = $group[0]; // <tag> or </tag>
            $styleName = $group[1]; // tag
            $stylesString = $group[2]; // stuff like color=red

            // do not process unknown style tags
            if ($styleName !== 'style' && ! $this->hasStyle($styleName)) {
                continue;
            }

            // is this a closing tag?
            if (stripos($tag, '/') !== false) {
                // get previous style
                array_pop($styleStack);
                $styleCode = array_last($styleStack);

                if ( ! $styleCode) {
                    $styleCode = 0;
                }
            } else {
                if ($styleName === 'style') {
                    $style = new ConsoleStyle('style');
                } else {
                    $style = $this->getStyle($styleName);
                }

                if ($style instanceof IConsoleStyle) {
                    // clone style to prevent unwanted
                    // modification on future uses
                    $style = clone $style;
                    $style->parseStyle($stylesString);
                    $styleCode = $style->getStyleCode();
                }

                $styleStack[] = $styleCode;
            }

            // replace first matching tag with the escape sequence;
            $pattern = s('#%s#', preg_quote($tag));
            $escapeSequence = s("\e[%sm", $styleCode);

            $string = preg_replace($pattern, $escapeSequence, $string, 1);
        }

        $string = $this->formatParser->unescapeTags($string);

        return $string;
    }
100713
protected function _parseStyles(&$text)
    {
        $styles = '';

        $matches = array();
        if (preg_match_all('#<style\s*src="([^"]+)"(.*)\/>#iU', $text, $matches)) {
            foreach (array_unique($matches[1]) as $key => $match) {
                $attribs = $this->_parseAttributes($matches[2][$key]);
                $styles .= $this->_renderStyle($match, true, $attribs);
            }

            $text = str_replace($matches[0], '', $text);
        }

        $matches = array();
        if (preg_match_all('#<style(.*)>(.*)<\/style>#siU', $text, $matches)) {
            foreach ($matches[2] as $key => $match) {
                $attribs = $this->_parseAttributes($matches[1][$key]);
                $styles .= $this->_renderStyle($match, false, $attribs);
            }

            $text = str_replace($matches[0], '', $text);
        }

        return $styles;
    }
235630
public static function get_strings($strings) {
        $params = self::validate_parameters(self::get_strings_parameters(),
                      array('strings'=>$strings));
        $stringmanager = get_string_manager();

        $translatedstrings = array();
        foreach($params['strings'] as $string) {

            if (!empty($string['lang'])) {
                $lang = $string['lang'];
            } else {
                $lang = current_language();
            }

            $translatedstrings[] = array(
                'stringid' => $string['stringid'],
                'component' => $string['component'],
                'lang' => $lang,
                'string' => $stringmanager->get_string($string['stringid'], $string['component'],
                    core_external::format_string_parameters($string['stringparams']), $lang));
        }

        return $translatedstrings;
    }
1173355
protected function _format($items) {
		$e = [];
		foreach ($items as $item) {
			$tmp = [];
			foreach ($item as $key => $row) {
				switch ($key) {
					case 'editable':
						$tmp[] = $row ? 'true' : 'false';
						break;
					case 'start':
					case 'end':
						$tmp[] = '\'' . $key . '\': ' . $this->_date($row);
						break;
					default:
						$tmp[] = '\'' . $key . '\': \'' . str_replace('\'', '\\\'', $row) . '\'';
				}
			}
			$e[] = '{' . implode(',' . PHP_EOL, $tmp) . '}';
		}
		$string = '[' . implode(',' . PHP_EOL, $e) . '];';
		return $string;
	}
100254
private function separateSelectString(string $string)
    {
        if (false === strpos($string, '(')) {
            return array_map('trim', explode(',', $string));
        }

        $opened = $closed = 0;
        $cnt = mb_strlen($string);
        $arrayStrings = [];
        $substring = '';

        for ($i = 0; $i < $cnt; $i++) {
            $substring .= $string[$i];
            if ('(' === $string[$i]) {
                $opened++;
            } elseif (')' === $string[$i]) {
                $closed++;
            } elseif (',' === $string[$i] && $opened === $closed) {
                $arrayStrings[] = trim($substring);
            }
        }
        $arrayStrings[] = trim($substring);

        return $arrayStrings;
    }