alecpl
2009-06-03 1ae1d85ce493f9cc0a978038f65bbf69dc51acb0
program/include/rcube_shared.inc
@@ -170,7 +170,7 @@
      foreach ($var as $key => $value)
      {
        // enclose key with quotes if it is not variable-name conform
        if (!ereg("^[_a-zA-Z]{1}[_a-zA-Z0-9]*$", $key) || is_js_reserved_word($key))
        if (!preg_match('/^[_a-zA-Z]{1}[_a-zA-Z0-9]*$/', $key) || is_js_reserved_word($key))
          $key = "'$key'";
        $pairs[] = sprintf("%s%s", $is_assoc ? "$key:" : '', json_serialize($value));
@@ -238,12 +238,12 @@
 * Parse a human readable string for a number of bytes
 *
 * @param string Input string
 * @return int Number of bytes
 * @return float Number of bytes
 */
function parse_bytes($str)
{
  if (is_numeric($str))
    return intval($str);
    return floatval($str);
    
  if (preg_match('/([0-9]+)([a-z])/i', $str, $regs))
  {
@@ -262,7 +262,7 @@
    }
  }
  return intval($bytes);
  return floatval($bytes);
}
    
/**
@@ -405,6 +405,54 @@
    return strrpos($haystack, $needle, $offset);
}
/**
 * Wrapper function for wordwrap
 */
function rc_wordwrap($string, $width=75, $break="\n", $cut=false)
{
  if (!function_exists('mb_substr') || !function_exists('mb_strlen'))
    return wordwrap($string, $width, $break, $cut);
  $para = explode($break, $string);
  $string = '';
  while (count($para)) {
    $list = explode(' ', array_shift($para));
    $len = 0;
    while (count($list)) {
      $line = array_shift($list);
      $l = mb_strlen($line);
      $newlen = $len + $l + ($len ? 1 : 0);
      if ($newlen <= $width) {
        $string .= ($len ? ' ' : '').$line;
        $len += ($len ? 1 : 0) + $l;
      } else {
   if ($l > $width) {
     if ($cut) {
       $start = 0;
       while ($l) {
         $str = mb_substr($line, $start, $width);
         $strlen = mb_strlen($str);
         $string .= ($len ? $break : '').$str;
         $start += $strlen;
         $l -= $strlen;
         $len = $strlen;
       }
     } else {
            $string .= ($len ? $break : '').$line;
       if (count($list)) $string .= $break;
       $len = 0;
     }
   } else {
          $string .= $break.$line;
     $len = $l;
        }
      }
    }
    if (count($para)) $string .= $break;
  }
  return $string;
}
/**
 * Read a specific HTTP request header