strlen() public static method

Gets the string length. Multibyte enabled version of strlen().
public static strlen ( string $string, array $options = [] ) : integer
$string string The string being measured for length.
$options array Allows for selecting the adapter to use via the `name` options. Will use the `'default'` adapter by default.
return integer The length of the string on success.
 public function apply($testable, array $config = array())
 {
     extract($config += $this->config);
     foreach ($testable->lines() as $i => $line) {
         $tabBounty = substr_count($line, "\t") * ($tabWidth - 1);
         $strlen = Multibyte::strlen($line, array('name' => 'li3_quality'));
         $totalLength = $length = $tabBounty + $strlen;
         if ($totalLength > $hardLimit) {
             $this->addViolation(array('message' => "Maximum line length of {$hardLimit} exceeded", 'line' => $i + 1, 'position' => $length));
         } elseif ($softLimit && $totalLength > $softLimit) {
             $this->addWarning(array('message' => "Soft line length of {$softLimit} exceeded", 'line' => $i + 1, 'position' => $length));
         }
     }
 }
 public function apply($testable, array $config = array())
 {
     $message = "Trailing whitespace found";
     $lines = $testable->lines();
     foreach ($lines as $i => $line) {
         $name = 'li3_quality';
         $length = Multibyte::strlen($line, compact('name'));
         $lengthTrimmed = Multibyte::strlen(rtrim($line), compact('name'));
         if ($length !== $lengthTrimmed) {
             $this->addViolation(array('message' => $message, 'line' => $i + 1, 'position' => $length));
         }
     }
     if (empty($line)) {
         $this->addViolation(array('message' => $message, 'line' => count($lines)));
     }
 }
Beispiel #3
0
 * Adds locale specific rules through the `Catalog` class. You can load more
 * locale dependent rules into the by specifying them manually or retrieving
 * them with the `Catalog` class.
 *
 * Enables support for multibyte strings through the `Multibyte` class by
 * overwriting rules (currently just `lengthBetween`).
 *
 * @see lithium\g11n\Catalog
 * @see lithium\g11n\Multibyte
 * @see lithium\util\Validator
 */
foreach (array('phone', 'postalCode', 'ssn') as $name) {
    Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
Validator::add('lengthBetween', function ($value, $format, $options) {
    $length = Multibyte::strlen($value);
    $options += array('min' => 1, 'max' => 255);
    return $length >= $options['min'] && $length <= $options['max'];
});
/**
 * In-View Translation
 *
 * Integration with `View`. Embeds message translation aliases into the `View`
 * class (or other content handler, if specified) when content is rendered. This
 * enables translation functions, i.e. `<?=$t("Translated content"); ?>`.
 *
 * @see lithium\g11n\Message::aliases()
 * @see lithium\net\http\Media
 */
Media::applyFilter('_handle', function ($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
 public function testStrlen()
 {
     Multibyte::strlen('test');
     $result = $this->adapter->testStrlenArgs;
     $expected = array('test');
     $this->assertEqual($expected, $result);
 }