コード例 #1
0
 /**
  * Checks if the passed value is valid.
  *
  * @param mixed      $value      The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  *
  * @api
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
         $length = grapheme_strlen($value);
     } elseif (function_exists('mb_strlen')) {
         $length = mb_strlen($value, $constraint->charset);
     } else {
         $length = strlen($value);
     }
     if ($constraint->min == $constraint->max && $length != $constraint->max) {
         $this->context->addViolation($constraint->exactMessage, array('{{ value }}' => $value, '{{ limit }}' => $constraint->max), null, (int) $constraint->max);
         return;
     }
     if ($length > $constraint->max) {
         $this->context->addViolation($constraint->maxMessage, array('{{ value }}' => $value, '{{ limit }}' => $constraint->max), null, (int) $constraint->max);
         return;
     }
     if ($length < $constraint->min) {
         $this->context->addViolation($constraint->minMessage, array('{{ value }}' => $value, '{{ limit }}' => $constraint->min), null, (int) $constraint->min);
     }
 }
コード例 #2
0
 /**
  * @covers Patchwork\PHP\Override\Intl::grapheme_strlen
  */
 function testGrapheme_strlen()
 {
     $this->assertSame(3, grapheme_strlen('한국어'));
     $this->assertSame(3, grapheme_strlen(n::normalize('한국어', n::NFD)));
     $this->assertSame(3, p::grapheme_strlen('한국어'));
     $this->assertSame(3, p::grapheme_strlen(n::normalize('한국어', n::NFD)));
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof Length) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Length');
     }
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $stringValue = (string) $value;
     if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
         $length = grapheme_strlen($stringValue);
     } elseif (function_exists('mb_strlen')) {
         $length = mb_strlen($stringValue, $constraint->charset);
     } else {
         $length = strlen($stringValue);
     }
     if (null !== $constraint->max && $length > $constraint->max) {
         $this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->max)->setInvalidValue($value)->setPlural((int) $constraint->max)->setCode(Length::TOO_LONG_ERROR)->addViolation();
         return;
     }
     if (null !== $constraint->min && $length < $constraint->min) {
         $this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->min)->setInvalidValue($value)->setPlural((int) $constraint->min)->setCode(Length::TOO_SHORT_ERROR)->addViolation();
     }
 }
コード例 #4
0
 public function excerpt($field, $length = 200)
 {
     $text = strip_tags($this->{$field});
     if (grapheme_strlen($text) > $length) {
         return grapheme_substr($text, 0, $length) . '...';
     } else {
         return $text;
     }
 }
コード例 #5
0
 public static function utf8Strlen($string)
 {
     if (function_exists('grapheme_strlen')) {
         return grapheme_strlen($string);
     } elseif (function_exists('mb_strlen')) {
         return mb_strlen($string, 'UTF-8');
     } else {
         return strlen($string);
     }
 }
コード例 #6
0
ファイル: SizeValidator.php プロジェクト: laubosslink/lab
 private function validateString($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string, scalar or object with __toString()');
     }
     $value = (string) $value;
     if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
         $length = grapheme_strlen($value);
     } elseif (function_exists('mb_strlen')) {
         $length = mb_strlen($value, $constraint->charset);
     } else {
         $length = strlen($value);
     }
     $this->validateSize($constraint, $length, Size::TYPE_STRING, array('{{ value }}' => $value));
 }
コード例 #7
0
 /**
  * Checks if the passed value is valid.
  *
  * @param mixed      $value      The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  *
  * @return Boolean Whether or not the value is valid
  *
  * @api
  */
 public function isValid($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return true;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
         $length = grapheme_strlen($value);
     } elseif (function_exists('mb_strlen')) {
         $length = mb_strlen($value, $constraint->charset);
     } else {
         $length = strlen($value);
     }
     if ($length < $constraint->limit) {
         $this->context->addViolation($constraint->message, array('{{ value }}' => $value, '{{ limit }}' => $constraint->limit));
         return false;
     }
     return true;
 }
コード例 #8
0
ファイル: StringUtils.php プロジェクト: solarfield/ok-kit-php
 public static function summarize($aText, $aLength, $aSuffix = '...')
 {
     $text = $aText;
     if (grapheme_strlen($aText) > 0) {
         if (grapheme_strlen($text) > $aLength) {
             $text = trim($text);
             $text = grapheme_substr($text, 0, $aLength);
             if ($aLength > 0) {
                 //trim the end at a word boundary
                 $text = strrev($text);
                 if (preg_match('/(?:\\s(\\S))|\\./', $text, $matches, PREG_OFFSET_CAPTURE) && count($matches) > 1) {
                     $newEnd = $matches[1][1];
                     if ($matches[1][0] == '.') {
                         $newEnd++;
                     }
                     $text = grapheme_substr($text, $newEnd);
                 }
                 $text = strrev($text) . $aSuffix;
             }
         }
     }
     return $text;
 }
コード例 #9
0
 /**
  * @param string $string
  *
  * @return int
  */
 private function getLength($string)
 {
     return grapheme_strlen($string);
 }
