$result = "";
$working = 0;
for( $i = 0; $i < strlen( $invalue ); $i++ ) {
- $bytevalue = ord( $invalue{$i} );
+ $bytevalue = ord( $invalue[$i] );
if ( $bytevalue <= 0x7F ) { //0xxx xxxx
$result .= chr( $bytevalue );
$bytesleft = 0;
function unmakesafe( $invalue ) {
$result = "";
for( $i = 0; $i < strlen( $invalue ); $i++ ) {
- if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
+ if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i+3] != '0' ) ) {
$i += 3;
$hexstring = "";
do {
- $hexstring .= $invalue{$i};
+ $hexstring .= $invalue[$i];
$i++;
- } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
+ } while( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
// Do some sanity checks. These aren't needed for reversability,
// but should help keep the breakage down if the editor
// This will cut out most of our slow time on Latin-based text,
// and 1/2 to 1/3 on East European and Asian scripts.
$bytePos = $splitPos;
- while ( $bytePos < $byteLen && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0" ) {
+ while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
++$bytePos;
}
$charPos = mb_strlen( substr( $str, 0, $bytePos ) );
while( $charPos++ < $splitPos ) {
++$bytePos;
// Move past any tail bytes
- while ( $bytePos < $byteLen && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0" ) {
+ while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
++$bytePos;
}
}
while( $bytePos > 0 && $charPos-- >= $splitPosX ) {
--$bytePos;
// Move past any tail bytes
- while ( $bytePos > 0 && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0" ) {
+ while ( $bytePos > 0 && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) {
--$bytePos;
}
}
// Decode and validate input string
$input = strtolower( $input );
for( $i = 0; $i < strlen( $input ); $i++ ) {
- $n = strpos( $digitChars, $input{$i} );
+ $n = strpos( $digitChars, $input[$i] );
if( $n === false || $n > $sourceBase ) {
return false;
}
return false;
}
- if( $head{0} != "\x00" || $head{74} != "\x00" ) {
+ if( $head[0] != "\x00" || $head[74] != "\x00" ) {
wfDebug( "$fname: header bytes 0 and 74 not null\n" );
return false;
}
}
} else {
$crc = sprintf( "%x != %x", $storedCRC, $calculatedCRC );
- if( $storedCRC == 0 && $head{82} == "\x00" &&
+ if( $storedCRC == 0 && $head[82] == "\x00" &&
substr( $head, 101, 24 ) == str_repeat( "\x00", 24 ) ) {
wfDebug( "$fname: no CRC, looks like MacBinary I\n" );
$this->version = 1;
}
}
- $nameLength = ord( $head{1} );
+ $nameLength = ord( $head[1] );
if( $nameLength < 1 || $nameLength > 63 ) {
wfDebug( "$fname: invalid filename size $nameLength\n" );
return false;
$len = strlen( $data );
$crc = $seed;
for( $i = 0; $i < $len; $i++ ) {
- $crc ^= ord( $data{$i} ) << 8;
+ $crc ^= ord( $data[$i] ) << 8;
$crc &= 0xFFFF;
$crc = ($crc << 8) ^ $MAGIC[$crc >> 8];
$crc &= 0xFFFF;
$line = sprintf( "%04x:", $at );
$printable = '';
for( $i = 0; $i < $width && $remaining - $i > 0; $i++ ) {
- $byte = ord( $data{$at++} );
+ $byte = ord( $data[$at++] );
$line .= sprintf( " %02x", $byte );
$printable .= ($byte >= 32 && $byte <= 126 )
? chr( $byte )
$digit = mt_rand( 0, $pwlength - 1 );
$np = '';
for ( $i = 0; $i < $pwlength; $i++ ) {
- $np .= $i == $digit ? chr( mt_rand( 48, 57 ) ) : $pwchars{ mt_rand( 0, $l ) };
+ $np .= $i == $digit ? chr( mt_rand( 48, 57 ) ) : $pwchars[ mt_rand( 0, $l ) ];
}
return $np;
}
if( $hash !== false ) {
$base = substr( $base, 0, $hash );
}
- if( $base{0} == '/' ) {
+ if( $base[0] == '/' ) {
return $base;
} else {
// We may get paths with a host prepended; strip it.
$handle = opendir( $dir );
if ( $handle ) {
while ( false !== ( $file = readdir($handle) ) ) {
- if ( $file{0} != '.' ) {
+ if ( $file[0] != '.' ) {
$files[] = $file;
}
}
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
}
- $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
+ $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]);
switch(true) {
case ((0x7F & $bytes) == $bytes):
return chr(0xC0 | (($bytes >> 6) & 0x1F))
. chr(0x80 | ($bytes & 0x3F));
- case (0xFC00 & $bytes) == 0xD800 && strlen($utf16) >= 4 && (0xFC & ord($utf16{2})) == 0xDC:
+ case (0xFC00 & $bytes) == 0xD800 && strlen($utf16) >= 4 && (0xFC & ord($utf16[2])) == 0xDC:
// return a 4-byte UTF-8 character
$char = ((($bytes & 0x03FF) << 10)
- | ((ord($utf16{2}) & 0x03) << 8)
- | ord($utf16{3}));
+ | ((ord($utf16[2]) & 0x03) << 8)
+ | ord($utf16[3]));
$char += 0x10000;
return chr(0xF0 | (($char >> 18) & 0x07))
. chr(0x80 | (($char >> 12) & 0x3F))
case 2:
// return a UTF-16 character from a 2-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr(0x07 & (ord($utf8{0}) >> 2))
- . chr((0xC0 & (ord($utf8{0}) << 6))
- | (0x3F & ord($utf8{1})));
+ return chr(0x07 & (ord($utf8[0]) >> 2))
+ . chr((0xC0 & (ord($utf8[0]) << 6))
+ | (0x3F & ord($utf8[1])));
case 3:
// return a UTF-16 character from a 3-byte UTF-8 char
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr((0xF0 & (ord($utf8{0}) << 4))
- | (0x0F & (ord($utf8{1}) >> 2)))
- . chr((0xC0 & (ord($utf8{1}) << 6))
- | (0x7F & ord($utf8{2})));
+ return chr((0xF0 & (ord($utf8[0]) << 4))
+ | (0x0F & (ord($utf8[1]) >> 2)))
+ . chr((0xC0 & (ord($utf8[1]) << 6))
+ | (0x7F & ord($utf8[2])));
case 4:
// return a UTF-16 surrogate pair from a 4-byte UTF-8 char
- if(ord($utf8{0}) > 0xF4) return ''; # invalid
- $char = ((0x1C0000 & (ord($utf8{0}) << 18))
- | (0x03F000 & (ord($utf8{1}) << 12))
- | (0x000FC0 & (ord($utf8{2}) << 6))
- | (0x00003F & ord($utf8{3})));
+ if(ord($utf8[0]) > 0xF4) return ''; # invalid
+ $char = ((0x1C0000 & (ord($utf8[0]) << 18))
+ | (0x03F000 & (ord($utf8[1]) << 12))
+ | (0x000FC0 & (ord($utf8[2]) << 6))
+ | (0x00003F & ord($utf8[3])));
if($char > 0x10FFFF) return ''; # invalid
$char -= 0x10000;
return chr(0xD8 | (($char >> 18) & 0x03))
*/
for ($c = 0; $c < $strlen_var; ++$c) {
- $ord_var_c = ord($var{$c});
+ $ord_var_c = ord($var[$c]);
switch (true) {
case $ord_var_c == 0x08:
case $ord_var_c == 0x2F:
case $ord_var_c == 0x5C:
// double quote, slash, slosh
- $ascii .= '\\'.$var{$c};
+ $ascii .= '\\'.$var[$c];
break;
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
// characters U-00000000 - U-0000007F (same as ASCII)
- $ascii .= $var{$c};
+ $ascii .= $var[$c];
break;
case (($ord_var_c & 0xE0) == 0xC0):
// characters U-00000080 - U-000007FF, mask 110XXXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
+ $char = pack('C*', $ord_var_c, ord($var[$c + 1]));
$c += 1;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}));
+ ord($var[$c + 1]),
+ ord($var[$c + 2]));
$c += 2;
$utf16 = $this->utf82utf16($char);
$ascii .= sprintf('\u%04s', bin2hex($utf16));
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
// These will always return a surrogate pair
$char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}));
+ ord($var[$c + 1]),
+ ord($var[$c + 2]),
+ ord($var[$c + 3]));
$c += 3;
$utf16 = $this->utf82utf16($char);
if($utf16 == '') {
for ($c = 0; $c < $strlen_chrs; ++$c) {
$substr_chrs_c_2 = substr($chrs, $c, 2);
- $ord_chrs_c = ord($chrs{$c});
+ $ord_chrs_c = ord($chrs[$c]);
switch (true) {
case $substr_chrs_c_2 == '\b':
case $substr_chrs_c_2 == '\\/':
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
- $utf8 .= $chrs{++$c};
+ $utf8 .= $chrs[++$c];
}
break;
break;
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
- $utf8 .= $chrs{$c};
+ $utf8 .= $chrs[$c];
break;
case ($ord_chrs_c & 0xE0) == 0xC0:
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
// array, or object notation
- if ($str{0} == '[') {
+ if ($str[0] == '[') {
$stk = array(SERVICES_JSON_IN_ARR);
$arr = array();
} else {
$top = end($stk);
$substr_chrs_c_2 = substr($chrs, $c, 2);
- if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
+ if (($c == $strlen_chrs) || (($chrs[$c] == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
// found a comma that is not inside a string, array, etc.,
// OR we've reached the end of the character list
$slice = substr($chrs, $top['where'], ($c - $top['where']));
}
- } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
+ } elseif ((($chrs[$c] == '"') || ($chrs[$c] == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
// found a quote, and we are not inside a string
- array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
+ array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]));
//print("Found start of string at {$c}\n");
- } elseif (($chrs{$c} == $top['delim']) &&
+ } elseif (($chrs[$c] == $top['delim']) &&
($top['what'] == SERVICES_JSON_IN_STR) &&
- (($chrs{$c - 1} != '\\') ||
- ($chrs{$c - 1} == '\\' && $chrs{$c - 2} == '\\'))) {
+ (($chrs[$c - 1] != '\\') ||
+ ($chrs[$c - 1] == '\\' && $chrs[$c - 2] == '\\'))) {
// found a quote, we're in a string, and it's not escaped
array_pop($stk);
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
- } elseif (($chrs{$c} == '[') &&
+ } elseif (($chrs[$c] == '[') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
//print("Found start of array at {$c}\n");
- } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
+ } elseif (($chrs[$c] == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
// found a right-bracket, and we're in an array
array_pop($stk);
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
- } elseif (($chrs{$c} == '{') &&
+ } elseif (($chrs[$c] == '{') &&
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
// found a left-brace, and we are in an array, object, or slice
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
//print("Found start of object at {$c}\n");
- } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
+ } elseif (($chrs[$c] == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
// found a right-brace, and we're in an object
array_pop($stk);
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
UtfNormal::loadData();
$len = strlen( $string );
for( $i = 0; $i < $len; $i++ ) {
- $c = $string{$i};
+ $c = $string[$i];
$n = ord( $c );
if( $n < 0x80 ) {
continue;
foreach( $matches[1] as $str ) {
$chunk = strlen( $str );
- if( $str{0} < "\x80" ) {
+ if( $str[0] < "\x80" ) {
# ASCII chunk: guaranteed to be valid UTF-8
# and in normal form C, so skip over it.
$base += $chunk;
$len = $chunk + 1; # Counting down is faster. I'm *so* sorry.
for( $i = -1; --$len; ) {
- $remaining = $tailBytes[$c = $str{++$i}];
+ $remaining = $tailBytes[$c = $str[++$i]];
if( $remaining ) {
# UTF-8 head byte!
$sequence = $head = $c;
do {
# Look for the defined number of tail bytes...
- if( --$len && ( $c = $str{++$i} ) >= "\x80" && $c < "\xc0" ) {
+ if( --$len && ( $c = $str[++$i] ) >= "\x80" && $c < "\xc0" ) {
# Legal tail bytes are nice.
$sequence .= $c;
} else {
$len = strlen( $string );
$out = '';
for( $i = 0; $i < $len; $i++ ) {
- $c = $string{$i};
+ $c = $string[$i];
$n = ord( $c );
if( $n < 0x80 ) {
# ASCII chars never decompose
# A lookup table would be slightly faster,
# but adds a lot of memory & disk needs.
#
- $index = ( (ord( $c{0} ) & 0x0f) << 12
- | (ord( $c{1} ) & 0x3f) << 6
- | (ord( $c{2} ) & 0x3f) )
+ $index = ( (ord( $c[0] ) & 0x0f) << 12
+ | (ord( $c[1] ) & 0x3f) << 6
+ | (ord( $c[2] ) & 0x3f) )
- UNICODE_HANGUL_FIRST;
$l = intval( $index / UNICODE_HANGUL_NCOUNT );
$v = intval( ($index % UNICODE_HANGUL_NCOUNT) / UNICODE_HANGUL_TCOUNT);
$combiners = array();
$lastClass = -1;
for( $i = 0; $i < $len; $i++ ) {
- $c = $string{$i};
+ $c = $string[$i];
$n = ord( $c );
if( $n >= 0x80 ) {
if( $n >= 0xf0 ) {
$x1 = ord(substr(UTF8_HANGUL_VBASE,0,1));
$x2 = ord(substr(UTF8_HANGUL_TEND,0,1));
for( $i = 0; $i < $len; $i++ ) {
- $c = $string{$i};
+ $c = $string[$i];
$n = ord( $c );
if( $n < 0x80 ) {
# No combining characters here...
#
#$lIndex = utf8ToCodepoint( $startChar ) - UNICODE_HANGUL_LBASE;
#$vIndex = utf8ToCodepoint( $c ) - UNICODE_HANGUL_VBASE;
- $lIndex = ord( $startChar{2} ) - 0x80;
- $vIndex = ord( $c{2} ) - 0xa1;
+ $lIndex = ord( $startChar[2] ) - 0x80;
+ $vIndex = ord( $c[2] ) - 0xa1;
$hangulPoint = UNICODE_HANGUL_FIRST +
UNICODE_HANGUL_TCOUNT *
$startChar <= UTF8_HANGUL_LAST &&
!$lastHangul ) {
# $tIndex = utf8ToCodepoint( $c ) - UNICODE_HANGUL_TBASE;
- $tIndex = ord( $c{2} ) - 0xa7;
- if( $tIndex < 0 ) $tIndex = ord( $c{2} ) - 0x80 + (0x11c0 - 0x11a7);
+ $tIndex = ord( $c[2] ) - 0xa7;
+ if( $tIndex < 0 ) $tIndex = ord( $c[2] ) - 0x80 + (0x11c0 - 0x11a7);
# Increment the code point by $tIndex, without
# the function overhead of decoding and recoding UTF-8
#
- $tail = ord( $startChar{2} ) + $tIndex;
+ $tail = ord( $startChar[2] ) + $tIndex;
if( $tail > 0xbf ) {
$tail -= 0x40;
- $mid = ord( $startChar{1} ) + 1;
+ $mid = ord( $startChar[1] ) + 1;
if( $mid > 0xbf ) {
- $startChar{0} = chr( ord( $startChar{0} ) + 1 );
+ $startChar[0] = chr( ord( $startChar[0] ) + 1 );
$mid -= 0x40;
}
- $startChar{1} = chr( $mid );
+ $startChar[1] = chr( $mid );
}
- $startChar{2} = chr( $tail );
+ $startChar[2] = chr( $tail );
# If there's another jamo char after this, *don't* try to merge it.
$lastHangul = 1;
$len = strlen( $string );
$out = '';
for( $i = 0; $i < $len; $i++ ) {
- $out .= $string{$i};
+ $out .= $string[$i];
}
return $out;
}
*/
function utf8ToCodepoint( $char ) {
# Find the length
- $z = ord( $char{0} );
+ $z = ord( $char[0] );
if ( $z & 0x80 ) {
$length = 0;
while ( $z & 0x80 ) {
# Add in the free bits from subsequent bytes
for ( $i=1; $i<$length; $i++ ) {
$z <<= 6;
- $z |= ord( $char{$i} ) & 0x3f;
+ $z |= ord( $char[$i] ) & 0x3f;
}
return $z;
$bits = array();
$key = $this->keys[$this->mSource];
for ( $p=0; $p < strlen($key); $p++ ) {
- if ( $key{$p} != ' ' ) {
- $bits[$key{$p}] = $matches[$p+1];
+ if ( $key[$p] != ' ' ) {
+ $bits[$key[$p]] = $matches[$p+1];
}
}
}
for ( $p=0; $p < strlen( $format ); $p++ ) {
- $char = $format{$p};
+ $char = $format[$p];
switch ( $char ) {
case 'd': # ISO day of month
$text .= $bits['d'];
* @todo document
*/
function makeNormalYear( $iso ) {
- if ( $iso{0} == '-' ) {
+ if ( $iso[0] == '-' ) {
$text = (intval( substr( $iso, 1 ) ) + 1) . ' BC';
} else {
$text = intval( $iso );
}
for ( $i = 0; $i < $shorter; ++$i ) {
- if ( $st1{$i} != $st2{$i} ) {
+ if ( $st1[$i] != $st2[$i] ) {
break;
}
}
$stack = 0;
$len = strlen( $str );
for( $i = 0; $i < $len; $i++ ) {
- $c = $str{$i};
+ $c = $str[$i];
switch( $state ) {
# (Using the number is a performance hack for common cases)
if( strlen( $isbn ) == 13 ) {
for( $i = 0; $i < 12; $i++ ) {
if($i % 2 == 0) {
- $sum += $isbn{$i};
+ $sum += $isbn[$i];
} else {
- $sum += 3 * $isbn{$i};
+ $sum += 3 * $isbn[$i];
}
}
$check = (10 - ($sum % 10)) % 10;
- if ($check == $isbn{12}) {
+ if ($check == $isbn[12]) {
return true;
}
} elseif( strlen( $isbn ) == 10 ) {
for($i = 0; $i < 9; $i++) {
- $sum += $isbn{$i} * ($i + 1);
+ $sum += $isbn[$i] * ($i + 1);
}
$check = $sum % 11;
if($check == 10) {
$check = "X";
}
- if($check == $isbn{9}) {
+ if($check == $isbn[9]) {
return true;
}
}
return Status::newFatal( 'nouserspecified' );
}
- if( $name{0} == '#' ) {
+ if( $name[0] == '#' ) {
// Numeric ID can be specified...
// We'll do a lookup for the name internally.
$id = intval( substr( $name, 1 ) );