--- np2/common/milstr.c 2003/10/29 21:35:58 1.2 +++ np2/common/milstr.c 2004/06/23 16:06:12 1.11 @@ -1,26 +1,137 @@ #include "compiler.h" -BOOL milstr_cmp(const char *str, const char *cmp) { +// ---- ANK / UCS2 / UCS4 + +#if defined(SUPPORT_ANK) +int milank_charsize(const OEMCHAR *str) { + + return((str[0] != '\0')?1:0); +} + +int milank_cmp(const OEMCHAR *str, const OEMCHAR *cmp) { int s; int c; - while(1) { - s = (BYTE)*str++; + do { + s = *str++; + if ((s >= 'a') && (s <= 'z')) { + s -= 0x20; + } + c = *cmp++; + if ((c >= 'a') && (c <= 'z')) { + c -= 0x20; + } + if (s != c) { + return((s > c)?1:-1); + } + } while(s); + return(0); +} + +int milank_memcmp(const OEMCHAR *str, const OEMCHAR *cmp) { + + int s; + int c; + + do { + c = *cmp++; + if (c == 0) { + return(0); + } + if ((c >= 'a') && (c <= 'z')) { + c -= 0x20; + } + s = *str++; + if ((s >= 'a') && (s <= 'z')) { + s -= 0x20; + } + } while(s == c); + return((s > c)?1:-1); +} + +void milank_ncpy(OEMCHAR *dst, const OEMCHAR *src, int maxlen) { + + int i; + + if (maxlen > 0) { + maxlen--; + for (i=0; i 0) { + maxlen--; + for (i=0; i c)?1:-1); } -BOOL milstr_memcmp(const char *str, const char *cmp) { +int milsjis_memcmp(const char *str, const char *cmp) { int s; int c; do { - c = (BYTE)*cmp++; + c = (UINT8)*cmp++; if ((((c ^ 0x20) - 0xa1) & 0xff) < 0x3c) { - s = (BYTE)*str++; + s = (UINT8)*str++; if (c != s) { break; } - c = (BYTE)*cmp++; - s = (BYTE)*str++; + c = (UINT8)*cmp++; + s = (UINT8)*str++; } else if (c) { if (((c - 'a') & 0xff) < 26) { c &= ~0x20; } - s = (BYTE)*str++; + s = (UINT8)*str++; if (((s - 'a') & 0xff) < 26) { s &= ~0x20; } @@ -66,79 +174,205 @@ BOOL milstr_memcmp(const char *str, cons return(0); } } while(s == c); - return(1); + return((s > c)?1:-1); } -BOOL milstr_extendcmp(const char *str, const char *cmp) { +int milsjis_kanji1st(const char *str, int pos) { - char c, s = '\0'; + int ret; - while(*cmp) { - while(*cmp) { - s = *cmp++; - if (!s) { - return(0); + ret = 0; + while((pos >= 0) && + ((((str[pos--] ^ 0x20) - 0xa1) & 0xff) < 0x3c)) { + ret ^= 1; + } + return(ret); +} + +int milsjis_kanji2nd(const char *str, int pos) { + + int ret; + + ret = 0; + while((pos > 0) && ((((str[--pos] ^ 0x20) - 0xa1) & 0xff) < 0x3c)) { + ret ^= 1; + } + return(ret); +} + +void milsjis_ncpy(char *dst, const char *src, int maxlen) { + + int i; + + if (maxlen > 0) { + maxlen--; + for (i=0; i= '0') && (s <= '9')) { + } + dst[i] = '\0'; + } +} + +void milsjis_ncat(char *dst, const char *src, int maxlen) { + + int i; + int j; + + if (maxlen > 0) { + maxlen--; + for (i=0; i= 'A') && (s <= 'Z')) { - break; + } + for (j=0; i 0) && (j > 0)) { + if (milsjis_kanji1st(dst, i-1)) { + i--; } } - while(1) { - c = *str++; - if (!c) { - return(1); + dst[i] = '\0'; + } +} + +char *milsjis_chr(const char *str, int c) { + + int s; + + if (str) { + do { + s = *str; + if (s == c) { + return((char *)str); } - if ((c >= '0') && (c <= '9')) { - break; + if ((((s ^ 0x20) - 0xa1) & 0xff) < 0x3c) { + str++; + s = *str; } - c &= 0xdf; - if ((c >= 'A') && (c <= 'Z')) { - break; + str++; + } while(s); + } + return(NULL); +} +#endif + + +// ---- EUC + +#if defined(SUPPORT_EUC) // あれ 半角カナ忘れてるぞ? +int mileuc_charsize(const char *str) { + + int pos; + + pos = (str[0] & 0x80)?1:0; + return((str[pos] != '\0')?(pos+1):0); +} + +int mileuc_cmp(const char *str, const char *cmp) { + + int s; + int c; + + do { + s = (UINT8)*str++; + if (s & 0x80) { + c = (UINT8)*cmp++; + if (s != c) { + goto mscp_err; + } + s = (UINT8)*str++; + c = (UINT8)*cmp++; + } + else { + if (((s - 'a') & 0xff) < 26) { + s -= 0x20; + } + c = (UINT8)*cmp++; + if (((c - 'a') & 0xff) < 26) { + c -= 0x20; } } - if (c != s) { - return(1); + if (s != c) { + goto mscp_err; } - } + } while(s); return(0); + +mscp_err: + return((s > c)?1:-1); +} + +int mileuc_memcmp(const char *str, const char *cmp) { + + int s; + int c; + + do { + c = (UINT8)*cmp++; + if (c & 0x80) { + s = (UINT8)*str++; + if (c != s) { + break; + } + c = (UINT8)*cmp++; + s = (UINT8)*str++; + } + else if (c) { + if (((c - 'a') & 0xff) < 26) { + c -= 0x20; + } + s = (BYTE)*str++; + if (((s - 'a') & 0xff) < 26) { + s -= 0x20; + } + } + else { + return(0); + } + } while(s == c); + return((s > c)?1:-1); } -int milstr_kanji1st(const char *str, int pos) { +int mileuc_kanji1st(const char *str, int pos) { int ret; ret = 0; - while((pos >= 0) && - ((((str[pos--] ^ 0x20) - 0xa1) & 0xff) < 0x3c)) { + while((pos >= 0) && (str[pos--] & 0x80)) { ret ^= 1; } return(ret); } -int milstr_kanji2nd(const char *str, int pos) { +int mileuc_kanji2nd(const char *str, int pos) { - int ret = 0; + int ret; - while((pos) && ((((str[--pos] ^ 0x20) - 0xa1) & 0xff) < 0x3c)) { + ret = 0; + while((pos > 0) && (str[--pos] & 0x80)) { ret ^= 1; } return(ret); } -void milstr_ncpy(char *dst, const char *src, int maxlen) { +void mileuc_ncpy(char *dst, const char *src, int maxlen) { int i; - if (maxlen--) { + if (maxlen > 0) { + maxlen--; for (i=0; i 0) { + maxlen--; for (i=0; i 0) && (j > 0)) { + if (mileuc_kanji1st(dst, i-1)) { i--; } } @@ -167,15 +404,218 @@ void milstr_ncat(char *dst, const char * } } -int milstr_getarg(char *str, char *arg[], int maxarg) { +char *mileuc_chr(const char *str, int c) { + + int s; + + if (str) { + do { + s = *str; + if (s == c) { + return((char *)str); + } + if (s & 0x80) { + str++; + s = *str; + } + str++; + } while(s); + } + return(NULL); +} +#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 ((str[0] & 0xe0) == 0xc0) { + if ((str[1] & 0xc0) == 0x80) { + return(2); + } + } + else if ((str[0] & 0xf0) == 0xe0) { + if (((str[1] & 0xc0) == 0x80) || + ((str[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 0) { + maxlen--; + for (i=0; i c)?1:-1); +} + +OEMCHAR *milstr_nextword(const OEMCHAR *str) { + + if (str) { + while((*str > '\0') && (*str <= ' ')) { + str++; + } + } + return((OEMCHAR *)str); +} + +int milstr_getarg(OEMCHAR *str, OEMCHAR *arg[], int maxarg) { int ret = 0; - char *p; + OEMCHAR *p; BOOL quot; while(maxarg--) { quot = FALSE; - while((*str) && (((BYTE)*str) <= 0x20)) { + while((*str > '\0') && (*str <= ' ')) { str++; } if (*str == '\0') { @@ -184,10 +624,10 @@ int milstr_getarg(char *str, char *arg[] arg[ret++] = str; p = str; while(*str) { - if (*str == 0x22) { + if (*str == '\"') { quot = !quot; } - else if ((((BYTE)*str) > 0x20) || (quot)) { + else if ((quot) || (*str < '\0') || (*str > ' ')) { *p++ = *str; } else { @@ -201,7 +641,7 @@ int milstr_getarg(char *str, char *arg[] return(ret); } -long milstr_solveHEX(const char *str) { +long milstr_solveHEX(const OEMCHAR *str) { long ret; int i; @@ -228,7 +668,7 @@ long milstr_solveHEX(const char *str) { return(ret); } -long milstr_solveINT(const char *str) { +long milstr_solveINT(const OEMCHAR *str) { long ret; int c; @@ -257,3 +697,15 @@ long milstr_solveINT(const char *str) { return(ret * s); } +OEMCHAR *milstr_list(const OEMCHAR *lststr, UINT pos) { + + if (lststr) { + while(pos) { + pos--; + while(*lststr++ != '\0') { + } + } + } + return((OEMCHAR *)lststr); +} +