Make WordPress Core


Ignore:
Timestamp:
06/23/2009 04:33:27 PM (17 years ago)
Author:
ryan
Message:

Merge latest pomo. Works around mbstring.func_overload. Props nbachiyski. fixes #10236 for 2.8.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.8/wp-includes/pomo/streams.php

    r10584 r11627  
    44 * Based on the classes from Danilo Segan <danilo@kvota.net>
    55 *
    6  * @version $Id: streams.php 33 2009-02-16 09:33:39Z nbachiyski $
     6 * @version $Id: streams.php 138 2009-06-23 13:22:09Z nbachiyski $
    77 * @package pomo
    88 * @subpackage streams
    … …  
    1818  var $_str;
    1919
    20   function POMO_StringReader($str = '') {
    21     $this->_str = $str;
    22     $this->_pos = 0;
    23   }
     20        function POMO_StringReader($str = '') {
     21                $this->_str = $str;
     22                $this->_pos = 0;
     23                $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
     24        }
    2425
    25   function read($bytes) {
    26     $data = substr($this->_str, $this->_pos, $bytes);
    27     $this->_pos += $bytes;
    28     if (strlen($this->_str)<$this->_pos)
    29       $this->_pos = strlen($this->_str);
     26        function _substr($string, $start, $length) {
     27                if ($this->is_overloaded) {
     28                        return mb_substr($string,$start,$length,'ascii');
     29                } else {
     30                        return substr($string,$start,$length);
     31                }
     32        }
     33       
     34        function _strlen($string) {
     35                if ($this->is_overloaded) {
     36                        return mb_strlen($string,'ascii');
     37                } else {
     38                        return strlen($string);
     39                }
     40        }
    3041
    31     return $data;
    32   }
     42        function read($bytes) {
     43                $data = $this->_substr($this->_str, $this->_pos, $bytes);
     44                $this->_pos += $bytes;
     45                if ($this->_strlen($this->_str) < $this->_pos) $this->_pos = $this->_strlen($this->_str);
     46                return $data;
     47        }
    3348
    34   function seekto($pos) {
    35     $this->_pos = $pos;
    36     if (strlen($this->_str)<$this->_pos)
    37       $this->_pos = strlen($this->_str);
    38     return $this->_pos;
    39   }
     49        function seekto($pos) {
     50                $this->_pos = $pos;
     51                if ($this->_strlen($this->_str) < $this->_pos) $this->_pos = $this->_strlen($this->_str);
     52                return $this->_pos;
     53        }
    4054
    41   function pos() {
    42     return $this->_pos;
    43   }
     55        function pos() {
     56                return $this->_pos;
     57        }
    4458
    45   function length() {
    46     return strlen($this->_str);
    47   }
     59        function length() {
     60                return $this->_strlen($this->_str);
     61        }
    4862
    4963}
    … …  
    5468class POMO_CachedFileReader extends POMO_StringReader {
    5569        function POMO_CachedFileReader($filename) {
     70                parent::POMO_StringReader();
    5671                $this->_str = file_get_contents($filename);
    5772                if (false === $this->_str)
    5873                        return false;
    59                 $this->pos = 0;
     74                $this->_pos = 0;
    6075        }
    6176}
    … …  
    97112        function readint32() {
    98113                $bytes = $this->read(4);
    99                 if (4 != strlen($bytes))
     114                if (4 != $this->_strlen($bytes))
    100115                        return false;
    101116                $endian_letter = ('big' == $this->endian)? 'N' : 'V';
    … …  
    113128        function readint32array($count) {
    114129                $bytes = $this->read(4 * $count);
    115                 if (4*$count != strlen($bytes))
     130                if (4*$count != $this->_strlen($bytes))
    116131                        return false;
    117132                $endian_letter = ('big' == $this->endian)? 'N' : 'V';
Note: See TracChangeset for help on using the changeset viewer.