"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/wikimedia/base-convert/src/Functions.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

Functions.php  (mediawiki-1.31.1):Functions.php  (mediawiki-1.32.0)
skipping to change at line 58 skipping to change at line 58
$destBase != (int)$destBase || $destBase != (int)$destBase ||
$pad != (int)$pad || $pad != (int)$pad ||
!preg_match( !preg_match(
"/^[" . substr( '0123456789abcdefghijklmnopqrstuvwxyz', 0 , $sourceBase ) . "]+$/i", "/^[" . substr( '0123456789abcdefghijklmnopqrstuvwxyz', 0 , $sourceBase ) . "]+$/i",
$input $input
) )
) { ) {
return false; return false;
} }
static $baseChars = array( static $baseChars = [
10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f', 10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f',
16 => 'g', 17 => 'h', 18 => 'i', 19 => 'j', 20 => 'k', 21 => 'l', 16 => 'g', 17 => 'h', 18 => 'i', 19 => 'j', 20 => 'k', 21 => 'l',
22 => 'm', 23 => 'n', 24 => 'o', 25 => 'p', 26 => 'q', 27 => 'r', 22 => 'm', 23 => 'n', 24 => 'o', 25 => 'p', 26 => 'q', 27 => 'r',
28 => 's', 29 => 't', 30 => 'u', 31 => 'v', 32 => 'w', 33 => 'x', 28 => 's', 29 => 't', 30 => 'u', 31 => 'v', 32 => 'w', 33 => 'x',
34 => 'y', 35 => 'z', 34 => 'y', 35 => 'z',
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5,
'6' => 6, '7' => 7, '8' => 8, '9' => 9, 'a' => 10, 'b' => 11, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'a' => 10, 'b' => 11,
'c' => 12, 'd' => 13, 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17, 'c' => 12, 'd' => 13, 'e' => 14, 'f' => 15, 'g' => 16, 'h' => 17,
'i' => 18, 'j' => 19, 'k' => 20, 'l' => 21, 'm' => 22, 'n' => 23, 'i' => 18, 'j' => 19, 'k' => 20, 'l' => 21, 'm' => 22, 'n' => 23,
'o' => 24, 'p' => 25, 'q' => 26, 'r' => 27, 's' => 28, 't' => 29, 'o' => 24, 'p' => 25, 'q' => 26, 'r' => 27, 's' => 28, 't' => 29,
'u' => 30, 'v' => 31, 'w' => 32, 'x' => 33, 'y' => 34, 'z' => 35 'u' => 30, 'v' => 31, 'w' => 32, 'x' => 33, 'y' => 34, 'z' => 35
); ];
if ( extension_loaded( 'gmp' ) && ( $engine == 'auto' || $engine == 'gmp' ) ) { if ( extension_loaded( 'gmp' ) && ( $engine == 'auto' || $engine == 'gmp' ) ) {
// Removing leading zeros works around broken base detection code in // Removing leading zeros works around broken base detection code in
// some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and // some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and
// <https://bugs.php.net/bug.php?id=55398>). // <https://bugs.php.net/bug.php?id=55398>).
$result = gmp_strval( gmp_init( ltrim( $input, '0' ) ?: '0', $sou rceBase ), $destBase ); $result = gmp_strval( gmp_init( ltrim( $input, '0' ) ?: '0', $sou rceBase ), $destBase );
} elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) { } elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) {
$decimal = '0'; $decimal = '0';
foreach ( str_split( strtolower( $input ) ) as $char ) { foreach ( str_split( strtolower( $input ) ) as $char ) {
$decimal = bcmul( $decimal, $sourceBase ); $decimal = bcmul( $decimal, $sourceBase );
$decimal = bcadd( $decimal, $baseChars[$char] ); $decimal = bcadd( $decimal, $baseChars[$char] );
} }
// @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTe stFunctionCall.NotAllowed // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTe stFunctionCall.NotAllowed
for ( $result = ''; bccomp( $decimal, 0 ); $decimal = bcdiv( $dec imal, $destBase, 0 ) ) { for ( $result = ''; bccomp( $decimal, 0 ); $decimal = bcdiv( $dec imal, $destBase, 0 ) ) {
$result .= $baseChars[bcmod( $decimal, $destBase )]; // As of PHP 7.2, bcmod can return a floating point value
if bcscale is nonzero
$result .= $baseChars[(int)bcmod( $decimal, $destBase )];
} }
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
$result = strrev( $result ); $result = strrev( $result );
} else { } else {
$inDigits = array(); $inDigits = [];
foreach ( str_split( strtolower( $input ) ) as $char ) { foreach ( str_split( strtolower( $input ) ) as $char ) {
$inDigits[] = $baseChars[$char]; $inDigits[] = $baseChars[$char];
} }
// Iterate over the input, modulo-ing out an output digit // Iterate over the input, modulo-ing out an output digit
// at a time until input is gone. // at a time until input is gone.
$result = ''; $result = '';
while ( $inDigits ) { while ( $inDigits ) {
$work = 0; $work = 0;
$workDigits = array(); $workDigits = [];
// Long division... // Long division...
foreach ( $inDigits as $digit ) { foreach ( $inDigits as $digit ) {
$work *= $sourceBase; $work *= $sourceBase;
$work += $digit; $work += $digit;
if ( $workDigits || $work >= $destBase ) { if ( $workDigits || $work >= $destBase ) {
$workDigits[] = (int)( $work / $destBase ); $workDigits[] = (int)( $work / $destBase );
} }
$work %= $destBase; $work %= $destBase;
 End of changes. 5 change blocks. 
5 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)