Creates a phoneme element with the given data as attributes.

@param string $alphabet
@param string $ph
@param string $text

@return Phoneme
516217
public static function factory(string $alphabet, string $ph, string $text): Phoneme
    {
        $instance = new static();
        $instance->alphabet = $alphabet;
        $instance->ph = $ph;
        $instance->text = $text;

        return $instance;
    }
806436
public static function nameToHtmlAttribute(string $text): string
    {
        if (isset(self::$textToHtmlAttributeCache[$text])) {
            return self::$textToHtmlAttributeCache[$text];
        }

        return self::$textToHtmlAttributeCache[$text] = preg_replace('/[^a-zA-Z0-9\_]+/', '_', $text);
    }
343164
public function addText($text, $pos = '20x20', $padding = 0, $fontColor = '#fff', $fontSize = 12, $angle = 0, $font = null)
		# Author:     Jarrod Oberto
		# Date:       18-11-09
		# Purpose:    Add text to an image
		# Param in:
		# Param out:
		# Reference:  http://php.net/manual/en/function.imagettftext.php
		# Notes:      Make sure you supply the font.
		#
	{

		// *** Convert color
		$rgbArray = $this->formatColor($fontColor);
		$r = $rgbArray['r'];
		$g = $rgbArray['g'];
		$b = $rgbArray['b'];

		// *** Get text font
		$font = $this->getTextFont($font);

		// *** Get text size
		$textSizeArray = $this->getTextSize($fontSize, $angle, $font, $text);
		$textWidth = $textSizeArray['width'];
		$textHeight = $textSizeArray['height'];

		// *** Find co-ords to place text
		$posArray = $this->calculatePosition($pos, $padding, $textWidth, $textHeight, false);
		$x = $posArray['width'];
		$y = $posArray['height'];

		$fontColor = imagecolorallocate($this->imageResized, $r, $g, $b);

		// *** Add text
		imagettftext($this->imageResized, $fontSize, $angle, $x, $y, $fontColor, $font, $text);
	}
1345708
def set_alphabet(self, alphabet):
        """"""

        # Turn the alphabet into a set and sort it to prevent duplicates
        # and ensure reproducibility.
        new_alphabet = list(sorted(set(alphabet)))
        if len(new_alphabet) > 1:
            self._alphabet = new_alphabet
            self._alpha_len = len(self._alphabet)
        else:
            raise ValueError("Alphabet with more than " "one unique symbols required.")
