Produces a compliant, formatted RFC 2822 'phrase' based on the string given.

@param string $string  as displayed
@param bool   $shorten the first line to make remove for header name
963284
protected function createPhrase(HeaderInterface $header, string $string, string $charset, bool $shorten = false): string
    {
        // Treat token as exactly what was given
        $phraseStr = $string;

        // If it's not valid
        if (!preg_match('/^'.self::PHRASE_PATTERN.'$/D', $phraseStr)) {
            // .. but it is just ascii text, try escaping some characters
            // and make it a quoted-string
            if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) {
                foreach (['\\', '"'] as $char) {
                    $phraseStr = str_replace($char, '\\'.$char, $phraseStr);
                }
                $phraseStr = '"'.$phraseStr.'"';
            } else {
                // ... otherwise it needs encoding
                // Determine space remaining on line if first line
                if ($shorten) {
                    $usedLength = \strlen($header->getName().': ');
                } else {
                    $usedLength = 0;
                }
                $phraseStr = $this->encodeWords($header, $string, $usedLength);
            }
        }

        return $phraseStr;
    }
773472
public static function safe(string $string) : string
  {
    $split = str_split($string);

    foreach($split as $k => $char) {
      if (str_contains('~!@#$%^&*()_-=+<>/\?;:{}[]|,.', $char)) {
        unset($split[$k]);
      }
    }

    return implode('', $split);
  }
10671
public function inflect(string $string, $pluralize = 0) : string
    {
        return ($pluralize) ? Inflect::pluralize($string) : Inflect::singularize($string);
    }
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;
    }
966845
public static function stringToValue($string)
	{
		if($string == '')
		{
			return $string;
		}
		if(is_float($string))
		{
			return (float) $string;
		}
		if(is_int($string))
		{
			return (int) $string;
		}
		if(strtolower($string) == 'true')
		{
			return true;
		}
		if(strtolower($string) == 'false')
		{
			return false;
		}
		if(strtolower($string) == 'null')
		{
			return NULL;
		}
		
		return $string;
	}
535968
private function trimLast($string)
        {
            $length = strlen($string) - 1;

            if (Arrays::in($string{$length}, array('t', 'x'))) {
                $string = substr($string, 0, $length);
            }
        }
295569
static function quickIsNFC( $string ) {
		# ASCII is always valid NFC!
		# If it's pure ASCII, let it through.
		if ( !preg_match( '/[\x80-\xff]/', $string ) ) {
			return true;
		}

		self::loadData();
		$len = strlen( $string );
		for ( $i = 0; $i < $len; $i++ ) {
			$c = $string[$i];
			$n = ord( $c );
			if ( $n < 0x80 ) {
				continue;
			} elseif ( $n >= 0xf0 ) {
				$c = substr( $string, $i, 4 );
				$i += 3;
			} elseif ( $n >= 0xe0 ) {
				$c = substr( $string, $i, 3 );
				$i += 2;
			} elseif ( $n >= 0xc0 ) {
				$c = substr( $string, $i, 2 );
				$i++;
			}
			if ( isset( self::$utfCheckNFC[$c] ) ) {
				# If it's NO or MAYBE, bail and do the slow check.
				return false;
			}
			if ( isset( self::$utfCombiningClass[$c] ) ) {
				# Combining character? We might have to do sorting, at least.
				return false;
			}
		}

		return true;
	}
258118
private function __validateString($string, $minLength = 1, $maxLength = 0)
    {
        if (!is_string($string)) {
            $this->error = 'parameter is not string.';
            return false;
        } else if ($maxLength > 0 && strlen($string) > $maxLength) {
            $this->error = 'parameter is too long. string:' . $string;
            return false;
        } else if (strlen($string) < $minLength) {
            $this->error = 'parameter is too short. string:' . $string;
            return false;
        }
        return true;
    }
566218
protected function sanitizeDescription($string)
    {
        $description = parent::sanitizeDescription($string);
        if (strpos($description, '/REMI/USTD//') !== false
            && preg_match('#/REMI/USTD//(.*?)/#s', $description, $results) && !empty($results[1])
        ) {
            return $results[1];
        }
        if (strpos($description, '/REMI/STRD/CUR/') !== false
            && preg_match('#/REMI/STRD/CUR/(.*?)/#s', $description, $results) && !empty($results[1])
        ) {
            return $results[1];
        }

        return $description;
    }
