diff options
author | Bram Moolenaar <Bram@vim.org> | 2005-07-03 21:39:27 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2005-07-03 21:39:27 +0000 |
commit | 7d1f5dbc0a254d7524b3f985f2440bf89e037355 (patch) | |
tree | 7e4c83253b68e454fca710b215f928c1e012ba74 /src/eval.c | |
parent | 51ac12f68322b411ae5b038834a649a0e9ccb462 (diff) | |
download | vim-git-7d1f5dbc0a254d7524b3f985f2440bf89e037355.tar.gz |
updated for version 7.0101v7.0101
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 82 |
1 files changed, 28 insertions, 54 deletions
diff --git a/src/eval.c b/src/eval.c index af2c73d7f..c1762265f 100644 --- a/src/eval.c +++ b/src/eval.c @@ -375,7 +375,6 @@ static long list_len __ARGS((list_T *l)); static int list_equal __ARGS((list_T *l1, list_T *l2, int ic)); static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic)); static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic)); -static int string_isa_number __ARGS((char_u *s)); static listitem_T *list_find __ARGS((list_T *l, long n)); static long list_idx_of_item __ARGS((list_T *l, listitem_T *item)); static void list_append __ARGS((list_T *l, listitem_T *item)); @@ -5179,7 +5178,8 @@ dict_equal(d1, d2, ic) /* * Return TRUE if "tv1" and "tv2" have the same value. - * Compares the items just like "==" would compare them. + * Compares the items just like "==" would compare them, but strings and + * numbers are different. */ static int tv_equal(tv1, tv2, ic) @@ -5190,61 +5190,35 @@ tv_equal(tv1, tv2, ic) char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; char_u *s1, *s2; - if (tv1->v_type == VAR_LIST || tv2->v_type == VAR_LIST) - { - /* recursive! */ - if (tv1->v_type != tv2->v_type - || !list_equal(tv1->vval.v_list, tv2->vval.v_list, ic)) - return FALSE; - } - else if (tv1->v_type == VAR_DICT || tv2->v_type == VAR_DICT) - { - /* recursive! */ - if (tv1->v_type != tv2->v_type - || !dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic)) - return FALSE; - } - else if (tv1->v_type == VAR_FUNC || tv2->v_type == VAR_FUNC) - { - if (tv1->v_type != tv2->v_type - || tv1->vval.v_string == NULL - || tv2->vval.v_string == NULL - || STRCMP(tv1->vval.v_string, tv2->vval.v_string) != 0) - return FALSE; - } - else if (tv1->v_type == VAR_NUMBER || tv2->v_type == VAR_NUMBER) - { - /* "4" is equal to 4. But don't consider 'a' and zero to be equal. - * Don't consider "4x" to be equal to 4. */ - if ((tv1->v_type == VAR_STRING - && !string_isa_number(tv1->vval.v_string)) - || (tv2->v_type == VAR_STRING - && !string_isa_number(tv2->vval.v_string))) - return FALSE; - if (get_tv_number(tv1) != get_tv_number(tv2)) - return FALSE; - } - else + if (tv1->v_type != tv2->v_type) + return FALSE; + + switch (tv1->v_type) { - s1 = get_tv_string_buf(tv1, buf1); - s2 = get_tv_string_buf(tv2, buf2); - if ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) != 0) - return FALSE; - } - return TRUE; -} + case VAR_LIST: + /* recursive! */ + return list_equal(tv1->vval.v_list, tv2->vval.v_list, ic); -/* - * Return TRUE if "tv" is a number without other non-white characters. - */ - static int -string_isa_number(s) - char_u *s; -{ - int len; + case VAR_DICT: + /* recursive! */ + return dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic); + + case VAR_FUNC: + return (tv1->vval.v_string != NULL + && tv2->vval.v_string != NULL + && STRCMP(tv1->vval.v_string, tv2->vval.v_string) == 0); + + case VAR_NUMBER: + return tv1->vval.v_number == tv2->vval.v_number; - vim_str2nr(s, NULL, &len, TRUE, TRUE, NULL, NULL); - return len > 0 && *skipwhite(s + len) == NUL; + case VAR_STRING: + s1 = get_tv_string_buf(tv1, buf1); + s2 = get_tv_string_buf(tv2, buf2); + return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0); + } + + EMSG2(_(e_intern2), "tv_equal()"); + return TRUE; } /* |