handle title Unicode Bidirectional control

This commit is contained in:
hathach committed 2017-04-17 13:57:13 +07:00
1 parent 3b4cef0941
commit 3f5d8cc3f1
2 files changed
+26 -4

No files matched your search

@@ -114,7 +114,7 @@ void connect_callback(void)
Serial.println("Found it");
// ANCS requires pairing to work, it makes sense to request security here as well
Serial.print("Attempt to bond/pair with iOS, please press PAIR on your phone ... ");
Serial.print("Attempt to PAIR with iOS, please press PAIR on your phone ... ");
if ( Bluefruit.requestPairing() )
{
Serial.println("Done");
@@ -139,10 +139,13 @@ void ancs_notification_callback(AncsNotification_t* notif)
Serial.print(" | ");
// Get notification Title
// iDevice often include Unicode "Bidirection Text Control" in the Title.
// Mostly are U+202D as beginning and U+202C as ending. You may want to remove them
// U+202D is E2-80-AD, U+202C is E2-80-AC in UTF-8
memset(buffer, 0, sizeof(buffer));
bleancs.getAttribute(notif->uid, ANCS_ATTR_TITLE, buffer, sizeof(buffer));
Serial.printf("%-14s | ", buffer);
// Get notification Message
memset(buffer, 0, sizeof(buffer));
bleancs.getAttribute(notif->uid, ANCS_ATTR_MESSAGE, buffer, sizeof(buffer));
@@ -212,6 +212,26 @@ void displayNotification(int index)
{
notif->title[0] = 0; // invalid data if failed to receive
}
else
{
// iDevice often include Unicode "Bidirection Text Control" in the Title.
// Mostly are U+202D as beginning and U+202C as ending. Let's remove them
char u202D[3] = { 0xE2, 0x80, 0xAD }; // U+202D in UTF-8
char u202C[3] = { 0xE2, 0x80, 0xAC }; // U+202C in UTF-8
int len = strlen(notif->title);
if ( 0 == memcmp(&notif->title[len-3], u202C, 3) )
{
len -= 3;
notif->title[len] = 0; // chop ending U+202C
}
if ( 0 == memcmp(notif->title, u202D, 3) )
{
memmove(notif->title, notif->title+3, len-2); // move null-terminator as well
}
}
}
if ( notif->message[0] == 0 )
@@ -244,8 +264,7 @@ void displayNotification(int index)
oled.println(" Btn C to DECLINE");
}else
{
// Text size = 1, max char is 21
// Text size = 2, max char is 10
// Text size = 1, max char is 21. Text size = 2, max char is 10
char tempbuf[22];
sprintf(tempbuf, "%-15s %02d/%02d", notif->app_name, index+1, notifCount);