Extracts the ~ value from the $text at the $pos.
If the tilde is not ~~, ~F1, ~F2, ~F3, ~F4; an error is raised.

@param string $text
@param int $pos
@return string
14975
private static function extractTilde($text, $pos) {
        if ($text[$pos] === '~') {
            if (isset($text[$pos + 1])) {
                // Do we have a tilde?
                if ($text[$pos + 1] === '~') {
                    return '~~';
                } elseif ($text[$pos + 1] === 'F') {
                    // Do we have a number after?
                    if (isset($text[$pos + 2])) {
                        $v = intval($text[$pos + 2]);
                        if ($v >= 1 && $v <= 4) {
                            return '~F' . $v;
                        } else {
                            throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.');
                        }
                    } else {
                        throw new CINParseException('code128', 'Bad ~F. You must provide a number from 1 to 4.');
                    }
                } else {
                    throw new CINParseException('code128', 'Wrong code after the ~.');
                }
            } else {
                throw new CINParseException('code128', 'Wrong code after the ~.');
            }
        } else {
            throw new CINParseException('code128', 'There is no ~ at this location.');
        }
    }
1134779
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getTitle();
                break;
            case 2:
                return $this->getSlug();
                break;
            case 3:
                return $this->getSportId();
                break;
            case 4:
                return $this->getDescription();
                break;
            default:
                return null;
                break;
        } // switch()
    }
200630
public function unserialize($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as $line) {
            $data = explode(':', $line);
            if (count($data) < 2) {
                continue;
            }
            $key = trim($data[0]);
            if (isset($data[1]) && (strlen($data[1]) > 0)) {
                $value = trim($data[1]);
            } else {
                $value = '?';
            }
            if (strcasecmp($key, 'set') === 0) {
                $data = explode('=', $value);
                $key = trim($data[0]);
                if (isset($data[1]) && (strlen($data[1]) > 0)) {
                    $value = trim($data[1]);
                } else {
                    $value = '?';
                }
                $this->setVariable($key, $value);
            } else {
                $this->setParameter($key, $value);
            }
        }
    }
64312
public function keyValueFromString($text)
    {
        // Match colon separator outside of quoted substrings
        // Fallback to nearest semicolon outside of quoted substrings, if colon cannot be found
        // Do not try and match within the value paired with the keyword
        preg_match('/(.*?)(?::(?=(?:[^"]*"[^"]*")*[^"]*$)|;(?=[^:]*$))([\w\W]*)/', htmlspecialchars($text, ENT_QUOTES, 'UTF-8'), $matches);

        if (count($matches) == 0) {
            return false;
        }

        if (preg_match('/^([A-Z-]+)([;][\w\W]*)?$/', $matches[1])) {
            $matches = array_splice($matches, 1, 2); // Remove first match and re-align ordering

            // Process properties
            if (preg_match('/([A-Z-]+)[;]([\w\W]*)/', $matches[0], $properties)) {
                array_shift($properties); // Remove first match
                $matches[0] = $properties[0]; // Fix to ignore everything in keyword after a ; (e.g. Language, TZID, etc.)
                array_shift($properties); // Repeat removing first match

                $formatted = [];
                foreach ($properties as $property) {
                    preg_match_all('~[^\r\n";]+(?:"[^"\\\]*(?:\\\.[^"\\\]*)*"[^\r\n";]*)*~', $property, $attributes); // Match semicolon separator outside of quoted substrings
                    $attributes = (sizeof($attributes) == 0) ? [$property] : reset($attributes); // Remove multi-dimensional array and use the first key

                    foreach ($attributes as $attribute) {
                        preg_match_all('~[^\r\n"=]+(?:"[^"\\\]*(?:\\\.[^"\\\]*)*"[^\r\n"=]*)*~', $attribute, $values); // Match equals sign separator outside of quoted substrings
                        $value = (sizeof($values) == 0) ? null : reset($values); // Remove multi-dimensional array and use the first key

                        if (is_array($value) && isset($value[1])) {
                            $formatted[$value[0]] = trim($value[1], '"'); // Remove double quotes from beginning and end only
                        }
                    }
                }

                $properties[0] = $formatted; // Assign the keyword property information

                array_unshift($properties, $matches[1]); // Add match to beginning of array
                $matches[1] = $properties;
            }

            return $matches;
        }

        return false; // Ignore this match
    }
631652
public function text($path=null, $pos=0) {
		if($this->xpath === null)
			return null;
		if(!$path)
			return trim($this->domnode->nodeValue);
		else {
			$item = $this->item($path, $pos);
			if($item === null)
				return null;
			return $item->text();
		}
	}
