comparison src/eval.c @ 388:f92bb1845823 v7.0101

updated for version 7.0101
author vimboss
date Sun, 03 Jul 2005 21:39:27 +0000
parents a509e3ba61f6
children 06234af3a8b7
comparison
equal deleted inserted replaced
387:a509e3ba61f6 388:f92bb1845823
373 static void listitem_remove __ARGS((list_T *l, listitem_T *item)); 373 static void listitem_remove __ARGS((list_T *l, listitem_T *item));
374 static long list_len __ARGS((list_T *l)); 374 static long list_len __ARGS((list_T *l));
375 static int list_equal __ARGS((list_T *l1, list_T *l2, int ic)); 375 static int list_equal __ARGS((list_T *l1, list_T *l2, int ic));
376 static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic)); 376 static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic));
377 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic)); 377 static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic));
378 static int string_isa_number __ARGS((char_u *s));
379 static listitem_T *list_find __ARGS((list_T *l, long n)); 378 static listitem_T *list_find __ARGS((list_T *l, long n));
380 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item)); 379 static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
381 static void list_append __ARGS((list_T *l, listitem_T *item)); 380 static void list_append __ARGS((list_T *l, listitem_T *item));
382 static int list_append_tv __ARGS((list_T *l, typval_T *tv)); 381 static int list_append_tv __ARGS((list_T *l, typval_T *tv));
383 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item)); 382 static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
5177 return TRUE; 5176 return TRUE;
5178 } 5177 }
5179 5178
5180 /* 5179 /*
5181 * Return TRUE if "tv1" and "tv2" have the same value. 5180 * Return TRUE if "tv1" and "tv2" have the same value.
5182 * Compares the items just like "==" would compare them. 5181 * Compares the items just like "==" would compare them, but strings and
5182 * numbers are different.
5183 */ 5183 */
5184 static int 5184 static int
5185 tv_equal(tv1, tv2, ic) 5185 tv_equal(tv1, tv2, ic)
5186 typval_T *tv1; 5186 typval_T *tv1;
5187 typval_T *tv2; 5187 typval_T *tv2;
5188 int ic; /* ignore case */ 5188 int ic; /* ignore case */
5189 { 5189 {
5190 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; 5190 char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
5191 char_u *s1, *s2; 5191 char_u *s1, *s2;
5192 5192
5193 if (tv1->v_type == VAR_LIST || tv2->v_type == VAR_LIST) 5193 if (tv1->v_type != tv2->v_type)
5194 { 5194 return FALSE;
5195 /* recursive! */ 5195
5196 if (tv1->v_type != tv2->v_type 5196 switch (tv1->v_type)
5197 || !list_equal(tv1->vval.v_list, tv2->vval.v_list, ic)) 5197 {
5198 return FALSE; 5198 case VAR_LIST:
5199 } 5199 /* recursive! */
5200 else if (tv1->v_type == VAR_DICT || tv2->v_type == VAR_DICT) 5200 return list_equal(tv1->vval.v_list, tv2->vval.v_list, ic);
5201 { 5201
5202 /* recursive! */ 5202 case VAR_DICT:
5203 if (tv1->v_type != tv2->v_type 5203 /* recursive! */
5204 || !dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic)) 5204 return dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic);
5205 return FALSE; 5205
5206 } 5206 case VAR_FUNC:
5207 else if (tv1->v_type == VAR_FUNC || tv2->v_type == VAR_FUNC) 5207 return (tv1->vval.v_string != NULL
5208 { 5208 && tv2->vval.v_string != NULL
5209 if (tv1->v_type != tv2->v_type 5209 && STRCMP(tv1->vval.v_string, tv2->vval.v_string) == 0);
5210 || tv1->vval.v_string == NULL 5210
5211 || tv2->vval.v_string == NULL 5211 case VAR_NUMBER:
5212 || STRCMP(tv1->vval.v_string, tv2->vval.v_string) != 0) 5212 return tv1->vval.v_number == tv2->vval.v_number;
5213 return FALSE; 5213
5214 } 5214 case VAR_STRING:
5215 else if (tv1->v_type == VAR_NUMBER || tv2->v_type == VAR_NUMBER) 5215 s1 = get_tv_string_buf(tv1, buf1);
5216 { 5216 s2 = get_tv_string_buf(tv2, buf2);
5217 /* "4" is equal to 4. But don't consider 'a' and zero to be equal. 5217 return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0);
5218 * Don't consider "4x" to be equal to 4. */ 5218 }
5219 if ((tv1->v_type == VAR_STRING 5219
5220 && !string_isa_number(tv1->vval.v_string)) 5220 EMSG2(_(e_intern2), "tv_equal()");
5221 || (tv2->v_type == VAR_STRING
5222 && !string_isa_number(tv2->vval.v_string)))
5223 return FALSE;
5224 if (get_tv_number(tv1) != get_tv_number(tv2))
5225 return FALSE;
5226 }
5227 else
5228 {
5229 s1 = get_tv_string_buf(tv1, buf1);
5230 s2 = get_tv_string_buf(tv2, buf2);
5231 if ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) != 0)
5232 return FALSE;
5233 }
5234 return TRUE; 5221 return TRUE;
5235 }
5236
5237 /*
5238 * Return TRUE if "tv" is a number without other non-white characters.
5239 */
5240 static int
5241 string_isa_number(s)
5242 char_u *s;
5243 {
5244 int len;
5245
5246 vim_str2nr(s, NULL, &len, TRUE, TRUE, NULL, NULL);
5247 return len > 0 && *skipwhite(s + len) == NUL;
5248 } 5222 }
5249 5223
5250 /* 5224 /*
5251 * Locate item with index "n" in list "l" and return it. 5225 * Locate item with index "n" in list "l" and return it.
5252 * A negative index is counted from the end; -1 is the last item. 5226 * A negative index is counted from the end; -1 is the last item.