Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String: Add fromUtf8ToEAscii. #177

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,4 +747,38 @@
return 0;
}

String String::fromUtf8ToEAscii(void) const
{
/*
* references :
* https://www.ime.usp.br/~pf/algoritmos/apend/unicode.html

Check failure on line 754 in api/String.cpp

View workflow job for this annotation

GitHub Actions / spellcheck

apend ==> append
* https://www.utf8-chartable.de/unicode-utf8-table.pl
* https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
*/
String eAsciiString;
for (uint8_t i=0; i< length(); i++)
{
uint8_t byteScope = (uint8_t)buffer[i];
if (byteScope < 0x7F)
{
eAsciiString += buffer[i];
}
else if (byteScope == 0xC3)
{
i++;
byteScope = (uint8_t)buffer[i];
if (byteScope > 0x7F)
eAsciiString += (char)(byteScope+0x40);
}
else if (byteScope == 0xC2)
{
i++;
byteScope = (uint8_t)buffer[i];
if (byteScope > 0x7F)
eAsciiString += (char)(byteScope);
}
}
return eAsciiString;
}

} // namespace arduino
1 change: 1 addition & 0 deletions api/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class String
long toInt(void) const;
float toFloat(void) const;
double toDouble(void) const;
String fromUtf8ToEAscii(void) const;

protected:
char *buffer; // the actual char array
Expand Down
Loading