Skip to content

Commit

Permalink
Merge pull request #14 from juliangut/fix/unicode-emoji
Browse files Browse the repository at this point in the history
Fix/unicode emoji
  • Loading branch information
juliangut authored May 27, 2019
2 parents ccdbf6d + 83f0cfa commit d80bcbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
14 changes: 10 additions & 4 deletions SMSCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,20 @@ public function utf8ToUnicode($str)
}

if ($thisValue >= 128) {
if (count($values) == 0) {
$lookingFor = ($thisValue < 224) ? 2 : 3;
if (count($values) === 0) {
$lookingFor = 2;

if ($thisValue >= 240) {
$lookingFor = 4;
} elseif ($thisValue >= 224) {
$lookingFor = 3;
}
}

$values[] = $thisValue;

if (count($values) == $lookingFor) {
$number = ($lookingFor == 3) ?
if (count($values) === $lookingFor) {
$number = ($lookingFor === 3) ?
(($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64) :
(($values[0] % 32) * 64) + ($values[1] % 64);

Expand Down
17 changes: 17 additions & 0 deletions Tests/SMSCounterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ public function testUnicode()
$this->assertEquals($expected, $count);
}

public function testUnicodeEmoji()
{
$text = '😎😎';

$smsCounter = new SMSCounter();
$count = $smsCounter->count($text);

$expected = new \stdClass();
$expected->encoding = SMSCounter::UTF16;
$expected->length = 2;
$expected->per_message = 70;
$expected->remaining = 68;
$expected->messages = 1;

$this->assertEquals($expected, $count);
}

public function testRemoveNonGSMChars()
{
$text = 'áno-unicode-remaining` ñ';
Expand Down

0 comments on commit d80bcbf

Please sign in to comment.