396034
private function strStartsWith($string, $niddle)
    {
        return mb_strtolower(substr($string, 0, mb_strlen($niddle))) == mb_strtolower($niddle);
    }
1051955
static function quickIsNFCVerify( &$string ) {
		# Screen out some characters that eg won't be allowed in XML
		$string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', Constants::UTF8_REPLACEMENT, $string );

		# ASCII is always valid NFC!
		# If we're only ever given plain ASCII, we can avoid the overhead
		# of initializing the decomposition tables by skipping out early.
		if ( !preg_match( '/[\x80-\xff]/', $string ) ) {
			return true;
		}

		static $checkit = null, $tailBytes = null, $utfCheckOrCombining = null;
		if ( !isset( $checkit ) ) {
			# Load/build some scary lookup tables...
			self::loadData();

			$utfCheckOrCombining = array_merge( self::$utfCheckNFC, self::$utfCombiningClass );

			# Head bytes for sequences which we should do further validity checks
			$checkit = array_flip( array_map( 'chr',
				[ 0xc0, 0xc1, 0xe0, 0xed, 0xef,
					0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
					0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff ] ) );

			# Each UTF-8 head byte is followed by a certain
			# number of tail bytes.
			$tailBytes = [];
			for ( $n = 0; $n < 256; $n++ ) {
				if ( $n < 0xc0 ) {
					$remaining = 0;
				} elseif ( $n < 0xe0 ) {
					$remaining = 1;
				} elseif ( $n < 0xf0 ) {
					$remaining = 2;
				} elseif ( $n < 0xf8 ) {
					$remaining = 3;
				} elseif ( $n < 0xfc ) {
					$remaining = 4;
				} elseif ( $n < 0xfe ) {
					$remaining = 5;
				} else {
					$remaining = 0;
				}
				$tailBytes[chr( $n )] = $remaining;
			}
		}

		# Chop the text into pure-ASCII and non-ASCII areas;
		# large ASCII parts can be handled much more quickly.
		# Don't chop up Unicode areas for punctuation, though,
		# that wastes energy.
		$matches = [];
		preg_match_all(
			'/([\x00-\x7f]+|[\x80-\xff][\x00-\x40\x5b-\x5f\x7b-\xff]*)/',
			$string, $matches );

		$looksNormal = true;
		$base = 0;
		$replace = [];
		foreach ( $matches[1] as $str ) {
			$chunk = strlen( $str );

			if ( $str[0] < "\x80" ) {
				# ASCII chunk: guaranteed to be valid UTF-8
				# and in normal form C, so skip over it.
				$base += $chunk;
				continue;
			}

			# We'll have to examine the chunk byte by byte to ensure
			# that it consists of valid UTF-8 sequences, and to see
			# if any of them might not be normalized.

			# Since PHP is not the fastest language on earth, some of
			# this code is a little ugly with inner loop optimizations.

			$head = '';
			# Counting down is faster. I'm *so* sorry.
			$len = $chunk + 1;

			for ( $i = -1; --$len; ) {
				$remaining = $tailBytes[$c = $str[++$i]];
				if ( $remaining ) {
					# UTF-8 head byte!
					$sequence = $head = $c;
					do {
						# Look for the defined number of tail bytes...
						if ( --$len && ( $c = $str[++$i] ) >= "\x80" && $c < "\xc0" ) {
							# Legal tail bytes are nice.
							$sequence .= $c;
						} else {
							if ( 0 == $len ) {
								# Premature end of string!
								# Drop a replacement character into output to
								# represent the invalid UTF-8 sequence.
								$replace[] = [ Constants::UTF8_REPLACEMENT,
									$base + $i + 1 - strlen( $sequence ),
									strlen( $sequence ) ];
								break 2;
							} else {
								# Illegal tail byte; abandon the sequence.
								$replace[] = [ Constants::UTF8_REPLACEMENT,
									$base + $i - strlen( $sequence ),
									strlen( $sequence ) ];
								# Back up and reprocess this byte; it may itself
								# be a legal ASCII or UTF-8 sequence head.
								--$i;
								++$len;
								continue 2;
							}
						}
					} while ( --$remaining );

					if ( isset( $checkit[$head] ) ) {
						# Do some more detailed validity checks, for
						# invalid characters and illegal sequences.
						if ( $head == "\xed" ) {
							# 0xed is relatively frequent in Korean, which
							# abuts the surrogate area, so we're doing
							# this check separately to speed things up.

							if ( $sequence >= Constants::UTF8_SURROGATE_FIRST ) {
								# Surrogates are legal only in UTF-16 code.
								# They are totally forbidden here in UTF-8
								# utopia.
								$replace[] = [ Constants::UTF8_REPLACEMENT,
									$base + $i + 1 - strlen( $sequence ),
									strlen( $sequence ) ];
								$head = '';
								continue;
							}
						} else {
							# Slower, but rarer checks...
							$n = ord( $head );
							if (
								# "Overlong sequences" are those that are syntactically
								# correct but use more UTF-8 bytes than are necessary to
								# encode a character. Naïve string comparisons can be
								# tricked into failing to see a match for an ASCII
								# character, for instance, which can be a security hole
								# if blacklist checks are being used.
								( $n < 0xc2 && $sequence <= Constants::UTF8_OVERLONG_A )
								|| ( $n == 0xe0 && $sequence <= Constants::UTF8_OVERLONG_B )
								|| ( $n == 0xf0 && $sequence <= Constants::UTF8_OVERLONG_C )

								# U+FFFE and U+FFFF are explicitly forbidden in Unicode.
								|| ( $n == 0xef &&
									( $sequence == Constants::UTF8_FFFE )
									|| ( $sequence == Constants::UTF8_FFFF ) )

								# Unicode has been limited to 21 bits; longer
								# sequences are not allowed.
								|| ( $n >= 0xf0 && $sequence > Constants::UTF8_MAX )
							) {
								$replace[] = [ Constants::UTF8_REPLACEMENT,
									$base + $i + 1 - strlen( $sequence ),
									strlen( $sequence ) ];
								$head = '';
								continue;
							}
						}
					}

					if ( isset( $utfCheckOrCombining[$sequence] ) ) {
						# If it's NO or MAYBE, we'll have to rip
						# the string apart and put it back together.
						# That's going to be mighty slow.
						$looksNormal = false;
					}

					# The sequence is legal!
					$head = '';
				} elseif ( $c < "\x80" ) {
					# ASCII byte.
					$head = '';
				} elseif ( $c < "\xc0" ) {
					# Illegal tail bytes
					if ( $head == '' ) {
						# Out of the blue!
						$replace[] = [ Constants::UTF8_REPLACEMENT, $base + $i, 1 ];
					} else {
						# Don't add if we're continuing a broken sequence;
						# we already put a replacement character when we looked
						# at the broken sequence.
						$replace[] = [ '', $base + $i, 1 ];
					}
				} else {
					# Miscellaneous freaks.
					$replace[] = [ Constants::UTF8_REPLACEMENT, $base + $i, 1 ];
					$head = '';
				}
			}
			$base += $chunk;
		}
		if ( count( $replace ) ) {
			# There were illegal UTF-8 sequences we need to fix up.
			$out = '';
			$last = 0;
			foreach ( $replace as $rep ) {
				list( $replacement, $start, $length ) = $rep;
				if ( $last < $start ) {
					$out .= substr( $string, $last, $start - $last );
				}
				$out .= $replacement;
				$last = $start + $length;
			}
			if ( $last < strlen( $string ) ) {
				$out .= substr( $string, $last );
			}
			$string = $out;
		}

		return $looksNormal;
	}
447695
private function prepareMessage(string $string): string
    {
        if (Translator::isMessage($string)) {
            $string = substr($string, 2, -2);
        }

        return $string;
    }
641567
protected function createDisplayNameString($displayName, $shorten = false)
    {
        return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten);
    }
34852
public static function stringToBoolean($string)
    {
        $flag = filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

        if ($flag) {
            return true;
        } elseif (is_null($flag)) {
            return $string;
        }

        return false;
    }
923331
public static function normalizeEndings(string $string, bool $joinMultiple = true): string
    {
        if (!$joinMultiple) {
            return str_replace("\r\n", "\n", $string);
        }

        return preg_replace('/[\n\r]+/', "\n", $string);
    }
905095
public static function isMessage(string $string): bool
    {
        return substr($string, 0, 2) == self::I18N_PREFIX
            && substr($string, -2) == self::I18N_POSTFIX;
    }
442258
public function makeSQLSafe($string)
    {
        $string = str_replace('', '', $string);

        $chunks = explode('.', $string);

        return implode('.', $chunks);
    }