Skip to content

Commit

Permalink
Fix PHP 7.2 Warning - mb_split(): mbregex compile err: invalid code p…
Browse files Browse the repository at this point in the history
…oint value. (#153)

Fixes an "invalid code point value" PHP warning in PHP 7.2

* Fixes coding standard issue.

* Adds mb_chr() to the README.
  • Loading branch information
pocketarc authored and u01jmg3 committed Aug 1, 2017
1 parent 9fc49ca commit 539ce70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var_dump($event->dtstart_array);
| `isValidTimeZoneId` | `$timeZone` | `protected` | Checks if a time zone is valid |
| `keyValueFromString` | `$text` | `protected` | Gets the key value pair from an iCal string |
| `mb_str_replace` | `$search`, `$replace`, `$subject`, `$count = 0` | `protected` | Replaces all occurrences of a search string with a given replacement string |
| `mb_chr` | `$code` | `protected` | Provides a polyfill for PHP 7.2's mb_chr(), which is a multibyte safe version of chr(). |
| `numberOfDays` | `$days`, `$start`, `$end` | `protected` | Gets the number of days between a start and end date |
| `parseDuration` | `$date`, `$duration`, `$format = 'U'` | `protected` | Parses a duration and applies it to a date |
| `processDateConversions` | - | `protected` | Processes date conversions using the time zone |
Expand Down
31 changes: 30 additions & 1 deletion src/ICal/ICal.php
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,32 @@ protected function mb_str_replace($search, $replace, $subject, &$count = 0)
return $subject;
}

/**
* Provides a polyfill for PHP 7.2's mb_chr(), which is a multibyte safe version of chr().
* Multibyte safe.
*
* @param integer $code
* @return string
*/
protected function mb_chr($code)
{
if (function_exists('mb_chr')) {
return mb_chr($code);
} else {
if (0x80 > $code %= 0x200000) {
$s = chr($code);
} elseif (0x800 > $code) {
$s = chr(0xC0 | $code >> 6) . chr(0x80 | $code & 0x3F);
} elseif (0x10000 > $code) {
$s = chr(0xE0 | $code >> 12) . chr(0x80 | $code >> 6 & 0x3F) . chr(0x80 | $code & 0x3F);
} else {
$s = chr(0xF0 | $code >> 18) . chr(0x80 | $code >> 12 & 0x3F) . chr(0x80 | $code >> 6 & 0x3F) . chr(0x80 | $code & 0x3F);
}

return $s;
}
}

/**
* Replaces curly quotes and other special characters
* with their standard equivalents
Expand Down Expand Up @@ -1948,7 +1974,10 @@ protected function cleanData($data)
$cleanedData = strtr($data, $replacementChars);

// Replace Windows-1252 equivalents
$cleanedData = $this->mb_str_replace(array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133), chr(194)), $replacementChars, $cleanedData);
$charsToReplace = array_map(function ($code) {
return $this->mb_chr($code);
}, array(133, 145, 146, 147, 148, 150, 151, 194));
$cleanedData = $this->mb_str_replace($charsToReplace, $replacementChars, $cleanedData);

return $cleanedData;
}
Expand Down

0 comments on commit 539ce70

Please sign in to comment.