Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Merge 7394623 into 8750c5c
Browse files Browse the repository at this point in the history
  • Loading branch information
weberhofer committed Jan 4, 2017
2 parents 8750c5c + 7394623 commit f1dae31
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 238 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"require-dev" : {
"ext-gd": "*",
"phpunit/phpunit": "4.4.*",
"squizlabs/php_codesniffer": "2.*",
"phpunit/phpunit": "4.8.*",
"squizlabs/php_codesniffer": "3.0.0RC2",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
Expand Down
14 changes: 7 additions & 7 deletions src/Pel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Pel
* Flag that controls if dgettext can be used.
* Is set to true or fals at the first access
*
* @var unknown
* @var boolean|NULL
*/
private static $hasdgetext = null;

Expand Down Expand Up @@ -253,12 +253,12 @@ public static function getDebug()
* @param string $format
* the format string.
*
* @param mixed $args,...
* @param mixed ...$args
* any number of arguments can be given. The
* arguments will be available for the format string as usual with
* sprintf().
*/
public static function debug()
public static function debug($format)
{
if (self::$debug) {
$args = func_get_args();
Expand All @@ -278,12 +278,12 @@ public static function debug()
* @param string $format
* the format string.
*
* @param mixed $args,...
* @param mixed ...$args
* any number of arguments can be given. The
* arguments will be available for the format string as usual with
* sprintf().
*/
public static function warning()
public static function warning($format)
{
if (self::$debug) {
$args = func_get_args();
Expand Down Expand Up @@ -325,15 +325,15 @@ public static function tra($str)
* the format string. This will be translated
* before being used as a format string.
*
* @param mixed $args,...
* @param mixed ...$args
* any number of arguments can be given. The
* arguments will be available for the format string as usual with
* sprintf().
*
* @return string the translated string, or the original string if
* no translation could be found.
*/
public static function fmt()
public static function fmt($format)
{
$args = func_get_args();
$str = array_shift($args);
Expand Down
166 changes: 80 additions & 86 deletions src/PelConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class PelConvert
/**
* Convert an unsigned short into two bytes.
*
* @param
* int the unsigned short that will be converted. The lower
* @param integer $value
* the unsigned short that will be converted. The lower
* two bytes will be extracted regardless of the actual size passed.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the unsigned short.
Expand All @@ -97,12 +97,12 @@ public static function shortToBytes($value, $endian)
/**
* Convert a signed short into two bytes.
*
* @param
* int the signed short that will be converted. The lower
* @param integer $value
* the signed short that will be converted. The lower
* two bytes will be extracted regardless of the actual size passed.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the signed short.
Expand All @@ -124,15 +124,15 @@ public static function sShortToBytes($value, $endian)
* larger than 2^31-1 will be promoted to 64 bit signed floating
* point numbers, and so such large numbers can be handled too.
*
* @param
* int the unsigned long that will be converted. The
* @param integer $value
* the unsigned long that will be converted. The
* argument will be treated as an unsigned 32 bit integer and the
* lower four bytes will be extracted. Treating the argument as an
* unsigned integer means that the absolute value will be used. Use
* {@link sLongToBytes} to convert signed integers.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the unsigned long.
Expand All @@ -148,22 +148,24 @@ public static function longToBytes($value, $endian)
*/
$hex = str_pad(base_convert($value, 10, 16), 8, '0', STR_PAD_LEFT);
if ($endian == self::LITTLE_ENDIAN) {
return (chr(hexdec($hex{6} . $hex{7})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{0} . $hex{1})));
return (chr(hexdec($hex{6} . $hex{7})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{2} . $hex{3})) .
chr(hexdec($hex{0} . $hex{1})));
} else {
return (chr(hexdec($hex{0} . $hex{1})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{6} . $hex{7})));
return (chr(hexdec($hex{0} . $hex{1})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{4} . $hex{5})) .
chr(hexdec($hex{6} . $hex{7})));
}
}

/**
* Convert a signed long into four bytes.
*
* @param
* int the signed long that will be converted. The argument
* @param integer $value
* the signed long that will be converted. The argument
* will be treated as a signed 32 bit integer, from which the lower
* four bytes will be extracted.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*
* @return string the bytes representing the signed long.
Expand All @@ -186,15 +188,15 @@ public static function sLongToBytes($value, $endian)
/**
* Extract an unsigned byte from a string of bytes.
*
* @param
* string the bytes.
* @param string $bytes
* the bytes.
*
* @param
* int the offset. The byte found at the offset will be
* @param integer $offset
* The byte found at the offset will be
* returned as an integer. The must be at least one byte available
* at offset.
*
* @return int the unsigned byte found at offset, e.g., an integer
* @return integer $offset the unsigned byte found at offset, e.g., an integer
* in the range 0 to 255.
*/
public static function bytesToByte($bytes, $offset)
Expand All @@ -205,15 +207,15 @@ public static function bytesToByte($bytes, $offset)
/**
* Extract a signed byte from bytes.
*
* @param
* string the bytes.
* @param string $bytes
* the bytes.
*
* @param
* int the offset. The byte found at the offset will be
* @param integer $offset
* the offset. The byte found at the offset will be
* returned as an integer. The must be at least one byte available
* at offset.
*
* @return int the signed byte found at offset, e.g., an integer in
* @return integer the signed byte found at offset, e.g., an integer in
* the range -128 to 127.
*/
public static function bytesToSByte($bytes, $offset)
Expand All @@ -229,20 +231,19 @@ public static function bytesToSByte($bytes, $offset)
/**
* Extract an unsigned short from bytes.
*
* @param
* string the bytes.
* @param string $bytes
* the bytes.
*
* @param
* int the offset. The short found at the offset will be
* @param integer $offset
* the offset. The short found at the offset will be
* returned as an integer. There must be at least two bytes
* available beginning at the offset given.
*
* @return int the unsigned short found at offset, e.g., an integer
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
* @return integer the unsigned short found at offset, e.g., an integer
* in the range 0 to 65535.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
public static function bytesToShort($bytes, $offset, $endian)
{
Expand All @@ -256,20 +257,18 @@ public static function bytesToShort($bytes, $offset, $endian)
/**
* Extract a signed short from bytes.
*
* @param
* string the bytes.
* @param string $bytes
*
* @param
* int the offset. The short found at offset will be returned
* @param integer $offset
* The short found at offset will be returned
* as an integer. There must be at least two bytes available
* beginning at the offset given.
*
* @return int the signed byte found at offset, e.g., an integer in
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
* @return integer the signed byte found at offset, e.g., an integer in
* the range -32768 to 32767.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
public static function bytesToSShort($bytes, $offset, $endian)
{
Expand All @@ -284,47 +283,45 @@ public static function bytesToSShort($bytes, $offset, $endian)
/**
* Extract an unsigned long from bytes.
*
* @param
* string the bytes.
* @param string $bytes
*
* @param
* int the offset. The long found at offset will be returned
* @param integer $offset
* The long found at offset will be returned
* as an integer. There must be at least four bytes available
* beginning at the offset given.
*
* @return int the unsigned long found at offset, e.g., an integer
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
* @return integer the unsigned long found at offset, e.g., an integer
* in the range 0 to 4294967295.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
public static function bytesToLong($bytes, $offset, $endian)
{
if ($endian == self::LITTLE_ENDIAN) {
return (ord($bytes{$offset + 3}) * 16777216 + ord($bytes{$offset + 2}) * 65536 + ord($bytes{$offset + 1}) * 256 + ord($bytes{$offset}));
return (ord($bytes{$offset + 3}) * 16777216 + ord($bytes{$offset + 2}) * 65536 +
ord($bytes{$offset + 1}) * 256 + ord($bytes{$offset}));
} else {
return (ord($bytes{$offset}) * 16777216 + ord($bytes{$offset + 1}) * 65536 + ord($bytes{$offset + 2}) * 256 + ord($bytes{$offset + 3}));
return (ord($bytes{$offset}) * 16777216 + ord($bytes{$offset + 1}) * 65536 + ord($bytes{$offset + 2}) * 256 +
ord($bytes{$offset + 3}));
}
}

/**
* Extract a signed long from bytes.
*
* @param
* string the bytes.
* @param string $bytes
*
* @param
* int the offset. The long found at offset will be returned
* @param integer $offset
* The long found at offset will be returned
* as an integer. There must be at least four bytes available
* beginning at the offset given.
*
* @return int the signed long found at offset, e.g., an integer in
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}. *
* @return integer the signed long found at offset, e.g., an integer in
* the range -2147483648 to 2147483647.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
public static function bytesToSLong($bytes, $offset, $endian)
{
Expand All @@ -339,20 +336,18 @@ public static function bytesToSLong($bytes, $offset, $endian)
/**
* Extract an unsigned rational from bytes.
*
* @param
* string the bytes.
* @param string $bytes
*
* @param
* int the offset. The rational found at offset will be
* @param integer $offset
* The rational found at offset will be
* returned as an array. There must be at least eight bytes
* available beginning at the offset given.
*
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}. *
* @return array the unsigned rational found at offset, e.g., an
* array with two integers in the range 0 to 4294967295.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
public static function bytesToRational($bytes, $offset, $endian)
{
Expand All @@ -365,20 +360,18 @@ public static function bytesToRational($bytes, $offset, $endian)
/**
* Extract a signed rational from bytes.
*
* @param
* string the bytes.
* @param string $bytes
*
* @param
* int the offset. The rational found at offset will be
* @param integer $offset
* The rational found at offset will be
* returned as an array. There must be at least eight bytes
* available beginning at the offset given.
*
* @param integer $endian
* one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
* @return array the signed rational found at offset, e.g., an array
* with two integers in the range -2147483648 to 2147483647.
*
* @param
* PelByteOrder one of {@link LITTLE_ENDIAN} and {@link
* BIG_ENDIAN}.
*/
public static function bytesToSRational($bytes, $offset, $endian)
{
Expand All @@ -395,13 +388,14 @@ public static function bytesToSRational($bytes, $offset, $endian)
* hexadecimal dump suitable for display on a terminal. The output
* is printed directly to standard out.
*
* @param
* string the bytes that will be dumped.
* @param string $bytes
* the bytes that will be dumped.
*
* @param
* int the maximum number of bytes to dump. If this is left
* @param integer $max
* the maximum number of bytes to dump. If this is left
* out (or left to the default of 0), then the entire string will be
* dumped.
* @return void
*/
public static function bytesToDump($bytes, $max = 0)
{
Expand Down
Loading

0 comments on commit f1dae31

Please sign in to comment.