コード例 #10
0
ファイル: Uncurrency.php プロジェクト: leodido/moneylaundry
 /**
  * Returns the result of filtering $value
  *
  * @param  mixed $value
  * @return mixed
  */
 public function filter($value)
 {
     // Store original value
     $unfilteredValue = $value;
     if (is_string($value)) {
         // Initialization
         $formatter = $this->getFormatter();
         // Disable scientific notation
         $formatter->setSymbol(\NumberFormatter::EXPONENTIAL_SYMBOL, null);
         if ($this->getBreakingSpaceAllowed()) {
             // Replace spaces with NBSP (non breaking spaces)
             $value = str_replace(" ", " ", $value);
             // FIXME? can be removed
         }
         // Parse as currency
         ErrorHandler::start();
         $position = 0;
         $currencyCode = $this->setupCurrencyCode();
         if ($this->getCurrencyCorrectness()) {
             // The following parsing mode allows the predefined currency code ONLY.
             // Also it should be more strict and faster than parseCurrency.
             $result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
         } else {
             // The following parsing mode can work with multiple currencies.
             $result = $formatter->parseCurrency($value, $resultCurrencyCode, $position);
         }
         $fractionDigits = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
         // Input is a valid currency and the result is within the codomain?
         if ($result !== false && (is_float($result) && !is_infinite($result) && !is_nan($result))) {
             ErrorHandler::stop();
             // Exit if the parsing has finished before the end of the input
             if ($position < grapheme_strlen($value)) {
                 return $unfilteredValue;
             }
             // Retrieve currency symbol for the given locale and currency code
             $currencySymbol = $this->getFirstCurrencySymbol($this->getLocale(), $currencyCode);
             // Exit if the currency correctness is mandatory and the currency symbol is not present in the input
             if ($this->getCurrencyCorrectness() && grapheme_strpos($value, $currencySymbol) === false) {
                 return $unfilteredValue;
             }
             if ($this->getScaleCorrectness()) {
                 $countedDecimals = $this->countDecimalDigits($value, $formatter->getSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL), $currencySymbol);
                 // Exit if the number of decimal digits (i.e., the scale) does not match the requirement
                 if ($fractionDigits !== $countedDecimals) {
                     return $unfilteredValue;
                 }
             }
             // Here we have a perfectly parsed (pattern correct, currency correct, scale correct) currency amount
             return $result;
         }
         // At this stage result is FALSE and input probably is a not canonical currency amount
         // Check if the currency symbol is mandatory (assiming 'parse MODE')
         if ($this->getCurrencyCorrectness()) {
             ErrorHandler::stop();
             return $unfilteredValue;
         }
         // Retrieve symbols
         $symbolKeys = [self::CURRENCY_SYMBOL, self::GROUP_SEPARATOR_SYMBOL, self::SEPARATOR_SYMBOL, self::INFINITY_SYMBOL, self::NAN_SYMBOL, self::POSITIVE_PREFIX, self::POSITIVE_SUFFIX, self::NEGATIVE_PREFIX, self::NEGATIVE_SUFFIX, self::FRACTION_DIGITS];
         $symbols = [];
         foreach ($symbolKeys as $symbol) {
             $symbols[$symbol] = $this->getSymbol($symbol);
         }
         // Regex components
         $regexSymbols = array_filter(array_unique(array_values($symbols)));
         $numbers = $this->getRegexComponent(self::REGEX_NUMBERS);
         $flags = $this->getRegexComponent(self::REGEX_FLAGS);
         // Build allowed chars regex
         $allowedChars = sprintf('#^[%s]+$#%s', $numbers . implode('', array_map('preg_quote', $regexSymbols)), $flags);
         // FIXME: pay attention to NaN and INF symbols here
         // Check that value contains only allowed characters (digits, group and decimal separator)
         $result = false;
         if (preg_match($allowedChars, $value)) {
             $decimal = \NumberFormatter::create($this->getLocale(), \NumberFormatter::DECIMAL);
             // Get decimal place info
             // FIXME: parse and parseCurrancy could use different symbols
             // when used with non default currency code
             $currencySymbol = $this->getFirstCurrencySymbol($this->getLocale(), $currencyCode);
             $numDecimals = $this->countDecimalDigits($value, $symbols[self::SEPARATOR_SYMBOL], $currencySymbol);
             // Check if the number of decimal digits match the requirement
             if ($this->getScaleCorrectness() && $numDecimals !== $fractionDigits) {
                 return $unfilteredValue;
             }
             // Ignore spaces
             $value = str_replace(" ", '', $value);
             // Substitute negative currency representation with negative number representation
             $decimalNegPrefix = $decimal->getTextAttribute(\NumberFormatter::NEGATIVE_PREFIX);
             $decimalNegSuffix = $decimal->getTextAttribute(\NumberFormatter::NEGATIVE_SUFFIX);
             $currencyNegPrefix = $symbols[self::NEGATIVE_PREFIX];
             $currencyNegSuffix = $symbols[self::NEGATIVE_SUFFIX];
             if ($decimalNegPrefix !== $currencyNegPrefix && $decimalNegSuffix !== $currencyNegSuffix) {
                 $regex = sprintf('#^%s([%s%s%s]+)%s$#%s', preg_quote($currencyNegPrefix), $numbers, preg_quote($symbols[self::SEPARATOR_SYMBOL]), preg_quote($symbols[self::GROUP_SEPARATOR_SYMBOL]), preg_quote($currencyNegSuffix), $flags);
                 $value = preg_replace($regex, $decimalNegPrefix . '\\1' . $decimalNegSuffix, $value);
             }
             // Try to parse as a simple decimal (formatted) number
             $result = $decimal->parse($value, \NumberFormatter::TYPE_DOUBLE);
         }
         ErrorHandler::stop();
         return $result !== false ? $result : $unfilteredValue;
         // FIXME? strict check that it is a double
     }
     // At this stage input is not a string
     return $unfilteredValue;
 }
コード例 #11
0
ファイル: Intl.php プロジェクト: nilamdoc/KYCGlobal
 /**
  * Here used as a multibyte enabled equivalent of `strlen()`.
  *
  * @link http://php.net/manual/en/function.grapheme-strlen.php
  * @param string $string
  * @return integer|void
  */
 public function strlen($string)
 {
     return grapheme_strlen($string);
 }
コード例 #12
0
ファイル: CUString.php プロジェクト: nunodotferreira/Phred
 /**
  * Tells how many characters there are in a string.
  *
  * @param  string $string The string to be looked into.
  *
  * @return int The string's length.
  */
 public static function length($string)
 {
     assert('is_cstring($string)', vs(isset($this), get_defined_vars()));
     $res = grapheme_strlen($string);
     if (is_int($res)) {
         return $res;
     } else {
         assert('false', vs(isset($this), get_defined_vars()));
         return 0;
     }
 }
