Simplify counting of printable characters

This commit is contained in:
Scott Lahteine 2017-05-31 23:25:08 -05:00
parent 8d69394ae1
commit 4a96433b7e
3 changed files with 10 additions and 18 deletions

View file

@ -127,7 +127,6 @@
#define DECIMAL(a) (NUMERIC(a) || a == '.') #define DECIMAL(a) (NUMERIC(a) || a == '.')
#define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+') #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
#define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+') #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
#define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
#define COUNT(a) (sizeof(a)/sizeof(*a)) #define COUNT(a) (sizeof(a)/sizeof(*a))
#define ZERO(a) memset(a,0,sizeof(a)) #define ZERO(a) memset(a,0,sizeof(a))
#define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b))) #define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))

View file

@ -3885,11 +3885,7 @@ void lcd_init() {
int lcd_strlen(const char* s) { int lcd_strlen(const char* s) {
int i = 0, j = 0; int i = 0, j = 0;
while (s[i]) { while (s[i]) {
#if ENABLED(MAPPER_NON)
j++;
#else
if (PRINTABLE(s[i])) j++; if (PRINTABLE(s[i])) j++;
#endif
i++; i++;
} }
return j; return j;
@ -3898,11 +3894,7 @@ int lcd_strlen(const char* s) {
int lcd_strlen_P(const char* s) { int lcd_strlen_P(const char* s) {
int j = 0; int j = 0;
while (pgm_read_byte(s)) { while (pgm_read_byte(s)) {
#if ENABLED(MAPPER_NON)
j++;
#else
if (PRINTABLE(pgm_read_byte(s))) j++; if (PRINTABLE(pgm_read_byte(s))) j++;
#endif
s++; s++;
} }
return j; return j;
@ -4167,11 +4159,7 @@ void lcd_update() {
void set_utf_strlen(char* s, uint8_t n) { void set_utf_strlen(char* s, uint8_t n) {
uint8_t i = 0, j = 0; uint8_t i = 0, j = 0;
while (s[i] && (j < n)) { while (s[i] && (j < n)) {
#if ENABLED(MAPPER_NON)
j++;
#else
if (PRINTABLE(s[i])) j++; if (PRINTABLE(s[i])) j++;
#endif
i++; i++;
} }
while (j++ < n) s[i++] = ' '; while (j++ < n) s[i++] = ' ';

View file

@ -144,6 +144,8 @@
#endif // DISPLAY_CHARSET_HD44780 #endif // DISPLAY_CHARSET_HD44780
#endif // SIMULATE_ROMFONT #endif // SIMULATE_ROMFONT
#define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
#if ENABLED(MAPPER_C2C3) #if ENABLED(MAPPER_C2C3)
char charset_mapper(const char c) { char charset_mapper(const char c) {
@ -466,8 +468,11 @@
#define MAPPER_NON #define MAPPER_NON
#undef PRINTABLE
#define PRINTABLE(C) true
char charset_mapper(const char c) { char charset_mapper(const char c) {
HARDWARE_CHAR_OUT( c ); HARDWARE_CHAR_OUT(c);
return 1; return 1;
} }