expects PHP code and returns PHP code that will generate escaped string
Optimizes case when PHP string is given.

@return php code
483933
public function htmlchars($php)
    {
        // PHP strings can be escaped at compile time
        if (preg_match('/^\'((?:[^\'{]+|\\\\.)*)\'$/s', $php, $m)) {
            return "'".htmlspecialchars(str_replace('\\\'', "'", $m[1]), ENT_QUOTES, $this->encoding)."'";
        }
        return 'phptal_escape('.$php.', \''.$this->encoding.'\')';
    }
1121133
public final function getPhpCode() : string
   {

      $str = $this->stringValue;

      switch ( $this->typeName )
      {

         case Type::PHP_BOOLEAN:
         case 'boolean':
            return ( $this->value ? 'true' : 'false' );

         case Type::PHP_DOUBLE:
         case Type::PHP_FLOAT:
         case Type::PHP_INTEGER:
         case 'integer':
            return $str;

         case Type::PHP_STRING:
            if ( \preg_match( "~[\r\n\t]+~", $str ) )
            {
               $str = \str_replace(
                  array( '\\',  "\r", "\n", "\t", "\0", '"',  '$' ),
                  array( '\\\\','\\r','\\n','\\t','\\0','\\"','\\$' ),
                  $str
               );
               return '"' . $str . '"';
            }
            return "'" . \str_replace(
                  array( '\\',   "'" ),
                  array( '\\\\', "\\'" ),
                  $str
               )
               . "'";

         case Type::PHP_RESOURCE:
         case Type::PHP_NULL:
         case Type::PHP_UNKNOWN:
            return 'null';

         default:
            $str = \serialize( $this->value );
            if ( \preg_match( "~[\r\n\t]+~", $str ) )
            {
               $str = \str_replace(
                  array( '\\',  "\r", "\n", "\t", "\0", '"',  '$' ),
                  array( '\\\\','\\r','\\n','\\t','\\0','\\"','\\$' ),
                  $str
               );
            }
            else
            {
               $str = \str_replace(
                  array('\\',   '"',   '$'),
                  array('\\\\', '\\"', '\\$'),
                  $str );
            }
            return '\unserialize("' . $str . '")';

      }

   }
57280
public function toCamelCase(): Utility
    {
        // separate existing joined words
        $string = preg_replace('/([a-z0-9])(?=[A-Z])/', '$1 ', $this->string);

        $words = preg_split('/[\W_]/', $string);

        $words = array_map(function ($word) {
            return ucfirst(strtolower($word));
        }, $words);

        $string = lcfirst(implode('', $words));

        return new static($string, $this->encoding);
    }
387849
public function getEscapedString()
    {
        if ($this->escapedString === null) {
            $this->escapedString = str_replace('-', ' ', $this->escape($this->getRawString()));
            $this->escapedString = preg_replace(['/\s+([0-9])/','/\s+/'], ['$1', ' '], $this->escapedString);
        }
        return $this->escapedString;
    }
697707
public static function sep()
    {
        if (static::$sep !== null) {
            return static::$sep;
        }

        if (defined('PHP_EOL')) {
            static::$sep = PHP_EOL;
        } else {
            static::$sep = (strpos(PHP_OS, 'WIN') === false) ? '\n' : '\r\n';
        }

        return static::$sep;
    }
1270555
public function generateVerifyCode(): string
    {
        if ($this->minLength > $this->maxLength) {
            $this->maxLength = $this->minLength;
        }
        if ($this->minLength < 3) {
            $this->minLength = 3;
        }
        if ($this->maxLength > 20) {
            $this->maxLength = 20;
        }
        $length = random_int($this->minLength, $this->maxLength);

        $letters = 'bcdfghjklmnpqrstvwxyz';
        $vowels = 'aeiou';
        $code = '';
        for ($i = 0; $i < $length; ++$i) {
            if (($i % 2 && random_int(0, 10) > 2) || (!($i % 2) && random_int(0, 10) > 9)) {
                $code .= $vowels[random_int(0, 4)];
            } else {
                $code .= $letters[random_int(0, 20)];
            }
        }

        return $code;
    }
381991
public function stringify(): string
    {
        if ($this->isConvertibleToString()) {
            return (string) $this->getValue();
        }

        if ($this->isHashable()) {
            return (string) $this->getValue()->hash();
        }

        return $this->getTypeName();
    }
210926
public function getFormattedString()
    {
        $string = (string) $this->code;

        if (null !== $this->message) {
            $string = $string . ' ' . $this->message;
        }

        return $string;
    }
1254885
function() {
        var str = "",
          quote = exprI(index++),
          closed = false,
          ch;

        while (index < length) {
          ch = exprI(index++);
          if (ch === quote) {
            closed = true;
            break;
          } else if (ch === "\\") {
            // Check for all of the common escape codes
            ch = exprI(index++);
            switch (ch) {
              case "n":
                str += "\n";
                break;
              case "r":
                str += "\r";
                break;
              case "t":
                str += "\t";
                break;
              case "b":
                str += "\b";
                break;
              case "f":
                str += "\f";
                break;
              case "v":
                str += "\x0B";
                break;
              default:
                str += "\\" + ch;
            }
          } else {
            str += ch;
          }
        }

        if (!closed) {
          throwError('Unclosed quote after "' + str + '"', index);
        }

        return {
          type: code.LITERAL,
          value: str,
          raw: quote + str + quote
        };
      }