コード例 #13
0
 /**
  * Generate dataset.
  *
  * Formats:
  * - (positive and negative) currency amounts with their own currency symbol
  * - (positive and negative) currency amounts with ISO currency symbol
  * - (positive and negative) numbers (without currency symbol)
  * - (positive and negative) numbers expressed in scientific notation (without currency symbol)
  *
  * @return array
  */
 public function valuesProvider()
 {
     $data = [];
     $values = [0, 0.1, 0.01, 1000, 1234.61, 12345678.9];
     $values = array_unique(array_merge($values, array_map(function ($i) {
         return -$i;
     }, $values)));
     foreach ($this->locales as $locale) {
         $formatter = \NumberFormatter::create($locale, \NumberFormatter::CURRENCY);
         $currencySymbol = $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
         $isoSymbol = $formatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE);
         $groupSep = $formatter->getSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL);
         $numDecimals = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS);
         $posPre = $formatter->getTextAttribute(\NumberFormatter::POSITIVE_PREFIX);
         $negPre = $formatter->getTextAttribute(\NumberFormatter::NEGATIVE_PREFIX);
         $posSuf = $formatter->getTextAttribute(\NumberFormatter::POSITIVE_SUFFIX);
         $negSuf = $formatter->getTextAttribute(\NumberFormatter::NEGATIVE_SUFFIX);
         $exponantiatior = \NumberFormatter::create($locale, \NumberFormatter::SCIENTIFIC);
         foreach ($values as $value) {
             // Restore currency symbol
             $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $currencySymbol);
             if (is_float($value)) {
                 // If value is float and current currency does not have cents, jump it
                 if ($numDecimals === 0) {
                     continue;
                 }
                 // Create a currency with less decimal places then required (w/ currency symbol)
                 $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $numDecimals - 1);
                 $currency = preg_replace('/^[\\xC2\\xA0\\s]+|[\\xC2\\xA0\\s]+$/u', '', $formatter->format($value));
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, false, false, (double) sprintf('%.' . ($numDecimals - 1) . 'f', $value), $currency];
                 // Filtered
                 $data[] = [$locale, false, true, (double) sprintf('%.' . ($numDecimals - 1) . 'f', $value), $currency];
                 // Filtered
                 // Create a currency with less decimal places then required (w/o currency symbol)
                 $currency = preg_replace('#' . preg_quote($currencySymbol) . '#u', '', $currency);
                 $currency = preg_replace('/^[\\xC2\\xA0\\s]+|[\\xC2\\xA0\\s]+$/u', '', $currency);
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, false, false, (double) sprintf('%.' . ($numDecimals - 1) . 'f', $value), $currency];
                 // Filtered
                 $data[] = [$locale, false, true, $currency, $currency];
                 // Not filtered
                 // Create a currency with more decimal places then required (w/ currency symbol)
                 $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $numDecimals + 1);
                 $currency = preg_replace('/^[\\xC2\\xA0\\s]+|[\\xC2\\xA0\\s]+$/u', '', $formatter->format($value));
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, false, false, (double) sprintf('%.' . ($numDecimals + 1) . 'f', $value), $currency];
                 // Filtered
                 $data[] = [$locale, false, true, (double) sprintf('%.' . ($numDecimals + 1) . 'f', $value), $currency];
                 // Filtered
                 // Create a currency with more decimal places then required (w/o currency symbol)
                 $currency = preg_replace('#' . preg_quote($currencySymbol) . '#u', '', $currency);
                 $currency = preg_replace('/^[\\xC2\\xA0\\s]+|[\\xC2\\xA0\\s]+$/u', '', $currency);
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, false, false, (double) sprintf('%.' . ($numDecimals + 1) . 'f', $value), $currency];
                 // Filtered
                 $data[] = [$locale, false, true, $currency, $currency];
                 // Not filtered
             }
             // Restore correct number of maximum decimal places
             $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $numDecimals);
             // Create completely formatted currency value (w/ currency symbol)
             $currency = $formatter->formatCurrency($value, $isoSymbol);
             //                echo $currency . PHP_EOL;
             $data[] = [$locale, true, true, $value, $currency];
             // Filtered
             // Create currency value with letters inside
             $randomPos = rand(0, grapheme_strlen($currency) - 1);
             $currency = grapheme_substr($currency, 0, $randomPos) . 'X' . grapheme_substr($currency, $randomPos);
             //                echo $currency . PHP_EOL;
             $daa[] = [$locale, true, true, $currency, $currency];
             // Not filtered
             // Create currency value (w/ currency symbol) (w/o group separators)
             if (grapheme_strpos($currency, $groupSep) !== false) {
                 $formatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, null);
                 $currency = $formatter->formatCurrency($value, $isoSymbol);
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $value, $currency];
                 // Filtered
                 $formatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $groupSep);
             }
             // Create currency value with ISO currency symbol
             $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $isoSymbol);
             $currency = $formatter->format($value);
             //                echo $currency . PHP_EOL;
             $data[] = [$locale, true, true, $value, $currency];
             // Filtered
             // Create currency value with ISO currency symbol (w/o group separators)
             if (grapheme_strpos($currency, $groupSep) !== false) {
                 $formatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, null);
                 $currency = $formatter->format($value);
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $value, $currency];
                 // Filtered
                 $formatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $groupSep);
             }
             // Create currency values with wrong ISO currency symbol or other text after it
             $currency = $currency . 'S';
             //                echo $currency . PHP_EOL;
             $data[] = [$locale, true, true, $currency, $currency];
             // Not filtered
             // Create currency value w/o any currency symbol
             $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, null);
             $currency = $formatter->format($value);
             // preg_replace('/^[\xC2\xA0\s]+|[\xC2\xA0\s]+$/u', '', ...);
             //                echo $currency . PHP_EOL;
             $data[] = [$locale, true, true, $currency, $currency];
             // Not filtered
             $data[] = [$locale, true, false, $value, $currency];
             // Filtered when currency symbol is not mandatory
             if ($value >= 0) {
                 // Create currency value expressed in scientific notation w/o any currency symbol
                 $currency = $exponantiatior->format($value, \NumberFormatter::TYPE_DOUBLE);
                 //                    echo $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
                 // Create currency value expressed in scientific notation with proper currency symbol
                 $currency = $posPre . $currency . $posSuf;
                 //                    echo  $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
             } else {
                 // Create negative currency value expressed in scientific notation with proper currency symbol
                 $currency = $exponantiatior->format(abs($value), \NumberFormatter::TYPE_DOUBLE);
                 $currency = $negPre . $currency . $negSuf;
                 //                    echo  $currency . PHP_EOL;
                 $data[] = [$locale, true, true, $currency, $currency];
                 // Not filtered
                 $data[] = [$locale, true, false, $currency, $currency];
                 // Not filtered
             }
         }
         //            echo '---' . PHP_EOL;
     }
     return $data;
 }