548625
public function loadGrammar(string $text): Grammar
    {
        $this->symbols = [];
        $this->inline = [];
        $this->regexpMap = [];
        $this->defines = [];
        $this->whitespaces = [];
        $this->modifiers = null;

        try {
            /** @var Rule[] $rules */
            $rules = $this->parser->parse($text, $this->actions)->made();

            /** @var int[] $subject_rules_count */
            $subject_rules_count = [];
            /** @var int[] $inline_ref_count */
            $inline_ref_count = [];
            /** @var Rule[] $inline_ref_rule */
            $inline_ref_rule = [];

            $non_terminal_is_hidden = [];
            $hidden_non_terminals = [];

            foreach ($rules as $rule) {
                $subject = $rule->getSubject();
                $subject_name = $subject->getName();
                $subject_hidden = $subject->isHidden();

                // RegExp tokens cannot be non-terminals in the same time
                // since there is no anonymous RegExp terminals
                if (isset($this->regexpMap[$subject_name])) {
                    throw new GrammarException(
                        "Symbol `$subject_name` defined as non-terminal and as regexp terminal in the same time"
                    );
                }

                if (isset($non_terminal_is_hidden[$subject_name])) {
                    if ($subject_hidden !== $non_terminal_is_hidden[$subject_name]) {
                        throw new GrammarException(
                            "Symbol `$subject_name` defined both as hidden and as visible"
                        );
                    }
                } else {
                    $non_terminal_is_hidden[$subject_name] = $subject_hidden;
                }

                $subject_rules_count[$subject_name] = ($subject_rules_count[$subject_name] ?? 0) + 1;

                if ($subject_hidden) {
                    $hidden_non_terminals[$subject_name] = true;
                }

                foreach ($rule->getDefinition() as $symbol) {
                    $name = $symbol->getName();
                    if (isset($this->inline[$name])) {
                        $inline_ref_count[$name] = ($inline_ref_count[$name] ?? 0) + 1;

                        // it is needed in case of the only reference,
                        // so array of an subject is not needed
                        $inline_ref_rule[$name] = $rule;
                    }
                }
            }

            foreach ($hidden_non_terminals as $name => $_) {
                if (isset($this->symbols[$name][false])) {
                    $this->symbols[$name][false]->setIsHidden(true);
                }
            }

            // Convert non-terminals defined only once with inline tokens
            // `Subject: "inline"`
            // into fixed terminals
            $fixed = [];
            foreach ($inline_ref_count as $inline_token => $ref_count) {
                if (1 !== $ref_count) {
                    continue;
                }

                $rule = $inline_ref_rule[$inline_token];
                if (null === $rule->getTag() && 1 === count($rule->getDefinition())) {
                    $subject = $rule->getSubject();
                    $name = $subject->getName();

                    if (1 !== $subject_rules_count[$name]) {
                        continue;
                    }

                    // remove rule
                    $key = array_search($rule, $rules, true);
                    if (false !== $key) {
                        unset($rules[$key]);
                    }

                    // remove inline
                    unset($this->inline[$inline_token]);

                    // make terminal
                    $subject->setIsTerminal(true);
                    if (isset($this->symbols[$name][!$subject->isHidden()])) {
                        $this->symbols[$name][!$subject->isHidden()]->setIsTerminal(true);
                    }

                    $fixed[$name] = $inline_token;
                }
            }

            return new Grammar(
                $rules,
                $this->inline,
                $fixed,
                $this->regexpMap,
                $this->whitespaces,
                $this->defines,
                $this->modifiers ?? ''
            );
        } catch (UnknownCharacterException | UnexpectedInputAfterEndException | UnexpectedTokenException $e) {
            throw new GrammarException(
                'Cannot parse grammar: ' . $e->getMessage() . ' at offset ' . $e->getOffset(),
                0,
                $e
            );
        } catch (AbortedException $e) {
            for ($inner = $e; $inner; $inner = $inner->getPrevious()) {
                if ($inner instanceof GrammarException || $inner instanceof InternalException) {
                    throw $inner;
                }
            }
            throw new InternalException('Failure while parsing your grammar text', 0, $e);
        } finally {
            $this->symbols = null;
            $this->inline = null;
            $this->regexpMap = null;
            $this->defines = null;
            $this->whitespaces = null;
            $this->modifiers = null;
        }
    }
636117
public function addText(Text $text, $angle = 0) {
        $color = $this->getColorWithRGB($text->color);
        if (is_string($text->font) && is_file($text->font)) {
            imagettftext($this->image, $text->size, $angle,
                $text->x, $text->y, $color, $text->font, $text->content);
            return $this;
        }
        imagestring($this->image, intval($text->font), $text->x, $text->y,
            $text->content, $color);
        return $this;
    }
27792
function slug($text) {
		return trim(strtolower(preg_replace('/([^\pL\pN])+/u','-',
			trim(strtr($text,Base::instance()->DIACRITICS+$this->diacritics())))),'-');
	}