1156739
public function toStudlyCase(): Utility
    {
        $string = implode(' ', $this->prepareForCasing($this->string));

        $string = str_replace(' ', '', ucwords($string));

        return new static($string, $this->encoding);
    }
19048
protected function generateVerifyCode()
	{
		if($this->minLength > $this->maxLength)
			$this->maxLength = $this->minLength;
		if($this->minLength < 3)
			$this->minLength = 3;
		if($this->maxLength > 20)
			$this->maxLength = 20;
		$length = mt_rand($this->minLength,$this->maxLength);

		$letters = 'bcdfghjklmnpqrstvwxyz';
		$vowels = 'aeiou';
		$code = '';
		for($i = 0; $i < $length; ++$i)
		{
			if($i % 2 && mt_rand(0,10) > 2 || !($i % 2) && mt_rand(0,10) > 9)
				$code.=$vowels[mt_rand(0,4)];
			else
				$code.=$letters[mt_rand(0,20)];
		}

		return $code;
	}
868694
public function generate()
    {
        $alphabet = '';

        if (strpos($this->available_sets, 'l') !== false) {
            $alphabet .= $this->lowercase;
        }

        if (strpos($this->available_sets, 'u') !== false) {
            $alphabet .= $this->uppercase;
        }

        if (strpos($this->available_sets, 'd') !== false) {
            $alphabet .= $this->numbers;
        }

        if (strpos($this->available_sets, 's') !== false) {
            $alphabet .= $this->special_chars;
        }

        $alphamax = strlen($alphabet) - 1;

        if ($alphamax < 1) {
            throw new PasswordException('Invalid alphabet');
        }

        $this->password = '';

        for ($i = 0; $i < $this->length; ++$i) {
            $this->password .= $alphabet[random_int(0, $alphamax)];
        }

        return $this->password;
    }
981415
public function generateCode() {
        $content = "";
        foreach ($this->arrTemplates as $template) {
            if (!file_exists($template)) {
                //Template not found
                continue;
            }
            $content .= file_get_contents($template);
        }
        
        foreach ($this->attributes as $key => $val) {
            $content = str_replace($this->placeHolderStart.$key.$this->placeHolderEnd, $val, $content);
        }
        return $content;
    }
1374156
public function toString()
    {
        if (substr($this->name, -2) === '()') {
            return PHP_EOL . substr($this->name, 0, -2) . '(' . implode($this->glue, $this->elements) . ')';
        } else {
            return PHP_EOL . $this->name . ' ' . implode($this->glue, $this->elements);
        }
    }
180662
protected function generateRandomPassword()
    {
        $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+*=-_/()!?[]{}';
        $password = array();
        $alphabetLength = strlen($alphabet) - 1;
        
        for ($i = 0; $i < 10; $i++) {
            $charIndex = mt_rand(0, $alphabetLength);
            $password[] = $alphabet[$charIndex];
        }
        
        $password = implode('', $password);
        
        if (!preg_match('/\d/', $password)) {
            $password = mt_rand(0, 9) . $password . mt_rand(0, 9);
        }
        
        return $password;
    }
395557
protected function getAudibleCode()
    {
        $letters = array();
        $code    = $this->getCode(true, true);

        if (empty($code) || empty($code['code'])) {
            if (strlen($this->display_value) > 0) {
                $code = array('code' => $this->display_value, 'display' => $this->display_value);
            } else {
                $this->createCode();
                $code = $this->getCode(true);
            }
        }

        if (empty($code)) {
            $error = 'Failed to get audible code (are database settings correct?).  Check the error log for details';
            trigger_error($error, E_USER_WARNING);
            throw new \Exception($error);
        }

        if (preg_match('/(\d+) (\+|-|x) (\d+)/i', $code['display'], $eq)) {
            $math = true;

            $left  = $eq[1];
            $sign  = str_replace(array('+', '-', 'x'), array('plus', 'minus', 'times'), $eq[2]);
            $right = $eq[3];

            $letters = array($left, $sign, $right);
        } else {
            $math = false;

            $length = $this->strlen($code['display']);

            for($i = 0; $i < $length; ++$i) {
                $letter    = $this->substr($code['display'], $i, 1);
                $letters[] = $letter;
            }
        }

        try {
            return $this->generateWAV($letters);
        } catch(\Exception $ex) {
            throw $ex;
        }
    }
202937
function getAudibleCode()
  {
    $letters = array();
    $code    = $this->getCode();

    if ($code == '') {
      $this->createCode();
      $code = $this->getCode();
    }

    for($i = 0; $i < strlen($code); ++$i) {
      $letters[] = $code{$i};
    }

    return $this->generateWAV($letters);
  }