コード例 #14
0
ファイル: enc.php プロジェクト: pixlr/zce-3
<?php

$str = 'привет';
echo mb_detect_encoding($str) . PHP_EOL;
echo $str . PHP_EOL;
echo strlen($str) . PHP_EOL;
echo grapheme_strlen($str) . PHP_EOL;
echo mb_internal_encoding() . PHP_EOL;
echo mb_convert_encoding($str, 'utf-8', 'windows-1251') . PHP_EOL;
echo PHP_EOL;
コード例 #15
0
<?php

foreach (array('møøse', '𝔘𝔫𝔦𝔠𝔬𝔡𝔢', 'J̲o̲s̲é̲') as $s1) {
    printf('String "%s" measured with strlen: %d mb_strlen: %s grapheme_strlen %s%s', $s1, strlen($s1), mb_strlen($s1), grapheme_strlen($s1), PHP_EOL);
}
コード例 #16
0
ファイル: StringUtil.php プロジェクト: ableron/ableron-core
 /**
  * Returns the length of the given string in grapheme units.
  *
  * @param string $inputString The string to return the length of
  * @return int
  */
 public static function getLength(string $inputString) : int
 {
     return grapheme_strlen($inputString);
 }
コード例 #17
0
ファイル: Truncator.php プロジェクト: judev/php-htmltruncator
 function ht_strlen($string)
 {
     return grapheme_strlen($string);
 }
コード例 #18
0
ファイル: Intl.php プロジェクト: Thomvh/turbine
 static function grapheme_substr_workaround62759($s, $start, $len)
 {
     // Intl based http://bugs.php.net/62759 and 55562 workaround
     if (2147483647 == $len) {
         return grapheme_substr($s, $start);
     }
     $slen = grapheme_strlen($s);
     $start = (int) $start;
     if (0 > $start) {
         $start += $slen;
     }
     if (0 > $start) {
         return false;
     }
     if ($start >= $slen) {
         return false;
     }
     $rem = $slen - $start;
     if (0 > $len) {
         $len += $rem;
     }
     if (0 === $len) {
         return '';
     }
     if (0 > $len) {
         return false;
     }
     if ($len > $rem) {
         $len = $rem;
     }
     return grapheme_substr($s, $start, $len);
 }
