Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work
properly. THIS IS A HACK!
@param string $string a CSS colour definition
@return string
432807
protected function mungeRgb($string)
    {
        $p = '\s*(\d+(\.\d+)?([%]?))\s*';

        if (preg_match('/(rgba|hsla)\(/', $string)) {
            return preg_replace('/(rgba|hsla)\('.$p.','.$p.','.$p.','.$p.'\)/', '\1(\2,\5,\8,\11)', $string);
        }

        return preg_replace('/(rgb|hsl)\('.$p.','.$p.','.$p.'\)/', '\1(\2,\5,\8)', $string);
    }
57164
public function normalize($string) {
		$string = $this->_normalize($string, ['clean' => true, 'case' => true]);
		return implode('-', str_split($string, $this->_partLength));
	}
1135977
protected function removeBadCharLast( $string ) {
		if ( $string != '' ) {
			$char = ord( $string[strlen( $string ) - 1] );
			$m = array();
			if ( $char >= 0xc0 ) {
				# We got the first byte only of a multibyte char; remove it.
				$string = substr( $string, 0, -1 );
			} elseif ( $char >= 0x80 &&
				  preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
							  '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) )
			{
				# We chopped in the middle of a character; remove it
				$string = $m[1];
			}
		}
		return $string;
	}
901810
public static function cleanupString($string)
    {
        $string = trim($string);
        $string = str_replace(array("\n", "\r", "\0"), '', $string);

        $limit = Config::getInstance()->Tracker['page_maximum_length'];
        $clean = substr($string, 0, $limit);
        return $clean;
    }
719838
final public static function handlifyString($string)
    {
        $string = preg_replace('/\W+/', '_', $string);
        $string = preg_replace('/([A-Z])/', '_$1', $string);
        $string = strtolower($string);
        $string = preg_replace('/_+/', '_', trim($string, '_'));

        return $string;
    }
586772
static function TrimRight($string, $chars = null)
    {
        self::InitEncoding();
        if (!$chars)
            return rtrim($chars);

        return rtrim($string, $chars);
    }
702813
public static function clearString( string $string ) {
		$string = trim( $string );
		$string = stripslashes( $string );
		$string = htmlspecialchars( $string );

		return $string;
	}
455045
protected static function convertDoubleWidth( $string ) {
		static $full = null;
		static $half = null;

		if ( $full === null ) {
			$fullWidth = "０１２３４５６７８９ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯＰＱＲＳＴＵＶＷＸＹＺａｂｃｄｅｆｇｈｉｊｋｌｍｎｏｐｑｒｓｔｕｖｗｘｙｚ";
			$halfWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
			$full = str_split( $fullWidth, 3 );
			$half = str_split( $halfWidth );
		}

		$string = str_replace( $full, $half, $string );
		return $string;
	}
1206125
public static function parseRgbString(string $string) : array
    {
        if (!preg_match(self::REGEX_RGB, $string, $matches)) {
            throw InvalidArgumentException::format(
                    'Invalid rgb string passed to %s: expecting format "rgb(0-255, 0-255, 0-255)", "%s" given',
                    __METHOD__, $string
            );
        }

        return [(int)$matches[1], (int)$matches[2], (int)$matches[3]];
    }
692669
public static function spaceless(string $s)
	{
		$s = trim($s);
		$s = self::replace($s, '#\s#', '');

		return $s;
	}
1181545
private function clean(string $string, bool $space_remove = true)
    {
        $string = trim($string);
        if ($space_remove) {
            $string = str_replace(' ', '-', $string);
        }
        return preg_replace('/[^A-Za-z0-9\-][_]/', '', $string);
    }
406915
public static function highlight($string)
    {
        $tokens = self::tokenize($string);

        $return = '';

        foreach ($tokens as $token) {
            $return .= self::highlightToken($token);
        }

        return self::output($return);
    }
452045
public static function escapeCss($string)
    {
        if ($string !== '' && !ctype_digit($string))
        {
            $matcher = function($matches)
            {
                $chr = $matches[0];

                if (strlen($chr) !== 1)
                {
                    $chr = static::convertEncoding($chr, 'UTF-16BE', 'UTF-8');
                    $ord = hexdec(bin2hex($chr));
                }
                else $ord = ord($chr);

                return sprintf('\\%X ', $ord);
            };

            $string = preg_replace_callback('/[^a-z0-9]/iSu', $matcher, $string);
        }


        return $string;
    }
794010
public static function escape($string) {
    $escaped_chars = str_split(self::ESCAPED_CHARACTERS);
    $escaped_chars_replace = array_map(function($char) {
      return '\\' . $char;
    }, $escaped_chars);
    $string = str_replace($escaped_chars, $escaped_chars_replace, $string);
    // Ignored whitespace.
    return preg_replace('/\s+/u', ' ', $string);
  }
589175
public function convertNewlines($string) {
        $string = str_replace("\r\n", "\n", $string);
        $string = str_replace("\r", "\n", $string);

        return $this->cleanNewlines($string);
    }
1022624
private function filterSpecialCharacters($string)
    {
        $string = str_replace('<', ' <',
            $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething
        $string = strip_tags($string);
        $string = trim($string);
        $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters
        $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ',
            $string); // Replace sentence breaking charaters with spaces
        $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space.
        $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space.
        $string = preg_replace("/[^a-zA-Z0-9 ]/", '',
            $string); // Filter out everything that is not alphanumeric or a space
        $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space
        return $string;
    }
1255
private function vulgarize($string)
    {
        return trim(
            preg_replace(
                '/(-+)/',
                '-',
                preg_replace(
                    '/([^a-z0-9-]*)/',
                    '',
                    preg_replace(
                        '/((\s|\.|\'|\/)+)/',
                        '-',
                        html_entity_decode(
                            preg_replace(
                                '/&(a|o)elig;/',
                                '$1e',
                                preg_replace(
                                    '/&([a-z])(uml|acute|grave|circ|tilde|ring|cedil|slash);/',
                                    '$1',
                                    strtolower(
                                        htmlentities(
                                            $string,
                                            ENT_COMPAT,
                                            'utf-8'
                                        )
                                    )
                                )
                            ),
                            ENT_COMPAT,
                            'utf-8'
                        )
                    )
                )
            ),
            '-'
        );
    }