static int get_case_fold_codes_by_str(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]) { int len; OnigCodePoint code, code_lo, code_up; code = mbc_to_code(p, end); if (ONIGENC_IS_ASCII_CODE(code)) return onigenc_ascii_get_case_fold_codes_by_str(flag, p, end, items); len = mbc_enc_len(p); code_lo = get_lower_case(code); code_up = get_upper_case(code); if (code != code_lo) { items[0].byte_len = len; items[0].code_len = 1; items[0].code[0] = code_lo; return 1; } else if (code != code_up) { items[0].byte_len = len; items[0].code_len = 1; items[0].code[0] = code_up; return 1; } return 0; }
static OnigCodePoint mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc) { int c, len; OnigCodePoint n; len = mbc_enc_len(p, end, enc); c = *p++; if (len > 1) { len--; n = c & ((1 << (6 - len)) - 1); while (len--) { c = *p++; n = (n << 6) | (c & ((1 << 6) - 1)); } return n; } else { #ifdef USE_INVALID_CODE_SCHEME if (c > 0xfd) { return ((c == 0xfe) ? INVALID_CODE_FE : INVALID_CODE_FF); } #endif return (OnigCodePoint )c; } }
static int code_to_mbc(OnigCodePoint code, UChar *buf) { UChar *p = buf; if ((code & 0xff00) != 0) *p++ = (UChar )(((code >> 8) & 0xff)); *p++ = (UChar )(code & 0xff); #if 0 if (mbc_enc_len(buf) != (p - buf)) return REGERR_INVALID_CODE_POINT_VALUE; #endif return (int )(p - buf); }
static OnigCodePoint mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc) { int c, i, len; OnigCodePoint n; len = mbc_enc_len(p, end, enc); n = (OnigCodePoint )*p++; if (len == 1) return n; for (i = 1; i < len; i++) { if (p >= end) break; c = *p++; n <<= 8; n += c; } return n; }
static UChar* left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc) { const UChar *p; int len; if (s <= start) return (UChar* )s; p = s; if (SJIS_ISMB_TRAIL(*p)) { while (p > start) { if (! SJIS_ISMB_FIRST(*--p)) { p++; break; } } } len = mbc_enc_len(p, end, enc); if (p + len > s) return (UChar* )p; p += len; return (UChar* )(p + ((s - p) & ~1)); }
static int mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end, UChar* lower, OnigEncoding enc) { int len; const UChar* p = *pp; if (ONIGENC_IS_MBC_ASCII(p)) { *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p); (*pp)++; return 1; } else { int i; len = mbc_enc_len(p, end, enc); for (i = 0; i < len; i++) { *lower++ = *p++; } (*pp) += len; return len; /* return byte length of converted char to lower */ } }