コード例 #19
0
ファイル: grapheme.php プロジェクト: badlamer/hhvm
function ut_main()
{
    $res_str = '';
    $char_a_diaeresis = "ä";
    // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4)
    $char_a_ring = "å";
    // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5)
    $char_o_diaeresis = "ö";
    // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6)
    $char_O_diaeresis = "Ö";
    // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6)
    $char_angstrom_sign = "Å";
    // 'ANGSTROM SIGN' (U+212B)
    $char_A_ring = "Å";
    // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
    $char_ohm_sign = "Ω";
    // 'OHM SIGN' (U+2126)
    $char_omega = "Ω";
    // 'GREEK CAPITAL LETTER OMEGA' (U+03A9)
    $char_combining_ring_above = "̊";
    // 'COMBINING RING ABOVE' (U+030A)
    $char_fi_ligature = "fi";
    // 'LATIN SMALL LIGATURE FI' (U+FB01)
    $char_long_s_dot = "ẛ";
    // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B)
    // the word 'hindi' using Devanagari characters:
    $hindi = "हिन्दी";
    $char_a_ring_nfd = "å";
    $char_A_ring_nfd = "Å";
    $char_o_diaeresis_nfd = "ö";
    $char_O_diaeresis_nfd = "Ö";
    $char_diaeresis = "̈";
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strlen($string) {}' . "\n\n";
    $res_str .= "\"hindi\" in devanagari strlen " . grapheme_strlen($hindi) . "\n";
    $res_str .= "\"ab\" + \"hindi\" + \"cde\" strlen " . grapheme_strlen('ab' . $hindi . 'cde') . "\n";
    $res_str .= "\"\" strlen " . grapheme_strlen("") . "\n";
    $res_str .= "char_a_ring_nfd strlen " . grapheme_strlen($char_a_ring_nfd) . "\n";
    $res_str .= "char_a_ring_nfd + \"bc\" strlen " . grapheme_strlen($char_a_ring_nfd . 'bc') . "\n";
    $res_str .= "\"abc\" strlen " . grapheme_strlen('abc') . "\n";
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strpos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 1), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "a", "false"), array("abc", "d", "false"), array("abc", "c", 2), array("abc", "b", 1), array("abc", "a", 0), array("abc", "a", 0, 0), array("abc", "a", 1, "false"), array("ababc", "a", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "op", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "opq", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "bc", "false"), array($char_a_ring_nfd . "bc", "abcdefg", "false"), array("abc", "defghijklmnopq", "false"), array("abc", "ab", 0), array("abc", "bc", 1), array("abc", "abc", 0), array("abc", "abcd", "false"), array("abc", "ab", 0, 0), array("abc", "abc", 0, 0), array("abc", "abc", 1, "false"), array("ababc", "ab", 1, 2), array("ababc", "abc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_a_ring_nfd . "bc", "o" . $char_a_ring_nfd . "bc", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strpos";
        if (3 == count($test)) {
            $result = grapheme_strpos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_strpos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_stripos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "O", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_O_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd, 2), array("a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 1), array("Abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "A", "false"), array("abc", "D", "false"), array("abC", "c", 2), array("abc", "B", 1), array("Abc", "a", 0), array("abc", "A", 0, 0), array("Abc", "a", 1, "false"), array("ababc", "A", 1, 2), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "oP", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "opQ", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bC" . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "Bc", $char_A_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "BC", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "BC", "false"), array($char_a_ring_nfd . "BC", "aBCdefg", "false"), array("aBC", "Defghijklmnopq", "false"), array("abC", "Ab", 0), array("aBC", "bc", 1), array("abC", "Abc", 0), array("abC", "aBcd", "false"), array("ABc", "ab", 0, 0), array("aBc", "abC", 0, 0), array("abc", "aBc", 1, "false"), array("ABabc", "AB", 1, 2), array("abaBc", "aBc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_A_ring_nfd . "bC", "O" . $char_a_ring_nfd . "bC", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bC" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "Bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_stripos";
        if (3 == count($test)) {
            $result = grapheme_stripos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_stripos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strrpos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 1), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "a", "false"), array("abc", "d", "false"), array("abc", "c", 2), array("abc", "b", 1), array("abc", "a", 0), array("abc", "a", 0, 0), array("abc", "a", 1, "false"), array("ababc", "a", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "op", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "opq", "opq", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "bc", "false"), array($char_a_ring_nfd . "bc", "abcdefg", "false"), array("abc", "defghijklmnopq", "false"), array("abc", "ab", 0), array("abc", "bc", 1), array("abc", "abc", 0), array("abc", "abcd", "false"), array("abc", "ab", 0, 0), array("abc", "abc", 0, 0), array("abc", "abc", 1, "false"), array("ababc", "ab", 1, 2), array("ababc", "abc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_a_ring_nfd . "bc", "o" . $char_a_ring_nfd . "bc", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_a_ring_nfd . "bc" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strrpos";
        if (3 == count($test)) {
            $result = grapheme_strrpos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_strrpos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strripos($haystack, $needle, $offset = 0) {}' . "\n\n";
    $tests = array(array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 2, 3), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "O", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_O_diaeresis_nfd, $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd, 2), array("a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, 1), array("Abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "A", "false"), array("abc", "D", "false"), array("abC", "c", 2), array("abc", "B", 1), array("Abc", "a", 0), array("abc", "A", 0, 0), array("Abc", "a", 1, "false"), array("ababc", "A", 1, 2), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "oP", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", "opQ", 5), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "abc", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "bC" . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd . "bc" . $char_o_diaeresis_nfd, 4), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "Bc", $char_A_ring_nfd . "bc", 2), array("a" . $char_a_ring_nfd . "BC", $char_a_ring_nfd . "bc", 1), array("abc", $char_a_ring_nfd . "BC", "false"), array($char_a_ring_nfd . "BC", "aBCdefg", "false"), array("aBC", "Defghijklmnopq", "false"), array("abC", "Ab", 0), array("aBC", "bc", 1), array("abC", "Abc", 0), array("abC", "aBcd", "false"), array("ABc", "ab", 0, 0), array("aBc", "abC", 0, 0), array("abc", "aBc", 1, "false"), array("ABabc", "AB", 1, 2), array("abaBc", "aBc", 1, 2), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o" . $char_A_ring_nfd . "bC", "O" . $char_a_ring_nfd . "bC", 2, 6), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bC" . $char_a_ring_nfd . "def", $char_a_ring_nfd . "Bc" . $char_a_ring_nfd, 2, 3));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strripos";
        if (3 == count($test)) {
            $result = grapheme_strripos($test[0], $test[1]);
        } else {
            $res_str .= " from {$test['2']}";
            $result = grapheme_strripos($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= $result;
        }
        $res_str .= " == " . $test[count($test) - 1] . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_substr($string, $start, $length = -1) {}' . "\n\n";
    $tests = array(array("abc", 3, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, 5, "false"), array("ao" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", 2, $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array($char_o_diaeresis_nfd . $char_a_ring_nfd . "a" . $char_A_ring_nfd . "bc", 2, "a" . $char_A_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", 5, "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, 5, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_O_diaeresis_nfd, 4, $char_O_diaeresis_nfd), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", 2, $char_a_ring_nfd . "bc"), array("a" . $char_A_ring_nfd . "bc", 1, $char_A_ring_nfd . "bc"), array("Abc", -5, "false"), array($char_a_ring_nfd . "bc", 3, "false"), array("abc", 4, "false"), array("abC", 2, "C"), array("abc", 1, "bc"), array("Abc", 1, 1, "b"), array("abc", 0, 2, "ab"), array("Abc", -4, 1, "false"), array("ababc", 1, 2, "ba"), array("ababc", 0, 10, "ababc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, 10, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -1, "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -2, "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -3, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -4, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -1, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -2, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -3, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -4, "a" . $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -5, "a" . $char_a_ring_nfd . "b"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -6, "a" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -7, "a"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -8, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, -9, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -7, $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -6, "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -5, "c" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -4, $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -3, "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -2, "pq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -1, "q"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -999, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 8, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 7, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 6, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 5, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 4, "a" . $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 3, "a" . $char_a_ring_nfd . "b"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 2, "a" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 1, "a"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, 0, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -999, "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -1, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Op"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -2, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -3, "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -4, "a" . $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -5, "a" . $char_a_ring_nfd . "b"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -6, "a" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -7, "a"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -8, ""), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", -8, -9, "false"));
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "substring of \"{$arg0}\" from \"{$test['1']}\" - grapheme_substr";
        if (3 == count($test)) {
            $result = grapheme_substr($test[0], $test[1]);
        } else {
            $res_str .= " with length {$test['2']}";
            $result = grapheme_substr($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_strstr($haystack, $needle, $before_needle = FALSE) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "o", "o", "o"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, $char_a_ring_nfd . "bc"), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "a", "false"), array("abc", "d", "false"), array("abc", "c", "c"), array("abc", "b", "bc"), array("abc", "a", "abc"), array("abc", "ab", "abc"), array("abc", "abc", "abc"), array("abc", "bc", "bc"), array("abc", "a", FALSE, "abc"), array("abc", "a", TRUE, ""), array("abc", "b", TRUE, "a"), array("abc", "c", TRUE, "ab"), array("ababc", "bab", TRUE, "a"), array("ababc", "abc", TRUE, "ab"), array("ababc", "abc", FALSE, "abc"), array("ab" . $char_a_ring_nfd . "c", "d", "false"), array("bc" . $char_a_ring_nfd . "a", "a", "a"), array("a" . $char_a_ring_nfd . "bc", "b", "bc"), array($char_a_ring_nfd . "bc", "a", "false"), array($char_a_ring_nfd . "abc", "ab", "abc"), array("abc" . $char_a_ring_nfd, "abc", "abc" . $char_a_ring_nfd), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc", $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, FALSE, $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", "a", TRUE, ""), array($char_a_ring_nfd . "abc", "b", TRUE, $char_a_ring_nfd . "a"), array("ab" . $char_a_ring_nfd . "c", "c", TRUE, "ab" . $char_a_ring_nfd), array("aba" . $char_a_ring_nfd . "bc", "ba" . $char_a_ring_nfd . "b", TRUE, "a"), array("ababc" . $char_a_ring_nfd, "abc" . $char_a_ring_nfd, TRUE, "ab"), array("abab" . $char_a_ring_nfd . "c", "ab" . $char_a_ring_nfd . "c", FALSE, "ab" . $char_a_ring_nfd . "c"));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_strstr";
        if (3 == count($test)) {
            $result = grapheme_strstr($test[0], $test[1]);
        } else {
            $res_str .= " before flag is " . ($test[2] ? "TRUE" : "FALSE");
            $result = grapheme_strstr($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_stristr($haystack, $needle, $before_needle = FALSE) {}' . "\n\n";
    $tests = array(array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, $char_O_diaeresis_nfd, $char_o_diaeresis_nfd), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "O", "o", "O"), array("a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd, "o", "false"), array($char_o_diaeresis_nfd . "a" . $char_a_ring_nfd . "bc", $char_a_ring_nfd, $char_a_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd, $char_a_ring_nfd . "bc"), array("abc", $char_a_ring_nfd, "false"), array($char_a_ring_nfd . "bc", "A", "false"), array("abc", "d", "false"), array("abc", "C", "c"), array("aBc", "b", "Bc"), array("abc", "A", "abc"), array("abC", "ab", "abC"), array("abc", "aBc", "abc"), array("abC", "bc", "bC"), array("abc", "A", FALSE, "abc"), array("abc", "a", TRUE, ""), array("aBc", "b", TRUE, "a"), array("abc", "C", TRUE, "ab"), array("aBabc", "bab", TRUE, "a"), array("ababc", "aBc", TRUE, "ab"), array("ababc", "abC", FALSE, "abc"), array("ab" . $char_a_ring_nfd . "c", "d", "false"), array("bc" . $char_a_ring_nfd . "A", "a", "A"), array("a" . $char_a_ring_nfd . "bc", "B", "bc"), array($char_A_ring_nfd . "bc", "a", "false"), array($char_a_ring_nfd . "abc", "Ab", "abc"), array("abc" . $char_A_ring_nfd, "abc", "abc" . $char_A_ring_nfd), array("a" . $char_a_ring_nfd . "bc", $char_A_ring_nfd . "bc", $char_a_ring_nfd . "bc"), array("a" . $char_A_ring_nfd . "bc", $char_a_ring_nfd, FALSE, $char_A_ring_nfd . "bc"), array("a" . $char_a_ring_nfd . "bc", "A", TRUE, ""), array($char_a_ring_nfd . "aBc", "b", TRUE, $char_a_ring_nfd . "a"), array("ab" . $char_a_ring_nfd . "c", "C", TRUE, "ab" . $char_a_ring_nfd), array("aba" . $char_A_ring_nfd . "bc", "ba" . $char_a_ring_nfd . "b", TRUE, "a"), array("ababc" . $char_a_ring_nfd, "aBc" . $char_A_ring_nfd, TRUE, "ab"), array("abAB" . $char_A_ring_nfd . "c", "ab" . $char_a_ring_nfd . "c", FALSE, "AB" . $char_A_ring_nfd . "c"));
    foreach ($tests as $test) {
        $arg1 = urlencode($test[1]);
        $arg0 = urlencode($test[0]);
        $res_str .= "find \"{$arg1}\" in \"{$arg0}\" - grapheme_stristr";
        if (3 == count($test)) {
            $result = grapheme_stristr($test[0], $test[1]);
        } else {
            $res_str .= " before flag is " . ($test[2] ? "TRUE" : "FALSE");
            $result = grapheme_stristr($test[0], $test[1], $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_COUNT, $start = 0[, $next])' . "\n\n";
    $tests = array(array("abc", 3, "abc"), array("abc", 2, "ab"), array("abc", 1, "a"), array("abc", 0, ""), array("abc", 1, 0, "a"), array("abc", 1, 1, "b"), array("abc", 1, 2, "c"), array("abc", 0, 2, ""), array("abc", 3, 0, 3, "abc"), array("abc", 2, 0, 2, "ab"), array("abc", 1, 0, 1, "a"), array("abc", 0, 0, 0, ""), array("abc", 1, 0, 1, "a"), array("abc", 1, 1, 2, "b"), array("abc", 1, 2, 3, "c"), array("abc", 0, 2, 2, ""), array("http://news.bbc.co.uk/2/hi/middle_east/7831588.stm", 48, 48, 50, "tm"), array($char_a_ring_nfd . "bc", 3, $char_a_ring_nfd . "bc"), array($char_a_ring_nfd . "bc", 2, $char_a_ring_nfd . "b"), array($char_a_ring_nfd . "bc", 1, $char_a_ring_nfd . ""), array($char_a_ring_nfd . "bc", 3, 0, 5, $char_a_ring_nfd . "bc"), array($char_a_ring_nfd . "bc", 2, 0, 4, $char_a_ring_nfd . "b"), array($char_a_ring_nfd . "bc", 1, 0, 3, $char_a_ring_nfd . ""), array($char_a_ring_nfd . "bcde", 2, 3, 5, "bc"), array($char_a_ring_nfd . "bcde", 2, 4, 6, "cd"), array($char_a_ring_nfd . "bcde" . $char_a_ring_nfd . "f", 4, 5, 11, "de" . $char_a_ring_nfd . "f"), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, $char_a_ring_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 1, $char_a_ring_nfd . ""), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 0, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 2, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 3, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 1, 4, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 0, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 2, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 3, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 4, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 7, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 8, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 10, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 11, "false"));
    $next = -1;
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "extract from \"{$arg0}\" \"{$test['1']}\" graphemes - grapheme_extract";
        if (3 == count($test)) {
            $result = grapheme_extract($test[0], $test[1]);
        } elseif (4 == count($test)) {
            $res_str .= " starting at byte position {$test['2']}";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_COUNT, $test[2]);
        } else {
            $res_str .= " starting at byte position {$test['2']} with \$next";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_COUNT, $test[2], $next);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]);
        if (5 == count($test)) {
            $res_str .= " \$next={$next} == {$test['3']} ";
            if ($next != $test[3]) {
                $res_str .= "***FAILED***";
            }
        }
        $res_str .= "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_MAXBYTES, $start = 0)' . "\n\n";
    $tests = array(array("abc", 3, "abc"), array("abc", 2, "ab"), array("abc", 1, "a"), array("abc", 0, ""), array($char_a_ring_nfd . "bc", 5, $char_a_ring_nfd . "bc"), array($char_a_ring_nfd . "bc", 4, $char_a_ring_nfd . "b"), array($char_a_ring_nfd . "bc", 1, ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 9, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 10, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 11, $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, $char_a_ring_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 3, $char_a_ring_nfd . ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 4, $char_a_ring_nfd . ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 5, $char_a_ring_nfd . ""), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 6, $char_a_ring_nfd . $char_o_diaeresis_nfd), array($char_a_ring_nfd . $char_o_diaeresis_nfd . "c", 7, $char_a_ring_nfd . $char_o_diaeresis_nfd . "c"), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 0, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 2, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 3, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 4, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, 0, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, 2, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 6, 3, $char_o_diaeresis_nfd . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 5, 4, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 5, 7, $char_diaeresis . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 3, 8, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 10, $char_diaeresis), array($char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd . $char_o_diaeresis_nfd, 2, 11, "false"));
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "extract from \"{$arg0}\" \"{$test['1']}\" graphemes - grapheme_extract GRAPHEME_EXTR_MAXBYTES";
        if (3 == count($test)) {
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXBYTES);
        } else {
            $res_str .= " starting at byte position {$test['2']}";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXBYTES, $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    $res_str .= "\n" . 'function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_MAXCHARS, $start = 0)' . "\n\n";
    $tests = array(array("abc", 3, "abc"), array("abc", 2, "ab"), array("abc", 1, "a"), array("abc", 0, ""), array("abc" . $char_o_diaeresis_nfd, 0, ""), array("abc" . $char_o_diaeresis_nfd, 1, "a"), array("abc" . $char_o_diaeresis_nfd, 2, "ab"), array("abc" . $char_o_diaeresis_nfd, 3, "abc"), array("abc" . $char_o_diaeresis_nfd, 4, "abc"), array("abc" . $char_o_diaeresis_nfd, 5, "abc" . $char_o_diaeresis_nfd), array("abc" . $char_o_diaeresis_nfd, 6, "abc" . $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . "abc", 0, ""), array($char_o_diaeresis_nfd . "abc", 1, ""), array($char_o_diaeresis_nfd . "abc", 2, $char_o_diaeresis_nfd), array($char_o_diaeresis_nfd . "abc", 3, $char_o_diaeresis_nfd . "a"), array($char_o_diaeresis_nfd . "abc", 4, $char_o_diaeresis_nfd . "ab"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 5, $char_o_diaeresis_nfd . "abc"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 6, $char_o_diaeresis_nfd . "abc"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 7, $char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, $char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "x"), array("abc", 3, 0, "abc"), array("abc", 2, 1, "bc"), array("abc", 1, 2, "c"), array("abc", 0, 3, "false"), array("abc", 1, 3, "false"), array("abc", 1, 999, "false"), array($char_o_diaeresis_nfd . "abc", 1, 6, "false"), array($char_o_diaeresis_nfd . "abc", 1, 999, "false"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 0, $char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "x"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 1, $char_diaeresis . "abc" . $char_a_ring_nfd . "xy"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 2, "abc" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 3, "abc" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 4, "bc" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 5, "c" . $char_a_ring_nfd . "xyz"), array($char_o_diaeresis_nfd . "abc" . $char_a_ring_nfd . "xyz", 8, 6, $char_a_ring_nfd . "xyz"));
    foreach ($tests as $test) {
        $arg0 = urlencode($test[0]);
        $res_str .= "extract from \"{$arg0}\" \"{$test['1']}\" graphemes - grapheme_extract GRAPHEME_EXTR_MAXCHARS";
        if (3 == count($test)) {
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXCHARS);
        } else {
            $res_str .= " starting at byte position {$test['2']}";
            $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXCHARS, $test[2]);
        }
        $res_str .= " = ";
        if ($result === false) {
            $res_str .= 'false';
        } else {
            $res_str .= urlencode($result);
        }
        $res_str .= " == " . urlencode($test[count($test) - 1]) . check_result($result, $test[count($test) - 1]) . "\n";
    }
    //=====================================================================================
    return $res_str;
}
コード例 #20
0
ファイル: String.php プロジェクト: raz0rsdge/horde
 /**
  * Returns the character (not byte) length of a string.
  *
  * @param string $string  The string to return the length of.
  * @param string $charset The charset to use when calculating the string's
  *                        length.
  *
  * @return integer  The string's length.
  */
 public static function length($string, $charset = 'UTF-8')
 {
     $charset = self::lower($charset);
     if ($charset == 'utf-8' || $charset == 'utf8') {
         return strlen(utf8_decode($string));
     }
     if (Horde_Util::extensionExists('mbstring')) {
         $ret = @mb_strlen($string, self::_mbstringCharset($charset));
         if (!empty($ret)) {
             return $ret;
         }
     }
     if (Horde_Util::extensionExists('intl')) {
         return grapheme_strlen(self::convertCharset($string, $charset, 'UTF-8'));
     }
     return strlen($string);
 }
