Exemplo n.º 1
0
 /**
  * Filter: removes unnecessary whitespace and shortens value to control's max length.
  * @return string
  */
 public function sanitize($value)
 {
     if ($this->control->maxlength && String::length($value) > $this->control->maxlength) {
         $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
     }
     return String::trim(strtr($value, "\r\n", '  '));
 }
Exemplo n.º 2
0
 private function maxLength($value)
 {
     $max = $this->options['maxLength'];
     if (String::length($value) > $max) {
         $this->errors[] = __('The maximum length is %d number.', 'The maximum length is %d numbers.', $max);
     }
 }
Exemplo n.º 3
0
 /**
  * Filter: shortens value to control's max length.
  * @return string
  */
 public function checkMaxLength($value)
 {
     if ($this->control->maxlength && String::length($value) > $this->control->maxlength) {
         $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
     }
     return $value;
 }
Exemplo n.º 4
0
 private function minLength($value)
 {
     $min = (string) $this->options['min_length'];
     $len = String::length($value);
     if (ctype_digit($min) && $len < $min) {
         $this->errors[] = __('This field must be of %d character at least.', 'This field must be of %d characters at least.', $min);
     }
 }
Exemplo n.º 5
0
 /**
  * @param string|int $string
  */
 public function __construct($string = null)
 {
     if (is_int($string)) {
         parent::__construct($string);
         return;
     }
     $string = new String($string);
     parent::__construct($string->length() + 16);
     $this->append($string);
 }
Exemplo n.º 6
0
 /**
  * Extract Keywords from a text and return $num of them
  *
  * @param string $text
  * @param integer $num
  * @return array(string)
  */
 public function extract($text, $num = null)
 {
     // strip html
     $text = strip_tags($text);
     // strip stopwords
     if ($this->useStopWords) {
         $text = $this->stripStopWords($text);
     }
     // extract long words
     if ($this->collectPairs) {
         $regexp = '@([A-Z][a-z]{4,}|[A-Z]{3,})([\\s-][A-Z][a-z]{3,})?@';
     } else {
         $regexp = '@([A-Z][a-z]{4,}|[A-Z]{3,})@';
     }
     if (!preg_match_all($regexp, $text, $found)) {
         return array();
     }
     // count occurences that are used as basic score
     foreach ($found[0] as $word) {
         if (!isset($keywords[$word])) {
             $keywords[$word] = 1;
         }
         $keywords[$word]++;
     }
     // extra scoring for word lengths and upper case words
     if (!empty($this->lengthBonus)) {
         $lastWordLengthBonusKey = array_keys($this->lengthBonus);
         $lastWordLengthBonusKey = end($lastWordLengthBonusKey);
     }
     foreach ($keywords as $word => $count) {
         // word length bonus
         if (!empty($this->lengthBonus)) {
             $wordLength = String::length($word);
             if (isset($this->lengthBonus[$wordLength])) {
                 $keywords[$word] += $this->lengthBonus[$wordLength];
             }
             if ($wordLength > $this->lengthBonus[$lastWordLengthBonusKey]) {
                 $keywords[$word] *= 1.5;
             }
         }
         // capital letters bonus
         if (preg_match('@^[A-Z]+$@', $word)) {
             $keywords[$word] += $this->capitalLetterBonus;
         }
     }
     // sort by score
     arsort($keywords);
     if ($num !== null) {
         $keywords = array_slice($keywords, 0, $num);
     }
     return array_keys($keywords);
 }
Exemplo n.º 7
0
 public function offsetUnsetAtEnd()
 {
     $str = new String('www.m�ller.com');
     unset($str[$str->length() - 1]);
     $this->assertEquals(new String('www.m�ller.co'), $str);
 }
Exemplo n.º 8
0
 function testSampleStringSize()
 {
     $sample = new String("abc");
     $this->assertEqual(3, $sample->length());
 }
/**
 * @param mixed $value_
 *
 * @return boolean|false If given parameter has no value.
 */
function assertNotEmpty($value_)
{
    $message = Assertion_Helper::getMessage('Expected any value', __FUNCTION__, func_get_args());
    if ((0 === $value_ || is_string($value_) && 1 > String::length($value_) || is_array($value_) && 1 > count($value_)) && false !== $value_) {
        Assertion_Context::current()->add(__FUNCTION__, false, $message);
        return false;
    }
    Assertion_Context::current()->add(__FUNCTION__, true, $message);
    return true;
}
Exemplo n.º 10
0
 public static function displayTracer(Tracer $Tracer, $separator = ' » ', $protect = true)
 {
     $traces = $Tracer->getTraces();
     if (!empty($traces)) {
         $output = '';
         foreach ($traces as $trace) {
             $name = $protect ? Security::noHtml($trace['name']) : $trace['name'];
             if ($trace['link']) {
                 $output .= Html::LinkTo($name, $trace['link']) . $separator;
             } else {
                 $output .= $name . $separator;
             }
         }
         return String::substr($output, 0, -String::length($separator));
     } else {
         return null;
     }
 }
