Beispiel #1
0
/* returns 1 if m1 is better than m2, -1 if m1 is worse than m2, 0 if equally good*/
gint gtk_mate_matcher_compare_match (const char* scope_string, OnigMatch* m1, OnigMatch* m2) {
	GeeArrayList* space_ixs;
	gint max_cap1;
	gint max_cap2;
	gint cap1_ix;
	gint cap1_el_ix;
	gint len1;
	gint cap2_ix;
	gint cap2_el_ix;
	gint len2;
	gint _tmp4_;
	g_return_val_if_fail (scope_string != NULL, 0);
	g_return_val_if_fail (m1 != NULL, 0);
	g_return_val_if_fail (m2 != NULL, 0);
	space_ixs = string_helper_occurrences (scope_string, " ");
	max_cap1 = onig_match_num_captures (m1);
	max_cap2 = onig_match_num_captures (m2);
	cap1_ix = 0;
	cap1_el_ix = 0;
	len1 = 0;
	cap2_ix = 0;
	cap2_el_ix = 0;
	len2 = 0;
	{
		gint i;
		i = 0;
		for (; i < MIN (max_cap1, max_cap2); i++) {
			/* first try element depth:*/
			cap1_ix = onig_match_begin (m1, (max_cap1 - 1) - i);
			cap2_ix = onig_match_begin (m2, (max_cap2 - 1) - i);
			cap1_el_ix = gtk_mate_matcher_sorted_ix (space_ixs, cap1_ix);
			cap2_el_ix = gtk_mate_matcher_sorted_ix (space_ixs, cap2_ix);
			if (cap1_el_ix > cap2_el_ix) {
				gint _tmp0_;
				return (_tmp0_ = 1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp0_);
			} else {
				if (cap1_el_ix < cap2_el_ix) {
					gint _tmp1_;
					return (_tmp1_ = -1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp1_);
				}
			}
			/* next try length of match*/
			len1 = onig_match_end (m1, (max_cap1 - 1) - i) - cap1_ix;
			len2 = onig_match_end (m2, (max_cap2 - 1) - i) - cap2_ix;
			if (len1 > len2) {
				gint _tmp2_;
				return (_tmp2_ = 1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp2_);
			} else {
				if (len1 < len2) {
					gint _tmp3_;
					return (_tmp3_ = -1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp3_);
				}
			}
		}
	}
	return (_tmp4_ = 0, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp4_);
}
Beispiel #2
0
gint gtk_mate_matcher_compare_match (const char* scope_string, OnigMatch* m1, OnigMatch* m2) {
	GeeArrayList* space_ixs;
	gint max_cap1;
	gint max_cap2;
	gint cap1_ix;
	gint cap1_el_ix;
	gint len1;
	gint cap2_ix;
	gint cap2_el_ix;
	gint len2;
	gint _tmp4;
	g_return_val_if_fail (scope_string != NULL, 0);
	g_return_val_if_fail (m1 != NULL, 0);
	g_return_val_if_fail (m2 != NULL, 0);
	space_ixs = string_helper_occurrences (scope_string, " ");
	/* foreach (var ix in space_ixs) {
	stdout.printf("space at %d\n", ix);
	 }*/
	max_cap1 = onig_match_num_captures (m1);
	max_cap2 = onig_match_num_captures (m2);
	/*stdout.printf("m1 has %d matches\n", m1.num_captures());
	stdout.printf("m2 has %d matches\n", m2.num_captures());*/
	cap1_ix = 0;
	cap1_el_ix = 0;
	len1 = 0;
	cap2_ix = 0;
	cap2_el_ix = 0;
	len2 = 0;
	{
		gint i;
		i = 0;
		for (; i < MIN (max_cap1, max_cap2); i++) {
			/* first try element depth:*/
			cap1_ix = onig_match_begin (m1, (max_cap1 - 1) - i);
			cap2_ix = onig_match_begin (m2, (max_cap2 - 1) - i);
			/*stdout.printf("m1 capture %d at %d\n", max_cap1-1-i, cap1_ix);
			stdout.printf("m2 capture %d at %d\n", max_cap2-1-i, cap2_ix);*/
			cap1_el_ix = gtk_mate_matcher_sorted_ix (space_ixs, cap1_ix);
			cap2_el_ix = gtk_mate_matcher_sorted_ix (space_ixs, cap2_ix);
			/*stdout.printf("m1 capture %d at el %d\n", max_cap1-1-i, cap1_el_ix);
			stdout.printf("m2 capture %d at el %d\n", max_cap2-1-i, cap2_el_ix);*/
			if (cap1_el_ix > cap2_el_ix) {
				gint _tmp0;
				return (_tmp0 = 1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp0);
			} else {
				if (cap1_el_ix < cap2_el_ix) {
					gint _tmp1;
					return (_tmp1 = -1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp1);
				}
			}
			/* next try length of match*/
			len1 = onig_match_end (m1, (max_cap1 - 1) - i) - cap1_ix;
			len2 = onig_match_end (m2, (max_cap2 - 1) - i) - cap2_ix;
			if (len1 > len2) {
				gint _tmp2;
				return (_tmp2 = 1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp2);
			} else {
				if (len1 < len2) {
					gint _tmp3;
					return (_tmp3 = -1, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp3);
				}
			}
		}
	}
	return (_tmp4 = 0, (space_ixs == NULL) ? NULL : (space_ixs = (g_object_unref (space_ixs), NULL)), _tmp4);
}