コード例 #21
0
ファイル: Utf8.php プロジェクト: nicolas-grekas/Patchwork
 static function strspn($s, $mask, $start = 0, $len = 2147483647)
 {
     if ($start || 2147483647 != $len) {
         $s = self::substr($s, $start, $len);
     }
     return preg_match('/^' . self::rxClass($mask) . '+/u', $s, $s) ? grapheme_strlen($s[0]) : 0;
 }
コード例 #22
0
ファイル: Str.php プロジェクト: etrepat/compleet
 /**
  * Reliable unicode string length computation.
  *
  * @param   string $input
  * @return  int
  */
 public static function size($input)
 {
     return grapheme_strlen($input);
 }
コード例 #23
0
ファイル: SitemapQueryHandler.php プロジェクト: PHPinDD/blog
 /**
  * @param SitemapQuery $query
  */
 public function handle(SitemapQuery $query)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $urlSet = $dom->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
     $urlSet->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1');
     $urlSet->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:video', 'http://www.google.com/schemas/sitemap-video/1.1');
     $dom->appendChild($urlSet);
     $url = $dom->createElement('url');
     $homeLoc = $dom->createElement('loc', App::getUrl());
     $homeImage = $dom->createElement('image:image');
     $homeImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/phpindd-logo.png');
     $homeImageCaption = $dom->createElement('image:caption', 'PHP in DD Blog');
     $homeImage->appendChild($homeImageLoc);
     $homeImage->appendChild($homeImageCaption);
     $url->appendChild($homeLoc);
     $url->appendChild($homeImage);
     $urlSet->appendChild($url);
     $posts = $this->blogPostReadService->getAllPosts();
     foreach ($posts as $post) {
         $url = $dom->createElement('url');
         $postLoc = $dom->createElement('loc', App::getUrl() . $post->url);
         $url->appendChild($postLoc);
         $urlSet->appendChild($url);
     }
     # hwoltersdorf
     $url = $dom->createElement('url');
     $authorLoc = $dom->createElement('loc', App::getUrl() . '/about/author/holger-woltersdorf');
     $authorImage = $dom->createElement('image:image');
     $authorImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/hwoltersdorf.jpg');
     $authorImageCaption = $dom->createElement('image:caption', 'Holger Woltersdorf');
     $authorImage->appendChild($authorImageLoc);
     $authorImage->appendChild($authorImageCaption);
     $url->appendChild($authorLoc);
     $url->appendChild($authorImage);
     $urlSet->appendChild($url);
     # dmersiowsky
     $url = $dom->createElement('url');
     $authorLoc = $dom->createElement('loc', App::getUrl() . '/about/author/daniel-mersiowsky');
     $authorImage = $dom->createElement('image:image');
     $authorImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/dmersiowsky.jpg');
     $authorImageCaption = $dom->createElement('image:caption', 'Daniel Mersiowsky');
     $authorImage->appendChild($authorImageLoc);
     $authorImage->appendChild($authorImageCaption);
     $url->appendChild($authorLoc);
     $url->appendChild($authorImage);
     $urlSet->appendChild($url);
     # tmissner
     $url = $dom->createElement('url');
     $authorLoc = $dom->createElement('loc', App::getUrl() . '/about/author/tobias-missner');
     $authorImage = $dom->createElement('image:image');
     $authorImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/tmissner.png');
     $authorImageCaption = $dom->createElement('image:caption', 'Tobias Mißner');
     $authorImage->appendChild($authorImageLoc);
     $authorImage->appendChild($authorImageCaption);
     $url->appendChild($authorLoc);
     $url->appendChild($authorImage);
     $urlSet->appendChild($url);
     $content = $dom->saveXML();
     header('Content-Type: text/xml; charset=utf-8');
     header('Content-Length: ' . grapheme_strlen($content));
     echo $content;
 }