File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -753,4 +753,38 @@ double String::toDouble(void) const
753
753
return 0 ;
754
754
}
755
755
756
+ String String::fromUtf8ToEAscii (void ) const
757
+ {
758
+ /*
759
+ * references :
760
+ * https://www.ime.usp.br/~pf/algoritmos/apend/unicode.html
761
+ * https://www.utf8-chartable.de/unicode-utf8-table.pl
762
+ * https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
763
+ */
764
+ String eAsciiString;
765
+ for (uint8_t i=0 ; i< length (); i++)
766
+ {
767
+ uint8_t byteScope = (uint8_t )buffer[i];
768
+ if (byteScope < 0x7F )
769
+ {
770
+ eAsciiString += buffer[i];
771
+ }
772
+ else if (byteScope == 0xC3 )
773
+ {
774
+ i++;
775
+ byteScope = (uint8_t )buffer[i];
776
+ if (byteScope > 0x7F )
777
+ eAsciiString += (char )(byteScope+0x40 );
778
+ }
779
+ else if (byteScope == 0xC2 )
780
+ {
781
+ i++;
782
+ byteScope = (uint8_t )buffer[i];
783
+ if (byteScope > 0x7F )
784
+ eAsciiString += (char )(byteScope);
785
+ }
786
+ }
787
+ return eAsciiString;
788
+ }
789
+
756
790
} // namespace arduino
Original file line number Diff line number Diff line change @@ -218,6 +218,7 @@ class String
218
218
long toInt (void ) const ;
219
219
float toFloat (void ) const ;
220
220
double toDouble (void ) const ;
221
+ String fromUtf8ToEAscii (void ) const ;
221
222
222
223
protected:
223
224
char *buffer; // the actual char array
You can’t perform that action at this time.
0 commit comments