comparison src/eval.c @ 5676:9ac2fc63501d v7.4.184

updated for version 7.4.184 Problem: match() does not work properly with a {count} argument. Solution: Compute the length once and update it. Quit the loop when at the end. (Hirohito Higashi)
author Bram Moolenaar <bram@vim.org>
date Sat, 22 Feb 2014 22:18:47 +0100
parents 5d03c3747121
children 0a9990bbd94a
comparison
equal deleted inserted replaced
5675:7ea91c82839f 5676:9ac2fc63501d
8012 #ifdef FEAT_FLOAT 8012 #ifdef FEAT_FLOAT
8013 {"log", 1, 1, f_log}, 8013 {"log", 1, 1, f_log},
8014 {"log10", 1, 1, f_log10}, 8014 {"log10", 1, 1, f_log10},
8015 #endif 8015 #endif
8016 #ifdef FEAT_LUA 8016 #ifdef FEAT_LUA
8017 {"luaeval", 1, 2, f_luaeval}, 8017 {"luaeval", 1, 2, f_luaeval},
8018 #endif 8018 #endif
8019 {"map", 2, 2, f_map}, 8019 {"map", 2, 2, f_map},
8020 {"maparg", 1, 4, f_maparg}, 8020 {"maparg", 1, 4, f_maparg},
8021 {"mapcheck", 1, 3, f_mapcheck}, 8021 {"mapcheck", 1, 3, f_mapcheck},
8022 {"match", 2, 4, f_match}, 8022 {"match", 2, 4, f_match},
13903 typval_T *argvars; 13903 typval_T *argvars;
13904 typval_T *rettv; 13904 typval_T *rettv;
13905 int type; 13905 int type;
13906 { 13906 {
13907 char_u *str = NULL; 13907 char_u *str = NULL;
13908 long len = 0;
13908 char_u *expr = NULL; 13909 char_u *expr = NULL;
13909 char_u *pat; 13910 char_u *pat;
13910 regmatch_T regmatch; 13911 regmatch_T regmatch;
13911 char_u patbuf[NUMBUFLEN]; 13912 char_u patbuf[NUMBUFLEN];
13912 char_u strbuf[NUMBUFLEN]; 13913 char_u strbuf[NUMBUFLEN];
13942 if ((l = argvars[0].vval.v_list) == NULL) 13943 if ((l = argvars[0].vval.v_list) == NULL)
13943 goto theend; 13944 goto theend;
13944 li = l->lv_first; 13945 li = l->lv_first;
13945 } 13946 }
13946 else 13947 else
13948 {
13947 expr = str = get_tv_string(&argvars[0]); 13949 expr = str = get_tv_string(&argvars[0]);
13950 len = (long)STRLEN(str);
13951 }
13948 13952
13949 pat = get_tv_string_buf_chk(&argvars[1], patbuf); 13953 pat = get_tv_string_buf_chk(&argvars[1], patbuf);
13950 if (pat == NULL) 13954 if (pat == NULL)
13951 goto theend; 13955 goto theend;
13952 13956
13966 } 13970 }
13967 else 13971 else
13968 { 13972 {
13969 if (start < 0) 13973 if (start < 0)
13970 start = 0; 13974 start = 0;
13971 if (start > (long)STRLEN(str)) 13975 if (start > len)
13972 goto theend; 13976 goto theend;
13973 /* When "count" argument is there ignore matches before "start", 13977 /* When "count" argument is there ignore matches before "start",
13974 * otherwise skip part of the string. Differs when pattern is "^" 13978 * otherwise skip part of the string. Differs when pattern is "^"
13975 * or "\<". */ 13979 * or "\<". */
13976 if (argvars[3].v_type != VAR_UNKNOWN) 13980 if (argvars[3].v_type != VAR_UNKNOWN)
13977 startcol = start; 13981 startcol = start;
13978 else 13982 else
13983 {
13979 str += start; 13984 str += start;
13985 len -= start;
13986 }
13980 } 13987 }
13981 13988
13982 if (argvars[3].v_type != VAR_UNKNOWN) 13989 if (argvars[3].v_type != VAR_UNKNOWN)
13983 nth = get_tv_number_chk(&argvars[3], &error); 13990 nth = get_tv_number_chk(&argvars[3], &error);
13984 if (error) 13991 if (error)
14024 startcol = (colnr_T)(regmatch.startp[0] 14031 startcol = (colnr_T)(regmatch.startp[0]
14025 + (*mb_ptr2len)(regmatch.startp[0]) - str); 14032 + (*mb_ptr2len)(regmatch.startp[0]) - str);
14026 #else 14033 #else
14027 startcol = (colnr_T)(regmatch.startp[0] + 1 - str); 14034 startcol = (colnr_T)(regmatch.startp[0] + 1 - str);
14028 #endif 14035 #endif
14036 if (startcol > (colnr_T)len
14037 || str + startcol <= regmatch.startp[0])
14038 {
14039 match = FALSE;
14040 break;
14041 }
14029 } 14042 }
14030 } 14043 }
14031 14044
14032 if (match) 14045 if (match)
14033 { 14046 {