src/enc/yp_big5.c in yarp-0.9.0 vs src/enc/yp_big5.c in yarp-0.10.0
- old
+ new
@@ -1,70 +1,43 @@
#include "yarp/enc/yp_encoding.h"
-typedef uint16_t yp_big5_codepoint_t;
-
-static yp_big5_codepoint_t
-yp_big5_codepoint(const char *c, ptrdiff_t n, size_t *width) {
- const unsigned char *uc = (const unsigned char *) c;
-
+static size_t
+yp_encoding_big5_char_width(const uint8_t *b, ptrdiff_t n) {
// These are the single byte characters.
- if (*uc < 0x80) {
- *width = 1;
- return *uc;
+ if (*b < 0x80) {
+ return 1;
}
// These are the double byte characters.
- if ((n > 1) && (uc[0] >= 0xA1 && uc[0] <= 0xFE) && (uc[1] >= 0x40 && uc[1] <= 0xFE)) {
- *width = 2;
- return (yp_big5_codepoint_t) (uc[0] << 8 | uc[1]);
+ if ((n > 1) && (b[0] >= 0xA1 && b[0] <= 0xFE) && (b[1] >= 0x40 && b[1] <= 0xFE)) {
+ return 2;
}
- *width = 0;
return 0;
}
static size_t
-yp_encoding_big5_char_width(const char *c, ptrdiff_t n) {
- size_t width;
- yp_big5_codepoint(c, n, &width);
-
- return width;
-}
-
-static size_t
-yp_encoding_big5_alpha_char(const char *c, ptrdiff_t n) {
- size_t width;
- yp_big5_codepoint_t codepoint = yp_big5_codepoint(c, n, &width);
-
- if (width == 1) {
- const char value = (const char) codepoint;
- return yp_encoding_ascii_alpha_char(&value, n);
+yp_encoding_big5_alpha_char(const uint8_t *b, ptrdiff_t n) {
+ if (yp_encoding_big5_char_width(b, n) == 1) {
+ return yp_encoding_ascii_alpha_char(b, n);
} else {
return 0;
}
}
static size_t
-yp_encoding_big5_alnum_char(const char *c, ptrdiff_t n) {
- size_t width;
- yp_big5_codepoint_t codepoint = yp_big5_codepoint(c, n, &width);
-
- if (width == 1) {
- const char value = (const char) codepoint;
- return yp_encoding_ascii_alnum_char(&value, n);
+yp_encoding_big5_alnum_char(const uint8_t *b, ptrdiff_t n) {
+ if (yp_encoding_big5_char_width(b, n) == 1) {
+ return yp_encoding_ascii_alnum_char(b, n);
} else {
return 0;
}
}
static bool
-yp_encoding_big5_isupper_char(const char *c, ptrdiff_t n) {
- size_t width;
- yp_big5_codepoint_t codepoint = yp_big5_codepoint(c, n, &width);
-
- if (width == 1) {
- const char value = (const char) codepoint;
- return yp_encoding_ascii_isupper_char(&value, n);
+yp_encoding_big5_isupper_char(const uint8_t *b, ptrdiff_t n) {
+ if (yp_encoding_big5_char_width(b, n) == 1) {
+ return yp_encoding_ascii_isupper_char(b, n);
} else {
return false;
}
}