MCPcopy Create free account
hub / github.com/PricelessToolkit/MailBoxGuard / utf8ascii

Method utf8ascii

Code/Arduino_libraries/SSD1306/OLEDDisplay.cpp:1108–1133  ·  view source on GitHub ↗

You need to free the char!

Source from the content-addressed store, hash-verified

1106
1107// You need to free the char!
1108char* OLEDDisplay::utf8ascii(const String &str) {
1109 uint16_t k = 0;
1110 uint16_t length = str.length() + 1;
1111
1112 // Copy the string into a char array
1113 char* s = (char*) malloc(length * sizeof(char));
1114 if(!s) {
1115 DEBUG_OLEDDISPLAY("[OLEDDISPLAY][utf8ascii] Can't allocate another char array. Drop support for UTF-8.\n");
1116 return (char*) str.c_str();
1117 }
1118 str.toCharArray(s, length);
1119
1120 length--;
1121
1122 for (uint16_t i=0; i < length; i++) {
1123 char c = (this->fontTableLookupFunction)(s[i]);
1124 if (c!=0) {
1125 s[k++]=c;
1126 }
1127 }
1128
1129 s[k]=0;
1130
1131 // This will leak 's' be sure to free it in the calling function.
1132 return s;
1133}
1134
1135void OLEDDisplay::setFontTableLookupFunction(FontTableLookupFunction function) {
1136 this->fontTableLookupFunction = function;

Callers

nothing calls this directly

Calls 3

lengthMethod · 0.45
c_strMethod · 0.45
toCharArrayMethod · 0.45

Tested by

no test coverage detected