Mercurial > vim
comparison src/regexp.c @ 5794:a63d0cd691dc v7.4.241
updated for version 7.4.241
Problem: The string returned by submatch() does not distinguish between a
NL from a line break and a NL that stands for a NUL character.
Solution: Add a second argument to return a list. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 02 Apr 2014 19:00:58 +0200 |
parents | 50dbef5e774a |
children | 4901a36479f2 |
comparison
equal
deleted
inserted
replaced
5793:3b08d14e08a3 | 5794:a63d0cd691dc |
---|---|
7895 retval = vim_strnsave(s, (int)(submatch_match->endp[no] - s)); | 7895 retval = vim_strnsave(s, (int)(submatch_match->endp[no] - s)); |
7896 } | 7896 } |
7897 | 7897 |
7898 return retval; | 7898 return retval; |
7899 } | 7899 } |
7900 | |
7901 /* | |
7902 * Used for the submatch() function with the optional non-zero argument: get | |
7903 * the list of strings from the n'th submatch in allocated memory with NULs | |
7904 * represented in NLs. | |
7905 * Returns a list of allocated strings. Returns NULL when not in a ":s" | |
7906 * command, for a non-existing submatch and for any error. | |
7907 */ | |
7908 list_T * | |
7909 reg_submatch_list(no) | |
7910 int no; | |
7911 { | |
7912 char_u *s; | |
7913 linenr_T slnum; | |
7914 linenr_T elnum; | |
7915 colnr_T scol; | |
7916 colnr_T ecol; | |
7917 int i; | |
7918 list_T *list; | |
7919 int error = FALSE; | |
7920 | |
7921 if (!can_f_submatch || no < 0) | |
7922 return NULL; | |
7923 | |
7924 if (submatch_match == NULL) | |
7925 { | |
7926 slnum = submatch_mmatch->startpos[no].lnum; | |
7927 elnum = submatch_mmatch->endpos[no].lnum; | |
7928 if (slnum < 0 || elnum < 0) | |
7929 return NULL; | |
7930 | |
7931 scol = submatch_mmatch->startpos[no].col; | |
7932 ecol = submatch_mmatch->endpos[no].col; | |
7933 | |
7934 list = list_alloc(); | |
7935 if (list == NULL) | |
7936 return NULL; | |
7937 | |
7938 s = reg_getline_submatch(slnum) + scol; | |
7939 if (slnum == elnum) | |
7940 { | |
7941 if (list_append_string(list, s, ecol - scol) == FAIL) | |
7942 error = TRUE; | |
7943 } | |
7944 else | |
7945 { | |
7946 if (list_append_string(list, s, -1) == FAIL) | |
7947 error = TRUE; | |
7948 for (i = 1; i < elnum - slnum; i++) | |
7949 { | |
7950 s = reg_getline_submatch(slnum + i); | |
7951 if (list_append_string(list, s, -1) == FAIL) | |
7952 error = TRUE; | |
7953 } | |
7954 s = reg_getline_submatch(elnum); | |
7955 if (list_append_string(list, s, ecol) == FAIL) | |
7956 error = TRUE; | |
7957 } | |
7958 } | |
7959 else | |
7960 { | |
7961 s = submatch_match->startp[no]; | |
7962 if (s == NULL || submatch_match->endp[no] == NULL) | |
7963 return NULL; | |
7964 list = list_alloc(); | |
7965 if (list == NULL) | |
7966 return NULL; | |
7967 if (list_append_string(list, s, | |
7968 (int)(submatch_match->endp[no] - s)) == FAIL) | |
7969 error = TRUE; | |
7970 } | |
7971 | |
7972 if (error) | |
7973 { | |
7974 list_free(list, TRUE); | |
7975 return NULL; | |
7976 } | |
7977 return list; | |
7978 } | |
7900 #endif | 7979 #endif |
7901 | 7980 |
7902 static regengine_T bt_regengine = | 7981 static regengine_T bt_regengine = |
7903 { | 7982 { |
7904 bt_regcomp, | 7983 bt_regcomp, |