mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 07:28:34 +00:00
refactor(uncrustify): enable formatting for regexp and indent files (#18549)
The formatting for these files were originally disabled as to signal that "we don't own these files", meaning we intentionally want to minimize the amount of work put in these files as the return will be very little. This unfortunately conflicts with other refactoring efforts that happen to touch these files, and it's easier to simply enable formatting.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,6 @@
|
|||||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
|
||||||
// uncrustify:off
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handling of regular expressions: vim_regcomp(), vim_regexec(), vim_regsub()
|
* Handling of regular expressions: vim_regcomp(), vim_regexec(), vim_regsub()
|
||||||
*/
|
*/
|
||||||
@@ -18,21 +16,21 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "nvim/vim.h"
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/regexp.h"
|
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/eval/userfunc.h"
|
#include "nvim/eval/userfunc.h"
|
||||||
#include "nvim/ex_cmds2.h"
|
#include "nvim/ex_cmds2.h"
|
||||||
|
#include "nvim/garray.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/os/input.h"
|
#include "nvim/os/input.h"
|
||||||
#include "nvim/plines.h"
|
#include "nvim/plines.h"
|
||||||
#include "nvim/garray.h"
|
#include "nvim/regexp.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
#ifdef REGEXP_DEBUG
|
#ifdef REGEXP_DEBUG
|
||||||
// show/save debugging data when BT engine is used
|
// show/save debugging data when BT engine is used
|
||||||
@@ -62,15 +60,17 @@ typedef void (*(*fptr_T)(int *, int))(void);
|
|||||||
|
|
||||||
static int no_Magic(int x)
|
static int no_Magic(int x)
|
||||||
{
|
{
|
||||||
if (is_Magic(x))
|
if (is_Magic(x)) {
|
||||||
return un_Magic(x);
|
return un_Magic(x);
|
||||||
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int toggle_Magic(int x)
|
static int toggle_Magic(int x)
|
||||||
{
|
{
|
||||||
if (is_Magic(x))
|
if (is_Magic(x)) {
|
||||||
return un_Magic(x);
|
return un_Magic(x);
|
||||||
|
}
|
||||||
return Magic(x);
|
return Magic(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +93,7 @@ static int toggle_Magic(int x)
|
|||||||
return (semsg((const char *)(m), (c) ? "" : "\\", (a)), rc_did_emsg = true, (void *)NULL)
|
return (semsg((const char *)(m), (c) ? "" : "\\", (a)), rc_did_emsg = true, (void *)NULL)
|
||||||
#define EMSG2_RET_FAIL(m, c) \
|
#define EMSG2_RET_FAIL(m, c) \
|
||||||
return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, FAIL)
|
return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, FAIL)
|
||||||
#define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_( \
|
#define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)
|
||||||
"E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)
|
|
||||||
|
|
||||||
#define MAX_LIMIT (32767L << 16L)
|
#define MAX_LIMIT (32767L << 16L)
|
||||||
|
|
||||||
@@ -128,10 +127,12 @@ static char_u e_regexp_number_after_dot_pos_search[]
|
|||||||
/// Return MULTI_MULT if c is a multi "multi" operator.
|
/// Return MULTI_MULT if c is a multi "multi" operator.
|
||||||
static int re_multi_type(int c)
|
static int re_multi_type(int c)
|
||||||
{
|
{
|
||||||
if (c == Magic('@') || c == Magic('=') || c == Magic('?'))
|
if (c == Magic('@') || c == Magic('=') || c == Magic('?')) {
|
||||||
return MULTI_ONE;
|
return MULTI_ONE;
|
||||||
if (c == Magic('*') || c == Magic('+') || c == Magic('{'))
|
}
|
||||||
|
if (c == Magic('*') || c == Magic('+') || c == Magic('{')) {
|
||||||
return MULTI_MULT;
|
return MULTI_MULT;
|
||||||
|
}
|
||||||
return NOT_MULTI;
|
return NOT_MULTI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,10 +164,14 @@ static char_u REGEXP_ABBR[] = "nrtebdoxuU";
|
|||||||
static int backslash_trans(int c)
|
static int backslash_trans(int c)
|
||||||
{
|
{
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'r': return CAR;
|
case 'r':
|
||||||
case 't': return TAB;
|
return CAR;
|
||||||
case 'e': return ESC;
|
case 't':
|
||||||
case 'b': return BS;
|
return TAB;
|
||||||
|
case 'e':
|
||||||
|
return ESC;
|
||||||
|
case 'b':
|
||||||
|
return BS;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -223,12 +228,13 @@ static int get_char_class(char_u **pp)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ((*pp)[1] == ':') {
|
if ((*pp)[1] == ':') {
|
||||||
for (i = 0; i < (int)ARRAY_SIZE(class_names); ++i)
|
for (i = 0; i < (int)ARRAY_SIZE(class_names); i++) {
|
||||||
if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0) {
|
if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0) {
|
||||||
*pp += STRLEN(class_names[i]) + 2;
|
*pp += STRLEN(class_names[i]) + 2;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return CLASS_NONE;
|
return CLASS_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,41 +259,43 @@ static void init_class_tab(void)
|
|||||||
int i;
|
int i;
|
||||||
static int done = false;
|
static int done = false;
|
||||||
|
|
||||||
if (done)
|
if (done) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < 256; ++i) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (i >= '0' && i <= '7')
|
if (i >= '0' && i <= '7') {
|
||||||
class_tab[i] = RI_DIGIT + RI_HEX + RI_OCTAL + RI_WORD;
|
class_tab[i] = RI_DIGIT + RI_HEX + RI_OCTAL + RI_WORD;
|
||||||
else if (i >= '8' && i <= '9')
|
} else if (i >= '8' && i <= '9') {
|
||||||
class_tab[i] = RI_DIGIT + RI_HEX + RI_WORD;
|
class_tab[i] = RI_DIGIT + RI_HEX + RI_WORD;
|
||||||
else if (i >= 'a' && i <= 'f')
|
} else if (i >= 'a' && i <= 'f') {
|
||||||
class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
|
class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
|
||||||
else if (i >= 'g' && i <= 'z')
|
} else if (i >= 'g' && i <= 'z') {
|
||||||
class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
|
class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_LOWER;
|
||||||
else if (i >= 'A' && i <= 'F')
|
} else if (i >= 'A' && i <= 'F') {
|
||||||
class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
|
class_tab[i] = RI_HEX + RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
|
||||||
else if (i >= 'G' && i <= 'Z')
|
} else if (i >= 'G' && i <= 'Z') {
|
||||||
class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
|
class_tab[i] = RI_WORD + RI_HEAD + RI_ALPHA + RI_UPPER;
|
||||||
else if (i == '_')
|
} else if (i == '_') {
|
||||||
class_tab[i] = RI_WORD + RI_HEAD;
|
class_tab[i] = RI_WORD + RI_HEAD;
|
||||||
else
|
} else {
|
||||||
class_tab[i] = 0;
|
class_tab[i] = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
class_tab[' '] |= RI_WHITE;
|
class_tab[' '] |= RI_WHITE;
|
||||||
class_tab['\t'] |= RI_WHITE;
|
class_tab['\t'] |= RI_WHITE;
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
# define ri_digit(c) ((c) < 0x100 && (class_tab[c] & RI_DIGIT))
|
#define ri_digit(c) ((c) < 0x100 && (class_tab[c] & RI_DIGIT))
|
||||||
# define ri_hex(c) ((c) < 0x100 && (class_tab[c] & RI_HEX))
|
#define ri_hex(c) ((c) < 0x100 && (class_tab[c] & RI_HEX))
|
||||||
# define ri_octal(c) ((c) < 0x100 && (class_tab[c] & RI_OCTAL))
|
#define ri_octal(c) ((c) < 0x100 && (class_tab[c] & RI_OCTAL))
|
||||||
# define ri_word(c) ((c) < 0x100 && (class_tab[c] & RI_WORD))
|
#define ri_word(c) ((c) < 0x100 && (class_tab[c] & RI_WORD))
|
||||||
# define ri_head(c) ((c) < 0x100 && (class_tab[c] & RI_HEAD))
|
#define ri_head(c) ((c) < 0x100 && (class_tab[c] & RI_HEAD))
|
||||||
# define ri_alpha(c) ((c) < 0x100 && (class_tab[c] & RI_ALPHA))
|
#define ri_alpha(c) ((c) < 0x100 && (class_tab[c] & RI_ALPHA))
|
||||||
# define ri_lower(c) ((c) < 0x100 && (class_tab[c] & RI_LOWER))
|
#define ri_lower(c) ((c) < 0x100 && (class_tab[c] & RI_LOWER))
|
||||||
# define ri_upper(c) ((c) < 0x100 && (class_tab[c] & RI_UPPER))
|
#define ri_upper(c) ((c) < 0x100 && (class_tab[c] & RI_UPPER))
|
||||||
# define ri_white(c) ((c) < 0x100 && (class_tab[c] & RI_WHITE))
|
#define ri_white(c) ((c) < 0x100 && (class_tab[c] & RI_WHITE))
|
||||||
|
|
||||||
// flags for regflags
|
// flags for regflags
|
||||||
#define RF_ICASE 1 // ignore case
|
#define RF_ICASE 1 // ignore case
|
||||||
@@ -320,6 +328,8 @@ static int reg_strict; // "[abc" is illegal
|
|||||||
* META contains all characters that may be magic, except '^' and '$'.
|
* META contains all characters that may be magic, except '^' and '$'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// uncrustify:off
|
||||||
|
|
||||||
// META[] is used often enough to justify turning it into a table.
|
// META[] is used often enough to justify turning it into a table.
|
||||||
static char_u META_flags[] = {
|
static char_u META_flags[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@@ -338,6 +348,8 @@ static char_u META_flags[] = {
|
|||||||
1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
|
1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// uncrustify:on
|
||||||
|
|
||||||
static int curchr; // currently parsed character
|
static int curchr; // currently parsed character
|
||||||
// Previous character. Note: prevchr is sometimes -1 when we are not at the
|
// Previous character. Note: prevchr is sometimes -1 when we are not at the
|
||||||
// start, eg in /[ ^I]^ the pattern was never found even if it existed,
|
// start, eg in /[ ^I]^ the pattern was never found even if it existed,
|
||||||
@@ -490,10 +502,11 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char_u **newp)
|
|||||||
int mymagic;
|
int mymagic;
|
||||||
char_u *p = startp;
|
char_u *p = startp;
|
||||||
|
|
||||||
if (magic)
|
if (magic) {
|
||||||
mymagic = MAGIC_ON;
|
mymagic = MAGIC_ON;
|
||||||
else
|
} else {
|
||||||
mymagic = MAGIC_OFF;
|
mymagic = MAGIC_OFF;
|
||||||
|
}
|
||||||
get_cpo_flags();
|
get_cpo_flags();
|
||||||
|
|
||||||
for (; p[0] != NUL; MB_PTR_ADV(p)) {
|
for (; p[0] != NUL; MB_PTR_ADV(p)) {
|
||||||
@@ -503,8 +516,9 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char_u **newp)
|
|||||||
if ((p[0] == '[' && mymagic >= MAGIC_ON)
|
if ((p[0] == '[' && mymagic >= MAGIC_ON)
|
||||||
|| (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF)) {
|
|| (p[0] == '\\' && p[1] == '[' && mymagic <= MAGIC_OFF)) {
|
||||||
p = skip_anyof(p + 1);
|
p = skip_anyof(p + 1);
|
||||||
if (p[0] == NUL)
|
if (p[0] == NUL) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
} else if (p[0] == '\\' && p[1] != NUL) {
|
} else if (p[0] == '\\' && p[1] != NUL) {
|
||||||
if (dirc == '?' && newp != NULL && p[1] == '?') {
|
if (dirc == '?' && newp != NULL && p[1] == '?') {
|
||||||
// change "\?" to "?", make a copy first.
|
// change "\?" to "?", make a copy first.
|
||||||
@@ -686,8 +700,7 @@ static int peekchr(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\': {
|
||||||
{
|
|
||||||
int c = regparse[1];
|
int c = regparse[1];
|
||||||
|
|
||||||
if (c == NUL) {
|
if (c == NUL) {
|
||||||
@@ -712,13 +725,11 @@ static int peekchr(void)
|
|||||||
* Handle abbreviations, like "\t" for TAB -- webb
|
* Handle abbreviations, like "\t" for TAB -- webb
|
||||||
*/
|
*/
|
||||||
curchr = backslash_trans(c);
|
curchr = backslash_trans(c);
|
||||||
} else if (reg_magic == MAGIC_NONE && (c == '$' || c == '^'))
|
} else if (reg_magic == MAGIC_NONE && (c == '$' || c == '^')) {
|
||||||
curchr = toggle_Magic(c);
|
curchr = toggle_Magic(c);
|
||||||
else {
|
} else {
|
||||||
/*
|
// Next character can never be (made) magic?
|
||||||
* Next character can never be (made) magic?
|
// Then backslashing it won't do anything.
|
||||||
* Then backslashing it won't do anything.
|
|
||||||
*/
|
|
||||||
curchr = utf_ptr2char((char *)regparse + 1);
|
curchr = utf_ptr2char((char *)regparse + 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -816,15 +827,17 @@ static int64_t gethexchrs(int maxinputlen)
|
|||||||
|
|
||||||
for (i = 0; i < maxinputlen; ++i) {
|
for (i = 0; i < maxinputlen; ++i) {
|
||||||
c = regparse[0];
|
c = regparse[0];
|
||||||
if (!ascii_isxdigit(c))
|
if (!ascii_isxdigit(c)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
nr <<= 4;
|
nr <<= 4;
|
||||||
nr |= hex2nr(c);
|
nr |= hex2nr(c);
|
||||||
++regparse;
|
++regparse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,16 +853,18 @@ static int64_t getdecchrs(void)
|
|||||||
|
|
||||||
for (i = 0;; ++i) {
|
for (i = 0;; ++i) {
|
||||||
c = regparse[0];
|
c = regparse[0];
|
||||||
if (c < '0' || c > '9')
|
if (c < '0' || c > '9') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
nr *= 10;
|
nr *= 10;
|
||||||
nr += c - '0';
|
nr += c - '0';
|
||||||
regparse++;
|
regparse++;
|
||||||
curchr = -1; // no longer valid
|
curchr = -1; // no longer valid
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -869,15 +884,17 @@ static int64_t getoctchrs(void)
|
|||||||
|
|
||||||
for (i = 0; i < 3 && nr < 040; i++) { // -V536
|
for (i = 0; i < 3 && nr < 040; i++) { // -V536
|
||||||
c = regparse[0];
|
c = regparse[0];
|
||||||
if (c < '0' || c > '7')
|
if (c < '0' || c > '7') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
nr <<= 3;
|
nr <<= 3;
|
||||||
nr |= hex2nr(c);
|
nr |= hex2nr(c);
|
||||||
++regparse;
|
++regparse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,8 +1080,9 @@ static reg_extmatch_T *make_extmatch(void)
|
|||||||
*/
|
*/
|
||||||
reg_extmatch_T *ref_extmatch(reg_extmatch_T *em)
|
reg_extmatch_T *ref_extmatch(reg_extmatch_T *em)
|
||||||
{
|
{
|
||||||
if (em != NULL)
|
if (em != NULL) {
|
||||||
em->refcnt++;
|
em->refcnt++;
|
||||||
|
}
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1077,8 +1095,9 @@ void unref_extmatch(reg_extmatch_T *em)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (em != NULL && --em->refcnt <= 0) {
|
if (em != NULL && --em->refcnt <= 0) {
|
||||||
for (i = 0; i < NSUBEXP; ++i)
|
for (i = 0; i < NSUBEXP; i++) {
|
||||||
xfree(em->matches[i]);
|
xfree(em->matches[i]);
|
||||||
|
}
|
||||||
xfree(em);
|
xfree(em);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1087,8 +1106,7 @@ void unref_extmatch(reg_extmatch_T *em)
|
|||||||
static int reg_prev_class(void)
|
static int reg_prev_class(void)
|
||||||
{
|
{
|
||||||
if (rex.input > rex.line) {
|
if (rex.input > rex.line) {
|
||||||
return mb_get_class_tab(
|
return mb_get_class_tab(rex.input - 1 - utf_head_off(rex.line, rex.input - 1),
|
||||||
rex.input - 1 - utf_head_off(rex.line, rex.input - 1),
|
|
||||||
rex.reg_buf->b_chartab);
|
rex.reg_buf->b_chartab);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1147,10 +1165,12 @@ static bool reg_match_visual(void)
|
|||||||
} else if (mode == Ctrl_V) {
|
} else if (mode == Ctrl_V) {
|
||||||
getvvcol(wp, &top, &start, NULL, &end);
|
getvvcol(wp, &top, &start, NULL, &end);
|
||||||
getvvcol(wp, &bot, &start2, NULL, &end2);
|
getvvcol(wp, &bot, &start2, NULL, &end2);
|
||||||
if (start2 < start)
|
if (start2 < start) {
|
||||||
start = start2;
|
start = start2;
|
||||||
if (end2 > end)
|
}
|
||||||
|
if (end2 > end) {
|
||||||
end = end2;
|
end = end2;
|
||||||
|
}
|
||||||
if (top.col == MAXCOL || bot.col == MAXCOL || curswant == MAXCOL) {
|
if (top.col == MAXCOL || bot.col == MAXCOL || curswant == MAXCOL) {
|
||||||
end = MAXCOL;
|
end = MAXCOL;
|
||||||
}
|
}
|
||||||
@@ -1241,21 +1261,18 @@ static void reg_nextline(void)
|
|||||||
* If "bytelen" is not NULL, it is set to the byte length of the match in the
|
* If "bytelen" is not NULL, it is set to the byte length of the match in the
|
||||||
* last line.
|
* last line.
|
||||||
*/
|
*/
|
||||||
static int match_with_backref(
|
static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum,
|
||||||
linenr_T start_lnum,
|
colnr_T end_col, int *bytelen)
|
||||||
colnr_T start_col,
|
|
||||||
linenr_T end_lnum,
|
|
||||||
colnr_T end_col,
|
|
||||||
int *bytelen)
|
|
||||||
{
|
{
|
||||||
linenr_T clnum = start_lnum;
|
linenr_T clnum = start_lnum;
|
||||||
colnr_T ccol = start_col;
|
colnr_T ccol = start_col;
|
||||||
int len;
|
int len;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
if (bytelen != NULL)
|
if (bytelen != NULL) {
|
||||||
*bytelen = 0;
|
*bytelen = 0;
|
||||||
for (;; ) {
|
}
|
||||||
|
for (;;) {
|
||||||
// Since getting one line may invalidate the other, need to make copy.
|
// Since getting one line may invalidate the other, need to make copy.
|
||||||
// Slow!
|
// Slow!
|
||||||
if (rex.line != reg_tofree) {
|
if (rex.line != reg_tofree) {
|
||||||
@@ -1275,10 +1292,11 @@ static int match_with_backref(
|
|||||||
p = reg_getline(clnum);
|
p = reg_getline(clnum);
|
||||||
assert(p);
|
assert(p);
|
||||||
|
|
||||||
if (clnum == end_lnum)
|
if (clnum == end_lnum) {
|
||||||
len = end_col - ccol;
|
len = end_col - ccol;
|
||||||
else
|
} else {
|
||||||
len = (int)STRLEN(p + ccol);
|
len = (int)STRLEN(p + ccol);
|
||||||
|
}
|
||||||
|
|
||||||
if (cstrncmp(p + ccol, rex.input, &len) != 0) {
|
if (cstrncmp(p + ccol, rex.input, &len) != 0) {
|
||||||
return RA_NOMATCH; // doesn't match
|
return RA_NOMATCH; // doesn't match
|
||||||
@@ -1295,13 +1313,15 @@ static int match_with_backref(
|
|||||||
|
|
||||||
// Advance to next line.
|
// Advance to next line.
|
||||||
reg_nextline();
|
reg_nextline();
|
||||||
if (bytelen != NULL)
|
if (bytelen != NULL) {
|
||||||
*bytelen = 0;
|
*bytelen = 0;
|
||||||
++clnum;
|
}
|
||||||
|
clnum++;
|
||||||
ccol = 0;
|
ccol = 0;
|
||||||
if (got_int)
|
if (got_int) {
|
||||||
return RA_FAIL;
|
return RA_FAIL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// found a match! Note that rex.line may now point to a copy of the line,
|
// found a match! Note that rex.line may now point to a copy of the line,
|
||||||
// that should not matter.
|
// that should not matter.
|
||||||
@@ -1324,7 +1344,7 @@ typedef struct {
|
|||||||
} decomp_T;
|
} decomp_T;
|
||||||
|
|
||||||
// 0xfb20 - 0xfb4f
|
// 0xfb20 - 0xfb4f
|
||||||
static decomp_T decomp_table[0xfb4f-0xfb20+1] =
|
static decomp_T decomp_table[0xfb4f - 0xfb20 + 1] =
|
||||||
{
|
{
|
||||||
{ 0x5e2, 0, 0 }, // 0xfb20 alt ayin
|
{ 0x5e2, 0, 0 }, // 0xfb20 alt ayin
|
||||||
{ 0x5d0, 0, 0 }, // 0xfb21 alt alef
|
{ 0x5d0, 0, 0 }, // 0xfb21 alt alef
|
||||||
@@ -1435,9 +1455,10 @@ static int cstrncmp(char_u *s1, char_u *s2, int *n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = c2 - c1;
|
result = c2 - c1;
|
||||||
if (result == 0)
|
if (result == 0) {
|
||||||
*n = (int)(str2 - s2);
|
*n = (int)(str2 - s2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1605,8 +1626,7 @@ static regsubmatch_T rsm; // can only be used when can_f_submatch is true
|
|||||||
|
|
||||||
/// Put the submatches in "argv[argskip]" which is a list passed into
|
/// Put the submatches in "argv[argskip]" which is a list passed into
|
||||||
/// call_func() by vim_regsub_both().
|
/// call_func() by vim_regsub_both().
|
||||||
static int fill_submatch_list(int argc FUNC_ATTR_UNUSED, typval_T *argv,
|
static int fill_submatch_list(int argc FUNC_ATTR_UNUSED, typval_T *argv, int argskip, int argcount)
|
||||||
int argskip, int argcount)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
typval_T *listarg = argv + argskip;
|
typval_T *listarg = argv + argskip;
|
||||||
@@ -1658,8 +1678,8 @@ static void clear_submatch_list(staticList10_T *sl)
|
|||||||
/// references invalid!
|
/// references invalid!
|
||||||
///
|
///
|
||||||
/// Returns the size of the replacement, including terminating NUL.
|
/// Returns the size of the replacement, including terminating NUL.
|
||||||
int vim_regsub(regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest,
|
int vim_regsub(regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest, int copy, int magic,
|
||||||
int copy, int magic, int backslash)
|
int backslash)
|
||||||
{
|
{
|
||||||
regexec_T rex_save;
|
regexec_T rex_save;
|
||||||
bool rex_in_use_save = rex_in_use;
|
bool rex_in_use_save = rex_in_use;
|
||||||
@@ -1685,8 +1705,8 @@ int vim_regsub(regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *dest,
|
int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *dest, int copy,
|
||||||
int copy, int magic, int backslash)
|
int magic, int backslash)
|
||||||
{
|
{
|
||||||
regexec_T rex_save;
|
regexec_T rex_save;
|
||||||
bool rex_in_use_save = rex_in_use;
|
bool rex_in_use_save = rex_in_use;
|
||||||
@@ -1713,8 +1733,8 @@ int vim_regsub_multi(regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *de
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, int copy, int magic,
|
||||||
int copy, int magic, int backslash)
|
int backslash)
|
||||||
{
|
{
|
||||||
char_u *src;
|
char_u *src;
|
||||||
char_u *dst;
|
char_u *dst;
|
||||||
@@ -1737,8 +1757,9 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
emsg(_(e_null));
|
emsg(_(e_null));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (prog_magic_wrong())
|
if (prog_magic_wrong()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
src = source;
|
src = source;
|
||||||
dst = dest;
|
dst = dest;
|
||||||
|
|
||||||
@@ -1851,11 +1872,11 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
rsm = rsm_save;
|
rsm = rsm_save;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
while ((c = *src++) != NUL) {
|
while ((c = *src++) != NUL) {
|
||||||
if (c == '&' && magic)
|
if (c == '&' && magic) {
|
||||||
no = 0;
|
no = 0;
|
||||||
else if (c == '\\' && *src != NUL) {
|
} else if (c == '\\' && *src != NUL) {
|
||||||
if (*src == '&' && !magic) {
|
if (*src == '&' && !magic) {
|
||||||
++src;
|
++src;
|
||||||
no = 0;
|
no = 0;
|
||||||
@@ -1863,16 +1884,21 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
no = *src++ - '0';
|
no = *src++ - '0';
|
||||||
} else if (vim_strchr((char_u *)"uUlLeE", *src)) {
|
} else if (vim_strchr((char_u *)"uUlLeE", *src)) {
|
||||||
switch (*src++) {
|
switch (*src++) {
|
||||||
case 'u': func_one = (fptr_T)do_upper;
|
case 'u':
|
||||||
|
func_one = (fptr_T)do_upper;
|
||||||
continue;
|
continue;
|
||||||
case 'U': func_all = (fptr_T)do_Upper;
|
case 'U':
|
||||||
|
func_all = (fptr_T)do_Upper;
|
||||||
continue;
|
continue;
|
||||||
case 'l': func_one = (fptr_T)do_lower;
|
case 'l':
|
||||||
|
func_one = (fptr_T)do_lower;
|
||||||
continue;
|
continue;
|
||||||
case 'L': func_all = (fptr_T)do_Lower;
|
case 'L':
|
||||||
|
func_all = (fptr_T)do_Lower;
|
||||||
continue;
|
continue;
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E': func_one = func_all = (fptr_T)NULL;
|
case 'E':
|
||||||
|
func_one = func_all = (fptr_T)NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1894,12 +1920,16 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
if (c == '\\' && *src != NUL) {
|
if (c == '\\' && *src != NUL) {
|
||||||
// Check for abbreviations -- webb
|
// Check for abbreviations -- webb
|
||||||
switch (*src) {
|
switch (*src) {
|
||||||
case 'r': c = CAR; ++src; break;
|
case 'r':
|
||||||
case 'n': c = NL; ++src; break;
|
c = CAR; ++src; break;
|
||||||
case 't': c = TAB; ++src; break;
|
case 'n':
|
||||||
|
c = NL; ++src; break;
|
||||||
|
case 't':
|
||||||
|
c = TAB; ++src; break;
|
||||||
// Oh no! \e already has meaning in subst pat :-(
|
// Oh no! \e already has meaning in subst pat :-(
|
||||||
// case 'e': c = ESC; ++src; break;
|
// case 'e': c = ESC; ++src; break;
|
||||||
case 'b': c = Ctrl_H; ++src; break;
|
case 'b':
|
||||||
|
c = Ctrl_H; ++src; break;
|
||||||
|
|
||||||
// If "backslash" is true the backslash will be removed
|
// If "backslash" is true the backslash will be removed
|
||||||
// later. Used to insert a literal CR.
|
// later. Used to insert a literal CR.
|
||||||
@@ -1967,7 +1997,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
for (;; ) {
|
for (;;) {
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
if (REG_MULTI) {
|
if (REG_MULTI) {
|
||||||
if (rex.reg_mmatch->endpos[no].lnum == clnum) {
|
if (rex.reg_mmatch->endpos[no].lnum == clnum) {
|
||||||
@@ -2042,8 +2072,10 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
|||||||
no = -1;
|
no = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (copy)
|
}
|
||||||
|
if (copy) {
|
||||||
*dst = NUL;
|
*dst = NUL;
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return (int)((dst - dest) + 1 - num_escaped);
|
return (int)((dst - dest) + 1 - num_escaped);
|
||||||
@@ -2083,8 +2115,9 @@ char_u *reg_submatch(int no)
|
|||||||
int round;
|
int round;
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
|
|
||||||
if (!can_f_submatch || no < 0)
|
if (!can_f_submatch || no < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (rsm.sm_match == NULL) {
|
if (rsm.sm_match == NULL) {
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
@@ -2123,12 +2156,14 @@ char_u *reg_submatch(int no)
|
|||||||
lnum++;
|
lnum++;
|
||||||
while (lnum < rsm.sm_mmatch->endpos[no].lnum) {
|
while (lnum < rsm.sm_mmatch->endpos[no].lnum) {
|
||||||
s = reg_getline_submatch(lnum++);
|
s = reg_getline_submatch(lnum++);
|
||||||
if (round == 2)
|
if (round == 2) {
|
||||||
STRCPY(retval + len, s);
|
STRCPY(retval + len, s);
|
||||||
|
}
|
||||||
len += STRLEN(s);
|
len += STRLEN(s);
|
||||||
if (round == 2)
|
if (round == 2) {
|
||||||
retval[len] = '\n';
|
retval[len] = '\n';
|
||||||
++len;
|
}
|
||||||
|
len++;
|
||||||
}
|
}
|
||||||
if (round == 2) {
|
if (round == 2) {
|
||||||
STRNCPY(retval + len, reg_getline_submatch(lnum),
|
STRNCPY(retval + len, reg_getline_submatch(lnum),
|
||||||
@@ -2273,8 +2308,7 @@ regprog_T *vim_regcomp(char_u *expr_arg, int re_flags)
|
|||||||
regname[newengine]);
|
regname[newengine]);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
emsg(_(
|
emsg(_("E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be used "));
|
||||||
"E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be used "));
|
|
||||||
regexp_engine = AUTOMATIC_ENGINE;
|
regexp_engine = AUTOMATIC_ENGINE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2339,8 +2373,9 @@ regprog_T *vim_regcomp(char_u *expr_arg, int re_flags)
|
|||||||
*/
|
*/
|
||||||
void vim_regfree(regprog_T *prog)
|
void vim_regfree(regprog_T *prog)
|
||||||
{
|
{
|
||||||
if (prog != NULL)
|
if (prog != NULL) {
|
||||||
prog->engine->regfree(prog);
|
prog->engine->regfree(prog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2462,16 +2497,17 @@ bool vim_regexec_nl(regmatch_T *rmp, char_u *line, colnr_T col)
|
|||||||
/// Note: "rmp->regprog" may be freed and changed, even set to NULL.
|
/// Note: "rmp->regprog" may be freed and changed, even set to NULL.
|
||||||
/// Uses curbuf for line count and 'iskeyword'.
|
/// Uses curbuf for line count and 'iskeyword'.
|
||||||
///
|
///
|
||||||
/// Return zero if there is no match. Return number of lines contained in the
|
/// @param win window in which to search or NULL
|
||||||
|
/// @param buf buffer in which to search
|
||||||
|
/// @param lnum nr of line to start looking for match
|
||||||
|
/// @param col column to start looking for match
|
||||||
|
/// @param tm timeout limit or NULL
|
||||||
|
/// @param timed_out flag is set when timeout limit reached
|
||||||
|
///
|
||||||
|
/// @return zero if there is no match. Return number of lines contained in the
|
||||||
/// match otherwise.
|
/// match otherwise.
|
||||||
long vim_regexec_multi(
|
long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col,
|
||||||
regmmatch_T *rmp,
|
proftime_T *tm, int *timed_out)
|
||||||
win_T *win, // window in which to search or NULL
|
|
||||||
buf_T *buf, // buffer in which to search
|
|
||||||
linenr_T lnum, // nr of line to start looking for match
|
|
||||||
colnr_T col, // column to start looking for match
|
|
||||||
proftime_T *tm, // timeout limit or NULL
|
|
||||||
int *timed_out) // flag is set when timeout limit reached
|
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
regexec_T rex_save;
|
regexec_T rex_save;
|
||||||
|
1635
src/nvim/regexp_bt.c
1635
src/nvim/regexp_bt.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user