/** * Personal names such as "Marcus Aurelius" are sometimes typed incorrectly using lowercase ("marcus aurelius"). * * @param string $names * @param string $delimiter * * @return string */ private function capitalizePersonalNameByDelimiter($names, $delimiter) { // init $names = explode($delimiter, $names); $encoding = $this->encoding; $specialCases = array('names' => array('ab', 'af', 'al', 'and', 'ap', 'bint', 'binte', 'da', 'de', 'del', 'den', 'der', 'di', 'dit', 'ibn', 'la', 'mac', 'nic', 'of', 'ter', 'the', 'und', 'van', 'von', 'y', 'zu'), 'prefixes' => array('al-', "d'", 'ff', "l'", 'mac', 'mc', 'nic')); foreach ($names as &$name) { if (in_array($name, $specialCases['names'], true)) { continue; } $continue = false; if ($delimiter == '-') { foreach ($specialCases['names'] as $beginning) { if (UTF8::strpos($name, $beginning, null, $encoding) === 0) { $continue = true; } } } foreach ($specialCases['prefixes'] as $beginning) { if (UTF8::strpos($name, $beginning, null, $encoding) === 0) { $continue = true; } } if ($continue) { continue; } $name = $this->capitalizeWord($name); } return new static(implode($delimiter, $names), $encoding); }
/** * Scan attributes from input & return them if found. * * @return Object|null */ protected function scanAttributes() { if ('(' === $this->input[0]) { $index = $this->getDelimitersIndex('(', ')'); $input = UTF8::substr($this->input, 1, $index - 1); $token = $this->takeToken('attributes', $input); $attributes = preg_split('/ *, *(?=[\'"\\w-]+ *[:=]|[\\w-]+ *$)/', $token->value); $this->consumeInput($index + 1); $token->attributes = array(); foreach ($attributes as $i => $pair) { $pair = preg_replace('/^ *| *$/', '', $pair); $colon = UTF8::strpos($pair, ':'); $equal = UTF8::strpos($pair, '='); $sbrac = UTF8::strpos($pair, '\''); $dbrac = UTF8::strpos($pair, '"'); if ($sbrac < 1) { $sbrac = false; } if ($dbrac < 1) { $dbrac = false; } if (false !== $sbrac && $colon > $sbrac || false !== $dbrac && $colon > $dbrac) { $colon = false; } if (false !== $sbrac && $equal > $sbrac || false !== $dbrac && $equal > $dbrac) { $equal = false; } if (false === $colon && false === $equal) { $key = $pair; $value = true; } else { $splitter = false !== $colon ? $colon : $equal; if (false !== $colon && $colon < $equal) { $splitter = $colon; } $key = UTF8::substr($pair, 0, $splitter); $value = preg_replace('/^ *[\'"]?|[\'"]? *$/', '', UTF8::substr($pair, ++$splitter, UTF8::strlen($pair))); if ('true' === $value) { $value = true; } elseif (empty($value) || 'null' === $value || 'false' === $value) { $value = false; } } $token->attributes[preg_replace(array('/^ +| +$/', '/^[\'"]|[\'"]$/'), '', $key)] = $value; } return $token; } }
/** * Return first and last position of text * * @param string The parent text of the text to be formatted * @param string The text to be formatted * @return string */ protected function getTextPosition($context, $text) { $pos = UTF8::strpos($context, $text); return [$pos, $pos + UTF8::strlen($text)]; }