Exemplo n.º 11
0
 public function length()
 {
     $str = new String($this->str);
     return $str->length();
 }
Exemplo n.º 12
0
 /**
  * Returns array of string length.
  * @param  mixed
  * @return int
  */
 public static function length($var)
 {
     return is_string($var) ? String::length($var) : count($var);
 }
Exemplo n.º 13
0
 static function substr($string, $start, $length = null)
 {
     if ($length === null) {
         $length = String::length($string) - $start;
     }
     return mb_substr($string, $start, $length);
 }
Exemplo n.º 14
0
 public function stringTestChar()
 {
     $s = new String('Übercoder', 'iso-8859-1');
     $this->assertTrue(isset($s[0]));
     $this->assertTrue(isset($s[$s->length() - 1]));
     $this->assertFalse(isset($s[$s->length()]));
     $this->assertFalse(isset($s[-1]));
 }
 private function append($string_)
 {
     $this->m_console->append($string_);
     $this->m_console->flush();
     $this->m_cursor += String::length($string_);
 }
Exemplo n.º 16
0
 public function testLength()
 {
     $o = new String(self::MULTI_LINE);
     $this->assertEquals(45, $o->length());
     $o = new String('abcdefg');
     $this->assertEquals(7, $o->length());
 }
Exemplo n.º 17
0
function usage()
{
    global $options, $c;
    if (count($options[1]) && ($options[1][0] == 'help' && !empty($options[1][1]) || !empty($options[1][0]) && in_array($options[1][0], array('commit', 'compendium', 'extract', 'init', 'make', 'merge')))) {
        if ($options[1][0] == 'help') {
            $cmd = $options[1][1];
        } else {
            $cmd = $options[1][0];
        }
        $c->writeln(_("Usage:") . ' translation.php [options] ' . $cmd . ' [command-options]');
        if (!empty($cmd)) {
            $c->writeln();
            $c->writeln(_("Command options:"));
        }
        switch ($cmd) {
            case 'cleanup':
                $c->writeln(_("  -l, --locale=ll_CC     Use only this locale."));
                $c->writeln(_("  -m, --module=MODULE    Cleanup PO files only for this (Horde) module."));
                break;
            case 'commit':
            case 'commit-help':
                $c->writeln(_("  -l, --locale=ll_CC     Use this locale."));
                $c->writeln(_("  -m, --module=MODULE    Commit translations only for this (Horde) module."));
                $c->writeln(_("  -M, --message=MESSAGE  Use this commit message instead of the default ones."));
                $c->writeln(_("  -n, --new              This is a new translation, commit also C{$C->REDITS},\n                         CHANGES and nls.php.dist."));
                break;
            case 'compendium':
                $c->writeln(_("  -a, --add=FILE        Add this PO file to the compendium. Useful to\n                        include a compendium from a different branch to\n                        the generated compendium."));
                $c->writeln(_("  -d, --directory=DIR   Create compendium in this directory."));
                $c->writeln(_("  -l, --locale=ll_CC    Use this locale."));
                break;
            case 'extract':
                $c->writeln(_("  -m, --module=MODULE  Generate POT file only for this (Horde) module."));
                break;
            case 'init':
                $c->writeln(_("  -l, --locale=ll_CC     Use this locale."));
                $c->writeln(_("  -m, --module=MODULE    Create a PO file only for this (Horde) module."));
                $c->writeln(_("  -c, --compendium=FILE  Use this compendium file instead of the default\n                         one (compendium.po in the horde/po directory)."));
                $c->writeln(_("  -n, --no-compendium    Don't use a compendium."));
                break;
            case 'make':
                $c->writeln(_("  -l, --locale=ll_CC     Use only this locale."));
                $c->writeln(_("  -m, --module=MODULE    Build MO files only for this (Horde) module."));
                $c->writeln(_("  -c, --compendium=FILE  Merge new translations to this compendium file\n                         instead of the default one (compendium.po in the\n                         horde/po directory."));
                $c->writeln(_("  -n, --no-compendium    Don't merge new translations to the compendium."));
                break;
            case 'make-help':
            case 'update-help':
                $c->writeln(_("  -l, --locale=ll_CC     Use only this locale."));
                $c->writeln(_("  -m, --module=MODULE    Update help files only for this (Horde) module."));
                break;
            case 'merge':
                $c->writeln(_("  -l, --locale=ll_CC     Use this locale."));
                $c->writeln(_("  -m, --module=MODULE    Merge PO files only for this (Horde) module."));
                $c->writeln(_("  -c, --compendium=FILE  Use this compendium file instead of the default\n                         one (compendium.po in the horde/po directory)."));
                $c->writeln(_("  -n, --no-compendium    Don't use a compendium."));
                break;
            case 'update':
                $c->writeln(_("  -l, --locale=ll_CC     Use this locale."));
                $c->writeln(_("  -m, --module=MODULE    Update only this (Horde) module."));
                $c->writeln(_("  -c, --compendium=FILE  Use this compendium file instead of the default\n                         one (compendium.po in the horde/po directory)."));
                $c->writeln(_("  -n, --no-compendium    Don't use a compendium."));
                break;
        }
    } else {
        $c->writeln(_("Usage:") . ' translation.php [options] command [command-options]');
        $c->writeln(str_repeat(' ', String::length(_("Usage:"))) . ' translation.php [help|-h|--help] [command]');
        $c->writeln();
        $c->writeln(_("Helper application to create and maintain translations for the Horde\nframework and its applications.\nFor an introduction read the file README in this directory."));
        $c->writeln();
        $c->writeln(_("Commands:"));
        $c->writeln(_("  help        Show this help message."));
        $c->writeln(_("  compendium  Rebuild the compendium file. Warning: This overwrites the\n              current compendium."));
        $c->writeln(_("  extract     Generate PO template (.pot) files."));
        $c->writeln(_("  init        Create one or more PO files for a new locale. Warning: This\n              overwrites the existing PO files of this locale."));
        $c->writeln(_("  merge       Merge the current PO file with the current PO template file."));
        $c->writeln(_("  update      Run extract and merge sequent."));
        $c->writeln(_("  update-help Extract all new and changed entries from the English XML help\n              file and merge them with the existing ones."));
        $c->writeln(_("  cleanup     Cleans the PO files up from untranslated and obsolete entries."));
        $c->writeln(_("  make        Build binary MO files from the specified PO files."));
        $c->writeln(_("  make-help   Mark all entries in the XML help file being up-to-date and\n              prepare the file for the next execution of update-help. You\n              should only run make-help AFTER update-help and revising the\n              help file."));
        $c->writeln(_("  commit      Commit translations to the CVS server."));
        $c->writeln(_("  commit-help Commit help files to the CVS server."));
    }
    $c->writeln();
    $c->writeln(_("Options:"));
    $c->writeln(_("  -b, --base=/PATH  Full path to the (Horde) base directory that should be\n                    used."));
    $c->writeln(_("  -d, --debug       Show error messages from the executed binaries."));
    $c->writeln(_("  -h, --help        Show this help message."));
    $c->writeln(_("  -t, --test        Show the executed commands but don't run anything."));
}
Exemplo n.º 18
0
<?php

