@param string $string
@param int $spaces
@param null $options

@return IOutput
165707
public function writeIndented($string, $spaces = 2, $options = null) {
        return $this->write($this->indent($string, $spaces), $options);
    }
1080127
public function normalizeCmsDatabaseString($string, $spaceSubstitute = '_')
    {
        $string = html_entity_decode($string);

        $string = mb_convert_encoding($string, "ISO-8859-1", 'UTF-8');

        $string = preg_replace('#\s+#', $spaceSubstitute, $string);

        $string = $this->normalizeCmsAccents($string);

        $string = preg_replace('#[^0-9a-z' . preg_quote($spaceSubstitute) . ']#i', '', $string);
        $string = preg_replace('#[' . preg_quote($spaceSubstitute) . ']+#', $spaceSubstitute, $string);

        $string = preg_replace('#\s+#', $spaceSubstitute, $string);

        $string = trim($string, $spaceSubstitute);

        return $string;
    }
551703
public function load($str, $options = [])
    {
        // check if it's a file
        if (strpos($str, "\n") === false && is_file($str)) {
            return $this->loadFromFile($str, $options);
        }
        // check if it's a url
        if (preg_match("/^https?:\/\//i", $str)) {
            return $this->loadFromUrl($str, $options);
        }

        return $this->loadStr($str, $options);
    }
1349901
public function indentString($str, $spaces)
    {
        if (!$str) {
            return null;
        }

        if ($spaces === 0) {
            return $str;
        }

        $lines = explode("\n", $str);

        foreach ($lines as &$line) {
            $line = sprintf('%\' ' . $spaces . 's%s', '', $line);
        }

        return implode("\n", $lines);
    }
210303
protected static function mcryptDecrypt($key, $string, $options)
	{
		$debug = \bdk\Debug::getInstance();
		if (Str::isBase64Encoded($string)) {
			$debug->log('base64 decoding crypt text');
			$string = base64_decode($string);
		}
		$iv		= substr($string, 0, $options['iv_size']);
		$string	= substr($string, $options['iv_size']);
		if ($string && strlen($iv) == $options['iv_size']) {
			$string	= mcrypt_decrypt($options['cipher'], $key, $string, $options['mode'], $iv);
		}
		// now remove any padding
		$last_chr = ord(substr($string, -1));
		#$debug->log('last_chr', $last_chr);
		$method_used = 0;
		if ($last_chr > 0 && $last_chr <= $options['block_size']) {
			$remove = substr($string, -$last_chr);
			if ($remove == str_repeat(chr($last_chr), $last_chr)) {
				$method_used = 1;
			} elseif ($remove == str_repeat(chr(0), $last_chr-1).chr($last_chr)) {
				$method_used = 3;
			}
			if ($method_used) {
				$string = substr($string, 0, -$last_chr);
			}
		} elseif ($last_chr == 0 && preg_match('/\x00{1,'.$options['block_size'].'}$/', $string, $matches)) {
			$remove = $matches[0];
			$length = strlen($remove);
			$string = substr($string, 0, -$length);
			$method_used = 4;
			if ($length < $options['block_size'] && ord(substr($string, -1)) == 0x80) {
				$method_used = 2;
				$remove = chr(0x80).$remove;
				$string = substr($string, 0, -1);
			}
		}
		if ($method_used) {
			$debug->log('padding removed ('.trim(chunk_split(bin2hex($remove), 2, ' ')).'), method', $method_used);
		}
		return $string;
	}
461225
public function fromString($string)
    {
        $fs = new Filesystem();
        $dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'gush';

        if (!file_exists($dir)) {
            $fs->mkdir($dir);
        }

        $tmpName = tempnam($dir, '');
        file_put_contents($tmpName, $string);
        $editor = getenv('EDITOR');

        if (!$editor) {
            throw new \RuntimeException('No EDITOR environment variable set.');
        }

        if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
            $processHelper = $this->getHelperSet()->get('process');
            /** @var ProcessHelper $processHelper */
            $process = $processHelper->getProcessBuilder($editor.' '.escapeshellarg($tmpName))->getProcess();
            $process->setTimeout(null);
            $process->start();

            // Wait till editor closes
            $process->wait();
        } else {
            system($editor.' '.$tmpName.' > `tty`');
        }

        $contents = file_get_contents($tmpName);
        $fs->remove($tmpName);

        return $contents;
    }