441773
public static function encode($text, $charset = 'UTF-8')
    {
        $charset = Horde_String::lower($charset);
        $text = Horde_String::convertCharset($text, 'UTF-8', $charset);

        $encoded = $is_encoded = false;
        $lwsp = $word = null;
        $out = '';

        /* 0 = word unencoded
         * 1 = word encoded
         * 2 = spaces */
        $parts = array();

        /* Tokenize string. */
        for ($i = 0, $len = strlen($text); $i < $len; ++$i) {
            switch ($text[$i]) {
            case "\t":
            case "\r":
            case "\n":
                if (!is_null($word)) {
                    $parts[] = array(intval($encoded), $word, $i - $word);
                    $word = null;
                } elseif (!is_null($lwsp)) {
                    $parts[] = array(2, $lwsp, $i - $lwsp);
                    $lwsp = null;
                }

                $parts[] = array(0, $i, 1);
                break;

            case ' ':
                if (!is_null($word)) {
                    $parts[] = array(intval($encoded), $word, $i - $word);
                    $word = null;
                }
                if (is_null($lwsp)) {
                    $lwsp = $i;
                }
                break;

            default:
                if (is_null($word)) {
                    $encoded = false;
                    $word = $i;
                    if (!is_null($lwsp)) {
                        $parts[] = array(2, $lwsp, $i - $lwsp);
                        $lwsp = null;
                    }

                    /* Check for MIME encoding delimiter. Encode it if
                     * found. */
                    if (($text[$i] === '=') &&
                        (($i + 1) < $len) &&
                        ($text[$i +1] === '?')) {
                        ++$i;
                        $encoded = $is_encoded = true;
                    }
                }

                /* Check for 8-bit characters or control characters. */
                if (!$encoded) {
                    $c = ord($text[$i]);
                    if ($encoded = (($c & 0x80) || ($c < 32))) {
                        $is_encoded = true;
                    }
                }
                break;
            }
        }

        if (!$is_encoded) {
            return $text;
        }

        if (is_null($lwsp)) {
            $parts[] = array(intval($encoded), $word, $len);
        } else {
            $parts[] = array(2, $lwsp, $len);
        }

        /* Combine parts into MIME encoded string. */
        for ($i = 0, $cnt = count($parts); $i < $cnt; ++$i) {
            $val = $parts[$i];

            switch ($val[0]) {
            case 0:
            case 2:
                $out .= substr($text, $val[1], $val[2]);
                break;

            case 1:
                $j = $i;
                for ($k = $i + 1; $k < $cnt; ++$k) {
                    switch ($parts[$k][0]) {
                    case 0:
                        break 2;

                    case 1:
                        $i = $k;
                        break;
                    }
                }

                $encode = '';
                for (; $j <= $i; ++$j) {
                    $encode .= substr($text, $parts[$j][1], $parts[$j][2]);
                }

                $delim = '=?' . $charset . '?b?';
                $e_parts = explode(
                    self::EOL,
                    rtrim(
                        chunk_split(
                            base64_encode($encode),
                            /* strlen($delim) + 2 = space taken by MIME
                             * delimiter */
                            intval((75 - strlen($delim) + 2) / 4) * 4
                        )
                    )
                );

                $tmp = array();
                foreach ($e_parts as $val) {
                    $tmp[] = $delim . $val . '?=';
                }

                $out .= implode(' ', $tmp);
                break;
            }
        }

        return rtrim($out);
    }
239476
public static function toHtml($text)
    {
        $text = htmlspecialchars($text);
        $text = nl2br(str_replace(' ', '&nbsp;', $text));
        return $text; //define in QuickPHP\Libs\CoreFunction.inc.php
    }