if (!empty($BlogPosts)) {
    foreach ($BlogPosts as $entry) {
        $text = $BlogPostFormater->format($entry->text);
        $text = trim(strip_tags($text));
        if ($entry->isEmpty('headline')) {
            $headline = String::truncate(strip_tags($text), 60, '…');
        } else {
            $headline = strip_tags($entry->get('headline'));
        }
        $headline = strftime('%F %H:%M', $entry->published) . ' ' . $headline;
        echo $headline . LF;
        echo str_repeat('=', String::length($headline)) . LF;
        echo $text . LF . LF;
    }
}
 public function testRandom()
 {
     $string = new String("Test15");
     $this->assertEquals(10, $string->length($string->random()));
     $this->assertFalse($string->random() == $string->random());
 }
Exemplo n.º 20
0
 protected function changeView($view)
 {
     if (is_array($view)) {
         if (count($view) === 2) {
             if ($view[0] === 'global') {
                 return 'globals/views/' . $view[1] . PHP;
             }
             return 'apps/views/' . $view[0] . '/' . $view[1] . PHP;
         } else {
             $view = $view[0];
         }
     }
     $cont = String::substr(get_class($this), 0, -String::length('Controller'));
     return 'apps/views/' . $cont . '/' . $view . PHP;
 }
Exemplo n.º 21
0
 /**
  * Length validator: is control's value length in range?
  * @param  TextBase
  * @param  array  min and max length pair
  * @return bool
  */
 public static function validateLength(TextBase $control, $range)
 {
     if (!is_array($range)) {
         $range = array($range, $range);
     }
     $len = String::length($control->getValue());
     return ($range[0] === NULL || $len >= $range[0]) && ($range[1] === NULL || $len <= $range[1]);
 }