1204495
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getSourceId();
                break;
            case 2:
                return $this->getPageid();
                break;
            case 3:
                return $this->getTitle();
                break;
            case 4:
                return $this->getFiles();
                break;
            case 5:
                return $this->getSubcats();
                break;
            case 6:
                return $this->getPages();
                break;
            case 7:
                return $this->getSize();
                break;
            case 8:
                return $this->getHidden();
                break;
            case 9:
                return $this->getCreatedAt();
                break;
            case 10:
                return $this->getUpdatedAt();
                break;
            case 11:
                return $this->getTreeLeft();
                break;
            case 12:
                return $this->getTreeRight();
                break;
            case 13:
                return $this->getTreeLevel();
                break;
            default:
                return null;
                break;
        } // switch()
    }
86167
private function tokenize($text)
    {
        $count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
        if(false === $count || preg_last_error() !== PREG_NO_ERROR) {
            throw new \RuntimeException(sprintf('PCRE failure `%s`.', preg_last_error()));
        }

        $tokens = array();
        $position = 0;

        foreach($matches as $match) {
            switch(true) {
                case -1 !== $match['string'][1]: { $token = $match['string'][0]; $type = self::TOKEN_STRING; break; }
                case -1 !== $match['ws'][1]: { $token = $match['ws'][0]; $type = self::TOKEN_WS; break; }
                case -1 !== $match['marker'][1]: { $token = $match['marker'][0]; $type = self::TOKEN_MARKER; break; }
                case -1 !== $match['delimiter'][1]: { $token = $match['delimiter'][0]; $type = self::TOKEN_DELIMITER; break; }
                case -1 !== $match['separator'][1]: { $token = $match['separator'][0]; $type = self::TOKEN_SEPARATOR; break; }
                case -1 !== $match['open'][1]: { $token = $match['open'][0]; $type = self::TOKEN_OPEN; break; }
                case -1 !== $match['close'][1]: { $token = $match['close'][0]; $type = self::TOKEN_CLOSE; break; }
                default: { throw new \RuntimeException(sprintf('Invalid token.')); }
            }
            $tokens[] = array($type, $token, $position);
            $position += mb_strlen($token, 'utf-8');
        }

        return $tokens;
    }
234612
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getLocale();
                break;
            case 2:
                return $this->getLabel();
                break;
            default:
                return null;
                break;
        } // switch()
    }
730823
protected function replaceTextTokens($text)
    {
        foreach ($this->tokens as $key => $val) {
            $text = str_replace('<' . $key . '>', $val, $text);
        }

        return $text;
    }
399324
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getCode();
                break;
            case 1:
                return $this->getAtosCode();
                break;
            case 2:
                return $this->getDecimals();
                break;
            default:
                return null;
                break;
        } // switch()
    }
385018
protected String splitNear (String text, int pos)
    {
        if (pos >= text.length()) {
            return text;
        }

        int forward = text.indexOf(' ', pos);
        int backward = text.lastIndexOf(' ', pos);

        int newpos = (Math.abs(pos - forward) < Math.abs(pos - backward)) ? forward : backward;

        // if we couldn't find a decent place to split, just do it wherever
        if (newpos == -1) {
            newpos = pos;

        } else {
            // actually split the space onto the first part
            newpos++;
        }
        return text.substring(0, newpos);
    }
180987
public function text($path=null, $pos=0) {
		if($path === null) {
			$res = '';
			foreach($this->items('/*') as $i)
				$res .= $i->text();
			return $res;
		}
		else
			return $this->item($path, $pos)->text();
	}
1110871
public function getValueForPosition($pos) {
        return (isset($this->cells[$pos])) ? $this->cells[$pos]->getValue(): null;
    }
608714
function(text, pos) {
			var result = this.find(text, pos);
			if (result && result.type == 'tag') {
				return result;
			}
		}
1131200
public function prompt($text) {

        // send out any escaping to implement anything sitting in the desired state
        $this->outputEscapeSequence();

        // save off the prompt string
        $prompt = $text  . $this->promptCaret . " ";

        // prompt and return the answer
        return $this->readUserInput($prompt);

    }
890219
public function findNextStringPosition($text, $apos = null) {
		if ($apos === null) {
			$pos = $this->getCurrentPosition();
		} else {
			$pos = $apos;
		}
		$pos += 1; // Start from the token following the current position

		$nbTokens = count($this->tokens);
		while ($pos < $nbTokens) {
			$token = $this->tokens[$pos];

			if ($text === $token->text) {
				return $pos;
			}

			$pos ++;
		}

		return null;
	}
1272664
public function parse(string $text) : string
    {
        if ($text === '')
            throw new ParseException($this, $text, 0, self::NO_EMPTY);
        return $text;
    }