2013-10-04 19:53:11 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "misc.h"
|
2014-02-12 16:31:30 +00:00
|
|
|
#include "mpconfig.h"
|
2013-10-04 19:53:11 +01:00
|
|
|
|
|
|
|
// attribute flags
|
|
|
|
#define FL_PRINT (0x01)
|
|
|
|
#define FL_SPACE (0x02)
|
|
|
|
#define FL_DIGIT (0x04)
|
|
|
|
#define FL_ALPHA (0x08)
|
|
|
|
#define FL_UPPER (0x10)
|
|
|
|
#define FL_LOWER (0x20)
|
|
|
|
|
|
|
|
// shorthand character attributes
|
|
|
|
#define AT_PR (FL_PRINT)
|
|
|
|
#define AT_SP (FL_SPACE | FL_PRINT)
|
|
|
|
#define AT_DI (FL_DIGIT | FL_PRINT)
|
|
|
|
#define AT_AL (FL_ALPHA | FL_PRINT)
|
|
|
|
#define AT_UP (FL_UPPER | FL_ALPHA | FL_PRINT)
|
|
|
|
#define AT_LO (FL_LOWER | FL_ALPHA | FL_PRINT)
|
|
|
|
|
|
|
|
// table of attributes for ascii characters
|
2014-02-12 16:31:30 +00:00
|
|
|
STATIC const uint8_t attr[] = {
|
2013-10-04 19:53:11 +01:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, AT_SP, AT_SP, AT_SP, 0, AT_SP, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
AT_SP, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR,
|
|
|
|
AT_PR, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR,
|
|
|
|
AT_DI, AT_DI, AT_DI, AT_DI, AT_DI, AT_DI, AT_DI, AT_DI,
|
|
|
|
AT_DI, AT_DI, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR,
|
|
|
|
AT_PR, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP,
|
|
|
|
AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP,
|
|
|
|
AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP, AT_UP,
|
|
|
|
AT_UP, AT_UP, AT_UP, AT_PR, AT_PR, AT_PR, AT_PR, AT_PR,
|
|
|
|
AT_PR, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO,
|
|
|
|
AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO,
|
|
|
|
AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO, AT_LO,
|
|
|
|
AT_LO, AT_LO, AT_LO, AT_PR, AT_PR, AT_PR, AT_PR, 0
|
|
|
|
};
|
|
|
|
|
2013-12-30 18:23:50 +00:00
|
|
|
unichar utf8_get_char(const char *s) {
|
2013-10-04 19:53:11 +01:00
|
|
|
return *s;
|
|
|
|
}
|
|
|
|
|
2013-12-30 18:23:50 +00:00
|
|
|
char *utf8_next_char(const char *s) {
|
2013-10-04 19:53:11 +01:00
|
|
|
return (char*)(s + 1);
|
|
|
|
}
|
|
|
|
|
2013-12-30 18:23:50 +00:00
|
|
|
bool unichar_isspace(unichar c) {
|
2013-10-04 19:53:11 +01:00
|
|
|
return c < 128 && (attr[c] & FL_SPACE) != 0;
|
|
|
|
}
|
|
|
|
|
2013-12-30 18:23:50 +00:00
|
|
|
bool unichar_isalpha(unichar c) {
|
2013-10-04 19:53:11 +01:00
|
|
|
return c < 128 && (attr[c] & FL_ALPHA) != 0;
|
|
|
|
}
|
|
|
|
|
2013-12-30 18:23:50 +00:00
|
|
|
bool unichar_isprint(unichar c) {
|
2013-10-04 19:53:11 +01:00
|
|
|
return c < 128 && (attr[c] & FL_PRINT) != 0;
|
|
|
|
}
|
|
|
|
|
2013-12-30 18:23:50 +00:00
|
|
|
bool unichar_isdigit(unichar c) {
|
2013-10-04 19:53:11 +01:00
|
|
|
return c < 128 && (attr[c] & FL_DIGIT) != 0;
|
|
|
|
}
|
|
|
|
|
2014-01-22 20:40:02 +00:00
|
|
|
bool unichar_isxdigit(unichar c) {
|
|
|
|
return unichar_isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
|
|
|
}
|
|
|
|
|
2013-10-04 19:53:11 +01:00
|
|
|
/*
|
|
|
|
bool char_is_alpha_or_digit(unichar c) {
|
|
|
|
return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool char_is_upper(unichar c) {
|
|
|
|
return c < 128 && (attr[c] & FL_UPPER) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool char_is_lower(unichar c) {
|
|
|
|
return c < 128 && (attr[c] & FL_LOWER) != 0;
|
|
|
|
}
|
|
|
|
*/
|