Class constructor from an STL vertex string.

Example vertex string:
outerloop
vertex -71.74323 47.70205 4.666243
vertex -72.13071 47.70205 4.932664
vertex -72.1506 47.2273 4.905148
endloop

@param string $stlVertexString
@return STLVertex
553426
public static function fromString(string $stlVertexString) : STLVertex
    {
        $class = new self();

        preg_match_all("/vertex +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
            $stlVertexString, $matches);

        $coordinates = array(
            array((float)$matches[1][0], (float)$matches[2][0], (float)$matches[3][0]),
            array((float)$matches[1][1], (float)$matches[2][1], (float)$matches[3][1]),
            array((float)$matches[1][2], (float)$matches[2][2], (float)$matches[3][2])
        );

        $class->setCoordinatesArray($coordinates);

        return $class;
    }
1108839
public static function forStringType(int $string_type): self
    {
        $steps = array(
            /* @formatter:off */
            self::STEP_TRANSCODE => new TranscodeStep($string_type), 
            self::STEP_MAP => new MapStep(), 
            self::STEP_NORMALIZE => new NormalizeStep(), 
            self::STEP_PROHIBIT => new ProhibitStep(), 
            self::STEP_CHECK_BIDI => new CheckBidiStep(), 
            // @todo Vary by string type
            self::STEP_INSIGNIFICANT_CHARS => 
                new InsignificantNonSubstringSpaceStep()
            /* @formatter:on */
        );
        return new self($steps);
    }
1353356
protected function parse($str)
    {
        $pos = 0;
        $len = strlen($str);

        // Convert infix operators to postfix using the shunting-yard algorithm.
        $output = array();
        $stack = array();
        while ($pos < $len) {
            $next = substr($str, $pos, 1);

            switch ($next) {
                // Ignore whitespace
                case ' ':
                case "\t":
                    $pos++;
                    break;

                // Variable (n)
                case 'n':
                    $output[] = array('var');
                    $pos++;
                    break;

                // Parentheses
                case '(':
                    $stack[] = $next;
                    $pos++;
                    break;

                case ')':
                    $found = false;
                    while (!empty($stack)) {
                        $o2 = $stack[count($stack) - 1];
                        if ($o2 !== '(') {
                            $output[] = array('op', array_pop($stack));
                            continue;
                        }

                        // Discard open paren.
                        array_pop($stack);
                        $found = true;
                        break;
                    }

                    if (!$found) {
                        throw new Exception('Mismatched parentheses');
                    }

                    $pos++;
                    break;

                // Operators
                case '|':
                case '&':
                case '>':
                case '<':
                case '!':
                case '=':
                case '%':
                case '?':
                    $end_operator = strspn($str, self::OP_CHARS, $pos);
                    $operator = substr($str, $pos, $end_operator);
                    if (!array_key_exists($operator, self::$op_precedence)) {
                        throw new Exception(sprintf('Unknown operator "%s"', $operator));
                    }

                    while (!empty($stack)) {
                        $o2 = $stack[count($stack) - 1];

                        // Ternary is right-associative in C
                        if ($operator === '?:' || $operator === '?') {
                            if (self::$op_precedence[$operator] >= self::$op_precedence[$o2]) {
                                break;
                            }
                        } elseif (self::$op_precedence[$operator] > self::$op_precedence[$o2]) {
                            break;
                        }

                        $output[] = array('op', array_pop($stack));
                    }
                    $stack[] = $operator;

                    $pos += $end_operator;
                    break;

                // Ternary "else"
                case ':':
                    $found = false;
                    $s_pos = count($stack) - 1;
                    while ($s_pos >= 0) {
                        $o2 = $stack[$s_pos];
                        if ($o2 !== '?') {
                            $output[] = array('op', array_pop($stack));
                            $s_pos--;
                            continue;
                        }

                        // Replace.
                        $stack[$s_pos] = '?:';
                        $found = true;
                        break;
                    }

                    if (!$found) {
                        throw new Exception('Missing starting "?" ternary operator');
                    }
                    $pos++;
                    break;

                // Default - number or invalid
                default:
                    if ($next >= '0' && $next <= '9') {
                        $span = strspn($str, self::NUM_CHARS, $pos);
                        $output[] = array('value', intval(substr($str, $pos, $span)));
                        $pos += $span;
                        break;
                    }

                    throw new Exception(sprintf('Unknown symbol "%s"', $next));
            }
        }

        while (!empty($stack)) {
            $o2 = array_pop($stack);
            if ($o2 === '(' || $o2 === ')') {
                throw new Exception('Mismatched parentheses');
            }

            $output[] = array('op', $o2);
        }

        $this->tokens = $output;
    }
34035
public static function fromString($string)
    {
        list($lat, $long) = explode(',', $string);
        return new self($lat, $long);
    }
875256
public function truncate($string, $endlength="30", $end="...")
        {
            $strlen = strlen($string);

            if ($strlen > $endlength) {
                $trim = $endlength - $strlen;
                $string = substr($string, 0, $trim);
                $string .= $end;
            }

            return $string;
        }
618379
static function fromString(string $string): self
    {
        $string = str_replace("/", "\\", $string);
        $string = preg_replace("#(\\\\){2,}#", "\\", $string);
        if (substr($string, -1, 1) == "\\") {
            $string = substr($string, 0, -1);
        }
        
        return new self($string);
    }