33780
function slug($text) {
		return trim(strtolower(preg_replace('/([^\pL\pN])+/u','-',
			trim(strtr(str_replace('\'','',$text),
			array(
				'Ǎ'=>'A','А'=>'A','Ā'=>'A','Ă'=>'A','Ą'=>'A','Å'=>'A',
				'Ǻ'=>'A','Ä'=>'Ae','Á'=>'A','À'=>'A','Ã'=>'A','Â'=>'A',
				'Æ'=>'AE','Ǽ'=>'AE','Б'=>'B','Ç'=>'C','Ć'=>'C','Ĉ'=>'C',
				'Č'=>'C','Ċ'=>'C','Ц'=>'C','Ч'=>'Ch','Ð'=>'Dj','Đ'=>'Dj',
				'Ď'=>'Dj','Д'=>'Dj','É'=>'E','Ę'=>'E','Ё'=>'E','Ė'=>'E',
				'Ê'=>'E','Ě'=>'E','Ē'=>'E','È'=>'E','Е'=>'E','Э'=>'E',
				'Ë'=>'E','Ĕ'=>'E','Ф'=>'F','Г'=>'G','Ģ'=>'G','Ġ'=>'G',
				'Ĝ'=>'G','Ğ'=>'G','Х'=>'H','Ĥ'=>'H','Ħ'=>'H','Ï'=>'I',
				'Ĭ'=>'I','İ'=>'I','Į'=>'I','Ī'=>'I','Í'=>'I','Ì'=>'I',
				'И'=>'I','Ǐ'=>'I','Ĩ'=>'I','Î'=>'I','Ĳ'=>'IJ','Ĵ'=>'J',
				'Й'=>'J','Я'=>'Ja','Ю'=>'Ju','К'=>'K','Ķ'=>'K','Ĺ'=>'L',
				'Л'=>'L','Ł'=>'L','Ŀ'=>'L','Ļ'=>'L','Ľ'=>'L','М'=>'M',
				'Н'=>'N','Ń'=>'N','Ñ'=>'N','Ņ'=>'N','Ň'=>'N','Ō'=>'O',
				'О'=>'O','Ǿ'=>'O','Ǒ'=>'O','Ơ'=>'O','Ŏ'=>'O','Ő'=>'O',
				'Ø'=>'O','Ö'=>'Oe','Õ'=>'O','Ó'=>'O','Ò'=>'O','Ô'=>'O',
				'Œ'=>'OE','П'=>'P','Ŗ'=>'R','Р'=>'R','Ř'=>'R','Ŕ'=>'R',
				'Ŝ'=>'S','Ş'=>'S','Š'=>'S','Ș'=>'S','Ś'=>'S','С'=>'S',
				'Ш'=>'Sh','Щ'=>'Shch','Ť'=>'T','Ŧ'=>'T','Ţ'=>'T','Ț'=>'T',
				'Т'=>'T','Ů'=>'U','Ű'=>'U','Ŭ'=>'U','Ũ'=>'U','Ų'=>'U',
				'Ū'=>'U','Ǜ'=>'U','Ǚ'=>'U','Ù'=>'U','Ú'=>'U','Ü'=>'Ue',
				'Ǘ'=>'U','Ǖ'=>'U','У'=>'U','Ư'=>'U','Ǔ'=>'U','Û'=>'U',
				'В'=>'V','Ŵ'=>'W','Ы'=>'Y','Ŷ'=>'Y','Ý'=>'Y','Ÿ'=>'Y',
				'Ź'=>'Z','З'=>'Z','Ż'=>'Z','Ž'=>'Z','Ж'=>'Zh','á'=>'a',
				'ă'=>'a','â'=>'a','à'=>'a','ā'=>'a','ǻ'=>'a','å'=>'a',
				'ä'=>'ae','ą'=>'a','ǎ'=>'a','ã'=>'a','а'=>'a','ª'=>'a',
				'æ'=>'ae','ǽ'=>'ae','б'=>'b','č'=>'c','ç'=>'c','ц'=>'c',
				'ċ'=>'c','ĉ'=>'c','ć'=>'c','ч'=>'ch','ð'=>'dj','ď'=>'dj',
				'д'=>'dj','đ'=>'dj','э'=>'e','é'=>'e','ё'=>'e','ë'=>'e',
				'ê'=>'e','е'=>'e','ĕ'=>'e','è'=>'e','ę'=>'e','ě'=>'e',
				'ė'=>'e','ē'=>'e','ƒ'=>'f','ф'=>'f','ġ'=>'g','ĝ'=>'g',
				'ğ'=>'g','г'=>'g','ģ'=>'g','х'=>'h','ĥ'=>'h','ħ'=>'h',
				'ǐ'=>'i','ĭ'=>'i','и'=>'i','ī'=>'i','ĩ'=>'i','į'=>'i',
				'ı'=>'i','ì'=>'i','î'=>'i','í'=>'i','ï'=>'i','ĳ'=>'ij',
				'ĵ'=>'j','й'=>'j','я'=>'ja','ю'=>'ju','ķ'=>'k','к'=>'k',
				'ľ'=>'l','ł'=>'l','ŀ'=>'l','ĺ'=>'l','ļ'=>'l','л'=>'l',
				'м'=>'m','ņ'=>'n','ñ'=>'n','ń'=>'n','н'=>'n','ň'=>'n',
				'ŉ'=>'n','ó'=>'o','ò'=>'o','ǒ'=>'o','ő'=>'o','о'=>'o',
				'ō'=>'o','º'=>'o','ơ'=>'o','ŏ'=>'o','ô'=>'o','ö'=>'oe',
				'õ'=>'o','ø'=>'o','ǿ'=>'o','œ'=>'oe','п'=>'p','р'=>'r',
				'ř'=>'r','ŕ'=>'r','ŗ'=>'r','ſ'=>'s','ŝ'=>'s','ș'=>'s',
				'š'=>'s','ś'=>'s','с'=>'s','ş'=>'s','ш'=>'sh','щ'=>'shch',
				'ß'=>'ss','ţ'=>'t','т'=>'t','ŧ'=>'t','ť'=>'t','ț'=>'t',
				'у'=>'u','ǘ'=>'u','ŭ'=>'u','û'=>'u','ú'=>'u','ų'=>'u',
				'ù'=>'u','ű'=>'u','ů'=>'u','ư'=>'u','ū'=>'u','ǚ'=>'u',
				'ǜ'=>'u','ǔ'=>'u','ǖ'=>'u','ũ'=>'u','ü'=>'ue','в'=>'v',
				'ŵ'=>'w','ы'=>'y','ÿ'=>'y','ý'=>'y','ŷ'=>'y','ź'=>'z',
				'ž'=>'z','з'=>'z','ż'=>'z','ж'=>'zh'
			)+Base::instance()->get('DIACRITICS'))))),'-');
	}
