/*
* Return TRUE if string "s" ends with the string "find", possibly followed by
* white space and comments. Skip strings and comments.
- * Ignore "ignore" after "find" if it's not NULL.
*/
static int
-cin_ends_in(char_u *s, char_u *find, char_u *ignore)
+cin_ends_in(char_u *s, char_u *find)
{
char_u *p = s;
char_u *r;
if (STRNCMP(p, find, len) == 0)
{
r = skipwhite(p + len);
- if (ignore != NULL && STRNCMP(r, ignore, STRLEN(ignore)) == 0)
- r = skipwhite(r + STRLEN(ignore));
if (cin_nocode(r))
return TRUE;
}
}
/*
- * Recognize structure initialization and enumerations:
+ * Strings can be concatenated with comments between:
+ * "string0" |*comment*| "string1"
+ */
+ static char_u *
+cin_skip_comment_and_string(char_u *s)
+{
+ char_u *r = NULL, *p = s;
+ do
+ {
+ r = p;
+ p = cin_skipcomment(p);
+ if (*p)
+ p = skip_string(p);
+ } while (p != r);
+ return p;
+}
+
+/*
+ * Recognize structure or compound literal initialization:
+ * =|return [&][(typecast)] [{]
+ * The number of opening braces is arbitrary.
+ */
+ static int
+cin_is_compound_init(char_u *s)
+{
+ char_u *p = s, *r = NULL;
+
+ while (*p)
+ {
+ if (*p == '=')
+ p = r = cin_skipcomment(p + 1);
+ else if (!STRNCMP(p, "return", 6) && !vim_isIDc(p[6])
+ && (p == s || (p > s && !vim_isIDc(p[-1]))))
+ p = r = cin_skipcomment(p + 6);
+ else
+ p = cin_skip_comment_and_string(p + 1);
+ }
+ if (!r)
+ return FALSE;
+ p = r; // p points now after '=' or "return"
+
+ if (cin_nocode(p))
+ return TRUE;
+
+ if (*p == '&')
+ p = cin_skipcomment(p + 1);
+
+ if (*p == '(') // skip a typecast
+ {
+ int open_count = 1;
+ do
+ {
+ p = cin_skip_comment_and_string(p + 1);
+ if (cin_nocode(p))
+ return TRUE;
+ open_count += (*p == '(') - (*p == ')');
+ } while (open_count);
+ p = cin_skipcomment(p + 1);
+ if (cin_nocode(p))
+ return TRUE;
+ }
+
+ while (*p == '{')
+ p = cin_skipcomment(p + 1);
+ return cin_nocode(p);
+}
+
+/*
+ * Recognize enumerations:
* "[typedef] [static|public|protected|private] enum"
- * "[typedef] [static|public|protected|private] = {"
+ * Call another function to recognize structure initialization.
*/
static int
cin_isinit(void)
if (cin_starts_with(s, "enum"))
return TRUE;
- if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
- return TRUE;
-
- return FALSE;
+ return cin_is_compound_init(s);
}
// Maximum number of lines to search back for a "namespace" line.
if (find_last_paren(ml_get_curline(), '(', ')')
&& (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
amount = get_indent_lnum(trypos->lnum); // XXX
- if (!cin_ends_in(ml_get_curline(), (char_u *)",", NULL))
+ if (!cin_ends_in(ml_get_curline(), (char_u *)","))
amount += curbuf->b_ind_cpp_baseclass;
}
else
cur_amount = MAXCOL;
l = ml_get(our_paren_pos.lnum);
if (curbuf->b_ind_unclosed_wrapped
- && cin_ends_in(l, (char_u *)"(", NULL))
+ && cin_ends_in(l, (char_u *)"("))
{
// look for opening unmatched paren, indent one level
// for each additional level
&& !cin_nocode(theline)
&& vim_strchr(theline, '{') == NULL
&& vim_strchr(theline, '}') == NULL
- && !cin_ends_in(theline, (char_u *)":", NULL)
- && !cin_ends_in(theline, (char_u *)",", NULL)
+ && !cin_ends_in(theline, (char_u *)":")
+ && !cin_ends_in(theline, (char_u *)",")
&& cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
cur_curpos.lnum + 1)
&& !cin_isterminated(theline, FALSE, TRUE))
// } foo,
// bar;
n = 0;
- if (cin_ends_in(l, (char_u *)",", NULL)
+ if (cin_ends_in(l, (char_u *)",")
|| (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\'))
{
// take us back to opening paren
// comments) align at column 0. For example:
// char *string_array[] = { "foo",
// / * x * / "b};ar" }; / * foobar * /
- if (cin_ends_in(l, (char_u *)"};", NULL))
+ if (cin_ends_in(l, (char_u *)"};"))
break;
// If the previous line ends on '[' we are probably in an
// array constant:
// something = [
// 234, <- extra indent
- if (cin_ends_in(l, (char_u *)"[", NULL))
+ if (cin_ends_in(l, (char_u *)"["))
{
amount = get_indent() + ind_continuation;
break;
break;
}
if (curwin->w_cursor.lnum > 0
- && cin_ends_in(look, (char_u *)"}", NULL))
+ && cin_ends_in(look, (char_u *)"}"))
break;
curwin->w_cursor = curpos_save;
// int foo,
// bar;
// indent_to_0 here;
- if (cin_ends_in(l, (char_u *)";", NULL))
+ if (cin_ends_in(l, (char_u *)";"))
{
l = ml_get(curwin->w_cursor.lnum - 1);
- if (cin_ends_in(l, (char_u *)",", NULL)
+ if (cin_ends_in(l, (char_u *)",")
|| (*l != NUL && l[STRLEN(l) - 1] == '\\'))
break;
l = ml_get_curline();