487567
public function deserialize($string, array $options=[])
    {
        if (!is_string($string)) {
            throw new UnexpectedValueException('I can only work with strings, not ' . Type::of($string));
        }

        return $string;
    }
1178621
private static function makePart($string, $position, $length = null, $offset_capture = false)
    {
        $cut = mb_strcut($string, $position, $length);

        return $offset_capture
            ? [$cut, $position]
            : $cut;
    }
1334426
public function evaluateStringOrExpression($string, array &$availableVars)
    {
        $regex = '/^eval: (?P<expr>.+)$/i';
        $success = preg_match($regex, $string, $matches);

        if (!$success) {
            return $string;
        }

        $vars = $availableVars;
        if (array_key_exists(self::CONTEXT_VARS, $availableVars)) {
            $vars = array_merge($availableVars, $availableVars[self::CONTEXT_VARS]);
        }

        return $this->evaluator->evaluateWithVars($matches['expr'], $vars);
    }
1109953
public function load(string $type, string $context, $contextId = null, array $options = null)
    {
        $user = null;
        if ($this->tokenStorage->getToken()->getUser() instanceof User) {
            $user = $this->tokenStorage->getToken()->getUser();
        }

        $workspace = null;
        if (DataSource::CONTEXT_WORKSPACE === $context) {
            $workspace = $this->om
                ->getRepository(Workspace::class)
                ->findOneBy(['uuid' => $contextId]);
        }

        /** @var GetDataEvent $event */
        $event = $this->eventDispatcher->dispatch(
            'data_source.'.$type.'.load',
            GetDataEvent::class,
            [$context, $options, $user, $workspace]
        );

        return $event->getData();
    }
1034521
function hash($string) {
		$options = [];
		if (!is_null($this->cost))
			$options	= ['cost'	=> $this->cost];
		
		return password_hash($string, PASSWORD_DEFAULT, $options);
	}
1108838
public static function fromString($string)
	{
		$fg      = '';
		$bg      = '';
		$options = array();

		$parts = explode(';', $string);

		foreach ($parts as $part)
		{
			$subParts = explode('=', $part);

			if (\count($subParts) < 2)
			{
				continue;
			}

			switch ($subParts[0])
			{
				case 'fg':
					$fg = $subParts[1];

					break;

				case 'bg':
					$bg = $subParts[1];

					break;

				case 'options':
					$options = explode(',', $subParts[1]);

					break;

				default:
					throw new \RuntimeException('Invalid option');

					break;
			}
		}

		return new self($fg, $bg, $options);
	}
1119967
public Output compileString(String string, URI inputPath, URI outputPath, Options options)
      throws CompilationException {
    StringContext context = new StringContext(string, inputPath, outputPath, options);

    return compile(context);
  }
859317
protected static function parseString(string $string, array $values, Settings $options) : string
    {
        $output = str_replace(array_map(function ($value) use ($options) {
            return $options->leftSeparator . $value . $options->rightSeparator;
        }, array_keys($values)), array_values($values), $string);

        if ($options->removeUnparsed
            && strpos($output, $options->leftSeparator) !== false
            && strpos($output, $options->rightSeparator) !== false) {
            $output = preg_replace(
                sprintf('/%s([a-zA-Z0-9_\\.\\-]+)%s/', $options->leftSeparator, $options->rightSeparator),
                $options->unparsedReplacement,
                $output
            );
        }

        if ($options->removeExtraSpaces) {
            $output = preg_replace('/\s+/', ' ', $output);
        }

        return trim($output);
    }
1250745
public function input($options = [])
    {
        if (is_string($options)) {
            $options = ['class' => $options];
        }

        $input = new Input($this->expression('input'), $options);

        return $input;
    }
245367
public function parse($string, array $vars = [])
    {
        $output = $string;

        if(is_file($string)) {
            $output = file_get_contents($string);
        }

        if($this->count()) {
            foreach($this->registry as $adapter) {
                if($adapter instanceof Abstracts\AbstractAdapter) {
                    if($adapter->isSupported()) {
                        $adapter->initialize();
                        $adapter->loadString($output);
                        $output = $adapter->parse($vars);
                    }
                }
            }
        }

        return $output;
    }
965471
public function indent($string, $spaces = 2) {
        $indentation = str_repeat(' ', $spaces);
        $lines = explode("\n", $string);

        foreach ($lines as $index => $line) {
            $lines[$index] = $indentation . $line;
        }

        return implode("\n", $lines);
    }