164109
public static function fromString(string $string): self
    {
        $stringHeaders = explode(SourceInterface::DELIMETER_HEADER, $string);
        $headers       = [];

        foreach ($stringHeaders as $value) {
            [$name, $valueRow] = explode(SourceInterface::DELIMETER_HEADER_ROW, $value);

            $headers[$name] = $valueRow;
        }

        return new self($headers);
    }
487005
public function createNodeFromNQuads($string)
    {
        $regex = '/'.$this->getRegexStringForNodeRecognition(
            true, true, true, true, true, true
        ).'/si';

        $string = trim($string);

        preg_match($regex, $string, $matches);

        if (0 == count($matches)) {
            throw new \Exception('Invalid parameter $string given. Our regex '.$regex.' doesnt apply.');
        }

        $firstChar = substr($matches[0], 0, 1);

        // http://...
        if ('<' == $firstChar) {
            return $this->createNamedNode(str_replace(['<', '>'], '', $matches[1]));
        // ".."^^<
        } elseif (false !== strpos($matches[0], '"^^<')) {
            return $this->createLiteral($matches[9], $matches[10]);
        // "foo"@en
        } elseif (false !== strpos($matches[0], '"@')) {
            return $this->createLiteral($matches[12], null, $matches[13]);
        // "foo"
        } elseif ('"' == $firstChar) {
            return $this->createLiteral($matches[15]);
        // _:foo
        } elseif ($this->simpleCheckBlankNodeId($matches[0])) {
            return $this->createBlankNode($matches[4]);
        // 0-9 (simple number, multi digits)
        } elseif (0 < (int) $matches[0]) {
            return $this->createLiteral(
                $matches[16],
                $this->createNamedNode('http://www.w3.org/2001/XMLSchema#double')
            );
        } else {
            throw new \Exception('Unknown case for: '.$matches[1]);
        }
        throw new \Exception("The given string (\"$string\") is not valid or doesn't represent any RDF node");
    }
627026
public function hex2bin($hexString)
    {
        $pos = 0;
        $result = '';
        while ($pos < strlen($hexString)) {
            if (strpos(" \t\n\r", $hexString[$pos]) !== false) {
                ++$pos;
            } else {
                $code = hexdec(substr($hexString, $pos, 2));
                $pos += 2;
                $result .= chr($code);
            }
        }

        return $result;
    }
818818
public static function constructFromString($str) {
		$str = strtoupper($str);
		$i = substr($str, -1) == 'I';

		preg_match('/^T[0-9]{1,}/', $str, $matches);
//		print_r($matches);
		$r = $matches[0];

		return new PitchClassSetTransformation($r, $i);
	}
1340350
public static function fromString($str)
    {
        $stringset = new Stringset();

        $entry = array();
        $state = null;
        $line = 1;

        foreach (explode("\n", $str) as $line) {
            $line = trim($line);
            if (strlen($line) === 0) {
                if (count($entry) > 0) {
                    $stringset->add($entry);
                    $entry = array();
                    $state = null;
                }
                continue;
            }

            if ($line[0] === '#' && $line[1] === ',') {
                $entry['flags'] = array_map('trim', explode(',', substr($line, 2)));
            } else if ($line[0] !== '#') {
                // non-comment
                list($key, $rest) = explode(' ', $line, 2);
                switch ($key) {
                    case 'msgid':
                    case 'msgid_plural':
                    case 'msgstr':
                    case 'msgctxt':
                        if (strpos($state, 'msgstr') === 0 && $key !== 'msgstr' && count($entry) > 0) {
                            $stringset->add($entry);
                            $entry = array();
                        }
                        $state = $key;
                        $entry[$key] = self::parseString($rest);
                        break;
                    default:
                        if (strpos($key, 'msgstr[') === 0) {
                            $state = $key;
                            $entry[$key] = self::parseString($rest);
                        } else {
                            $entry[$state] .= self::parseString(trim($line));
                        }
                }
            }
            $line += 1;
        }
        return $stringset;
    }
378939
public static function makeByString($string)
    {
        $fg = $bg = '';
        $extra = false;
        $options = [];
        $parts = \explode(';', \str_replace(' ', '', $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 'extra':
                    $extra = (bool)$subParts[1];
                    break;
                case 'options':
                    $options = \explode(',', $subParts[1]);
                    break;
                default:
                    throw new \RuntimeException('Invalid option');
                    break;
            }
        }

        return new self($fg, $bg, $options, $extra);
    }
638897
public static function convertStringToPrefix($string) {
    $words = explode(' ', $string);
    $prefix = '';
    foreach ($words as $word) {
      $prefix .= substr($word, 0, 1);
    }
    return strtoupper($prefix);
  }
144488
public static function convertNodeStr($str): string
    {
        $str = \trim($str, '-');

        // convert 'first-second' to 'firstSecond'
        if (\strpos($str, '-')) {
            $str = (string)\preg_replace_callback('/-+([a-z])/', function ($c) {
                return \strtoupper($c[1]);
            }, \trim($str, '- '));
        }

        return $str;
    }
127249
public static function fromPEMString(string $str): self
    {
        $pems = PEMBundle::fromString($str)->all();
        return self::fromPEMs(...$pems);
    }
896957
static public function strToCamelCase($string)
	{
		$string = self::strToLowerUrl($string, false);

		$string = implode('', array_map('ucfirst', explode('_', $string)));
		$string = implode('', array_map('ucfirst', explode('-', $string)));

		return strtolower(substr($string, 0, 1)) . substr($string, 1);
	}
527705
public function ensureLeft($substring) {
        $stringy = self::create($this->str, $this->encoding);

        if (!$stringy->startsWith($substring))
            $stringy->str = $substring . $stringy->str;

        return $stringy;
    }