1225740
protected function _encodeString($text, $charset)
    {
        if ($this->_appCharset === $charset) {
            return $text;
        }

        return mb_convert_encoding($text, $charset, $this->_appCharset);
    }
225303
public function createLegend($text, array $attributes = [])
    {
        $node = new Fieldset\Legend($attributes);
        $node->entity->setEntityName('legend');
        $node->attributes->addAttribute('for', dash($text));

        $node->textContent->push($text);

        $this->childNodes->prepend($node);

        return $this->legend = $this->childNodes->first();
    }
518757
static String hepburn(
        CharSequence text,
        int offset
    ) {

        StringBuilder sb = null;
        int n = Math.min(text.length(), offset + 32);

        for (int i = offset; i < n; i++) {
            final char c = text.charAt(i);
            char std;
            if (i == offset) { // capitalization
                std = ((c == '\u00D4') || (c == '\u00F4') || (c == '\u014D') ? '\u014C' : Character.toUpperCase(c));
                std = ((c == '\u00DB') || (c == '\u00FB') || (c == '\u016B') ? '\u016A' : std);
            } else {
                std = ((c == '\u00D4') || (c == '\u00F4') || (c == '\u014C') ? '\u014D' : Character.toLowerCase(c));
                std = ((c == '\u00DB') || (c == '\u00FB') || (c == '\u016A') ? '\u016B' : std);
            }
            std = ((c == '\'') ? '\u2019' : std); // use ’ as apostroph
            std = ((c == ' ') ? '-' : std); // use hyphen instead of space
            if ((sb != null) || (std != c)) {
                if (sb == null) {
                    sb = new StringBuilder(32);
                    sb.append(text.subSequence(offset, i));
                }
                sb.append(std);
            }
        }

        return ((sb == null) ? text.subSequence(offset, n).toString() : sb.toString());

    }
930420
public static function charNotInAlphabet(string $char) : self
    {
        $ord = \ord($char);

        if ($ord < 32 || $ord > 126) {
            $char = \strtoupper(\dechex($ord));

            if ($ord < 10) {
                $char = '0' . $char;
            }
        } else {
            $char = '"' . $char . '"';
        }

        return new self(sprintf('Char %s is not a valid character in the given alphabet.', $char));
    }
765267
protected function shuffle($alphabet, $salt)
    {
        $saltLength = strlen($salt);

        if (!$saltLength) {
            return $alphabet;
        }

        for ($i = strlen($alphabet) - 1, $v = 0, $p = 0; $i > 0; $i--, $v++) {
            $v %= $saltLength;
            $p += $int = ord($salt[$v]);
            $j = ($int + $v + $p) % $i;

            $temp = $alphabet[$j];
            $alphabet[$j] = $alphabet[$i];
            $alphabet[$i] = $temp;
        }

        return $alphabet;
    }
112367
public static function ampReplace($text)
    {
        $text = str_replace('&&', '*--*', $text);
        $text = str_replace('&#', '*-*', $text);
        $text = str_replace('&amp;', '&', $text);
        $text = preg_replace('|&(?![\w]+;)|', '&amp;', $text);
        $text = str_replace('*-*', '&#', $text);
        $text = str_replace('*--*', '&&', $text);

        return $text;
    }
421420
public static function create(array $words, $size = 15, $lang = 'en')
    {
        $alphabet = ($lang == 'fi') ? new Alphabet\Finnish : null;
        $generator = new Generator($words, $size, $alphabet);
        return $generator->generate();
    }