_INLINE static int do_ins_cmp_backref(VMState* vms) { int index = *(vms->snap->codes + 1); TRE_DEBUG_PRINT("%12s\n", "CMP_BACKREF"); if (vms->snap->text_end) return 0; if (index >= vms->group_num) return 0; if (vms->match_results[index].head && vms->match_results[index].tail) { uint32_t *p = vms->match_results[index].head; uint32_t *tail = vms->match_results[index].tail; uint32_t *p2 = vms->snap->str_pos; while (p < tail) { if (!char_cmp(*p, *p2, vms->flag)) return 0; p++; p2++; } // 匹配完成后将被+1,故先减去 vms->snap->str_pos = p2-1; return 2; } return 0; }
/** * Partitions the given array for quicksort. */ static int partition(struct sort_tree_transition** t, int m, int n, struct sort_infos* inf) { unichar pivot; struct sort_tree_transition* tmp; int i = m - 1; int j = n + 1; /* Final index of the pivot */ pivot = t[(m + n) / 2]->c; for (;;) { do j--; while ((j > (m - 1)) && (char_cmp(pivot, t[j]->c, inf) < 0)); do i++; while ((i < n + 1) && (char_cmp(t[i]->c, pivot, inf) < 0)); if (i < j) { tmp = t[i]; t[i] = t[j]; t[j] = tmp; } else return j; } }
_INLINE static int do_ins_cmp(VMState* vms) { VMSnap* snap = vms->snap; uint32_t char_code = *(snap->codes + 1); #ifdef TRE_DEBUG printf_u8("%12s ", "CMP"); putcode(char_code); printf(" "); putcode(snap->chrcode); putchar('\n'); #endif if (snap->text_end) return 0; if (char_cmp(char_code, snap->chrcode, vms->flag)) return 2; return 0; }
_INLINE static int do_ins_cmp_multi(VMState* vms, bool is_ncmp) { int i; uint32_t _type, _code; bool match = false; VMSnap* snap = vms->snap; uint32_t* data = snap->codes + 1; int num = *data++; TRE_DEBUG_PRINT("%12s\n", "CMP_MULTI"); if (snap->text_end) return 0; for (i = 0; i < num; i++) { _type = *(data + i * 3); _code = *(data + i * 3 + 1); if (_type == TK_CHAR) { if (char_cmp(_code, snap->chrcode, vms->flag)) { match = true; break; } } else if (_type == TK_CHAR_SPE) { if (char_cmp_spe(_code, snap->chrcode, vms->flag)) { match = true; break; } } else if (_type == '-') { if (char_cmp_range(_code, *((int*)data + i * 3 + 2), snap->chrcode, vms->flag)) { match = true; break; } } } if (is_ncmp) { return match ? 0 : (num * 3 + 2); } else { return match ? (num * 3 + 2) : 0; } }
int func_def_p_cmp(func_t *f, func_t *g) { if(f==NULL || g==NULL || func_ptype(f)!=FUNC_P_DEF || func_ptype(g)!=FUNC_P_DEF || f->p.def==NULL || g->p.def==NULL){ FUNC_ERROR_ARG2("func_def_cmp",f,g); } return char_cmp(f->p.def->name,g->p.def->name); }
/** * Does a unicode char to char comparison, according to the char_cmp function order. */ int strcmp2(unichar* a, unichar* b, struct sort_infos* inf) { int i = 0; while (a[i] && a[i] == b[i]) i++; return char_cmp(a[i], b[i], inf); }