|
|
| version 1.6, 2004/02/19 11:32:11 | version 1.8, 2004/06/20 01:03:04 |
|---|---|
| Line 5 | Line 5 |
| // ---- ANK | // ---- ANK |
| #if defined(SUPPORT_ANK) | #if defined(SUPPORT_ANK) |
| int milank_charsize(const char *str) { | |
| return((str[0] != '\0')?1:0); | |
| } | |
| int milank_cmp(const char *str, const char *cmp) { | int milank_cmp(const char *str, const char *cmp) { |
| int s; | int s; |
| Line 100 char *milank_chr(const char *str, int c) | Line 105 char *milank_chr(const char *str, int c) |
| // ---- Shift-JIS | // ---- Shift-JIS |
| #if defined(SUPPORT_SJIS) | #if defined(SUPPORT_SJIS) |
| int milsjis_charsize(const char *str) { | |
| int pos; | |
| pos = ((((str[0] ^ 0x20) - 0xa1) & 0xff) < 0x3c)?1:0; | |
| return((str[pos] != '\0')?(pos+1):0); | |
| } | |
| int milsjis_cmp(const char *str, const char *cmp) { | int milsjis_cmp(const char *str, const char *cmp) { |
| int s; | int s; |
| Line 253 char *milsjis_chr(const char *str, int c | Line 266 char *milsjis_chr(const char *str, int c |
| // ---- EUC | // ---- EUC |
| #if defined(SUPPORT_EUC) | #if defined(SUPPORT_EUC) // あれ 半角カナ忘れてるぞ? |
| int mileuc_charsize(const char *str) { | |
| int pos; | |
| pos = (((str[0] - 0xa1) & 0xff) < 0x5d)?1:0; | |
| return((str[pos] != '\0')?(pos+1):0); | |
| } | |
| int mileuc_cmp(const char *str, const char *cmp) { | int mileuc_cmp(const char *str, const char *cmp) { |
| int s; | int s; |
| Line 405 char *mileuc_chr(const char *str, int c) | Line 426 char *mileuc_chr(const char *str, int c) |
| #endif | #endif |
| // ---- UTF8 | |
| #if defined(SUPPORT_UTF8) | |
| int milutf8_charsize(const char *str) { | |
| if (str[0] == '\0') { | |
| return(0); | |
| } | |
| else if (!(str[0] & 0x80)) { | |
| return(1); | |
| } | |
| else if ((src[0] & 0xe0) == 0xc0) { | |
| if ((src[1] & 0xc0) == 0x80) { | |
| return(2); | |
| } | |
| } | |
| else if ((src[0] & 0xf0) == 0xe0) { | |
| if (((src[1] & 0xc0) == 0x80) || | |
| ((src[2] & 0xc0) == 0x80)) { | |
| return(3); | |
| } | |
| } | |
| return(0); | |
| } | |
| int milutf8_cmp(const char *str, const char *cmp) { | |
| int s; | |
| int c; | |
| do { | |
| s = (UINT8)*str++; | |
| if (((s - 'a') & 0xff) < 26) { | |
| s -= 0x20; | |
| } | |
| c = (BYTE)*cmp++; | |
| if (((c - 'a') & 0xff) < 26) { | |
| c -= 0x20; | |
| } | |
| if (s != c) { | |
| return((s > c)?1:-1); | |
| } | |
| } while(s); | |
| return(0); | |
| } | |
| int milutf8_memcmp(const char *str, const char *cmp) { | |
| int s; | |
| int c; | |
| do { | |
| c = (UINT8)*cmp++; | |
| if (c == 0) { | |
| return(0); | |
| } | |
| if (((c - 'a') & 0xff) < 26) { | |
| c -= 0x20; | |
| } | |
| s = (UINT8)*str++; | |
| if (((s - 'a') & 0xff) < 26) { | |
| s -= 0x20; | |
| } | |
| } while(s == c); | |
| return((s > c)?1:-1); | |
| } | |
| int milutf8_kanji1st(const char *str, int pos) { | |
| return(((str[pos] & 0xc0) >= 0xc0)?1:0); | |
| } | |
| int milutf8_kanji2nd(const char *str, int pos) { | |
| return(((str[pos] & 0xc0) == 0x80)?1:0); | |
| } | |
| void milutf8_ncpy(char *dst, const char *src, int maxlen) { | |
| int i; | |
| if (maxlen > 0) { | |
| maxlen--; | |
| for (i=0; i<maxlen && src[i]; i++) { | |
| dst[i] = src[i]; | |
| } | |
| while((i) && ((dst[i] & 0xc0) == 0x80)) { | |
| i--; | |
| } | |
| dst[i] = '\0'; | |
| } | |
| } | |
| void milutf8_ncat(char *dst, const char *src, int maxlen) { | |
| int i; | |
| int j; | |
| if (maxlen > 0) { | |
| maxlen--; | |
| for (i=0; i<maxlen; i++) { | |
| if (!dst[i]) { | |
| break; | |
| } | |
| } | |
| for (j=0; i<maxlen && src[j]; i++, j++) { | |
| dst[i] = src[j]; | |
| } | |
| while((i) && ((dst[i] & 0xc0) == 0x80)) { | |
| i--; | |
| } | |
| dst[i] = '\0'; | |
| } | |
| } | |
| char *milutf8_chr(const char *str, int c) { | |
| int s; | |
| if (str) { | |
| do { | |
| s = *str; | |
| if (s == c) { | |
| return((char *)str); | |
| } | |
| str++; | |
| } while(s); | |
| } | |
| return(NULL); | |
| } | |
| #endif | |
| // ---- other | // ---- other |
| int milstr_extendcmp(const char *str, const char *cmp) { | int milstr_extendcmp(const char *str, const char *cmp) { |