Merge pull request #4103 from cacplate/pr-3695

charset.c: change return type to bool
This commit is contained in:
Björn Linse
2016-02-09 18:18:53 +01:00

View File

@@ -799,32 +799,35 @@ unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len)
return (unsigned int)col; return (unsigned int)col;
} }
/// Return TRUE if 'c' is a normal identifier character: /// Check that "c" is a normal identifier character:
///
/// Letters and characters from the 'isident' option. /// Letters and characters from the 'isident' option.
/// ///
/// @param c /// @param c character to check
/// bool vim_isIDc(int c)
/// @return TRUE if 'c' is a normal identifier character. FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int vim_isIDc(int c)
{ {
return c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR); return c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR);
} }
/// return TRUE if 'c' is a keyword character: Letters and characters from /// Check that "c" is a keyword character:
/// 'iskeyword' option for current buffer. /// Letters and characters from 'iskeyword' option for current buffer.
///
/// For multi-byte characters mb_get_class() is used (builtin rules). /// For multi-byte characters mb_get_class() is used (builtin rules).
/// ///
/// @param c /// @param c character to check
/// bool vim_iswordc(int c)
/// @return TRUE if 'c' is a keyword character. FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int vim_iswordc(int c)
{ {
return vim_iswordc_buf(c, curbuf); return vim_iswordc_buf(c, curbuf);
} }
int vim_iswordc_buf(int c, buf_T *buf) /// Check that "c" is a keyword character:
/// Letters and characters from 'iskeyword' option for given buffer.
/// For multi-byte characters mb_get_class() is used (builtin rules).
///
/// @param c character to check
/// @param buf buffer whose keywords to use
bool vim_iswordc_buf(int c, buf_T *buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2)
{ {
if (c >= 0x100) { if (c >= 0x100) {
if (enc_dbcs != 0) { if (enc_dbcs != 0) {
@@ -840,10 +843,11 @@ int vim_iswordc_buf(int c, buf_T *buf)
/// Just like vim_iswordc() but uses a pointer to the (multi-byte) character. /// Just like vim_iswordc() but uses a pointer to the (multi-byte) character.
/// ///
/// @param p /// @param p pointer to the multi-byte character
/// ///
/// @return TRUE if 'p' points to a keyword character. /// @return true if "p" points to a keyword character.
int vim_iswordp(char_u *p) bool vim_iswordp(char_u *p)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) { if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) {
return mb_get_class(p) >= 2; return mb_get_class(p) >= 2;
@@ -851,7 +855,15 @@ int vim_iswordp(char_u *p)
return GET_CHARTAB(curbuf, *p) != 0; return GET_CHARTAB(curbuf, *p) != 0;
} }
int vim_iswordp_buf(char_u *p, buf_T *buf) /// Just like vim_iswordc_buf() but uses a pointer to the (multi-byte)
/// character.
///
/// @param p pointer to the multi-byte character
/// @param buf buffer whose keywords to use
///
/// @return true if "p" points to a keyword character.
bool vim_iswordp_buf(char_u *p, buf_T *buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) { if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) {
return mb_get_class(p) >= 2; return mb_get_class(p) >= 2;
@@ -859,26 +871,24 @@ int vim_iswordp_buf(char_u *p, buf_T *buf)
return GET_CHARTAB(buf, *p) != 0; return GET_CHARTAB(buf, *p) != 0;
} }
/// return TRUE if 'c' is a valid file-name character /// Check that "c" is a valid file-name character.
/// Assume characters above 0x100 are valid (multi-byte). /// Assume characters above 0x100 are valid (multi-byte).
/// ///
/// @param c /// @param c character to check
/// bool vim_isfilec(int c)
/// @return TRUE if 'c' is a valid file name character. FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int vim_isfilec(int c)
{ {
return c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR)); return c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR));
} }
/// return TRUE if 'c' is a valid file-name character or a wildcard character /// Check that "c" is a valid file-name character or a wildcard character
/// Assume characters above 0x100 are valid (multi-byte). /// Assume characters above 0x100 are valid (multi-byte).
/// Explicitly interpret ']' as a wildcard character as path_has_wildcard("]") /// Explicitly interpret ']' as a wildcard character as path_has_wildcard("]")
/// returns false. /// returns false.
/// ///
/// @param c /// @param c character to check
/// bool vim_isfilec_or_wc(int c)
/// @return TRUE if 'c' is a valid file-name character or wildcard character. FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int vim_isfilec_or_wc(int c)
{ {
char_u buf[2]; char_u buf[2];
buf[0] = (char_u)c; buf[0] = (char_u)c;
@@ -886,14 +896,12 @@ int vim_isfilec_or_wc(int c)
return vim_isfilec(c) || c == ']' || path_has_wildcard(buf); return vim_isfilec(c) || c == ']' || path_has_wildcard(buf);
} }
/// return TRUE if 'c' is a printable character /// Check that "c" is a printable character.
/// Assume characters above 0x100 are printable (multi-byte), except for /// Assume characters above 0x100 are printable for double-byte encodings.
/// Unicode.
/// ///
/// @param c /// @param c character to check
/// bool vim_isprintc(int c)
/// @return TRUE if 'c' a printable character. FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
int vim_isprintc(int c)
{ {
if (enc_utf8 && (c >= 0x100)) { if (enc_utf8 && (c >= 0x100)) {
return utf_printable(c); return utf_printable(c);
@@ -901,16 +909,17 @@ int vim_isprintc(int c)
return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)); return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR));
} }
/// Strict version of vim_isprintc(c), don't return TRUE if "c" is the head /// Strict version of vim_isprintc(c), don't return true if "c" is the head
/// byte of a double-byte character. /// byte of a double-byte character.
/// ///
/// @param c /// @param c character to check
/// ///
/// @return TRUE if 'c' is a printable character. /// @return true if "c" is a printable character.
int vim_isprintc_strict(int c) bool vim_isprintc_strict(int c)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
if ((enc_dbcs != 0) && (c < 0x100) && (MB_BYTE2LEN(c) > 1)) { if ((enc_dbcs != 0) && (c < 0x100) && (MB_BYTE2LEN(c) > 1)) {
return FALSE; return false;
} }
if (enc_utf8 && (c >= 0x100)) { if (enc_utf8 && (c >= 0x100)) {
@@ -1144,35 +1153,33 @@ static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
return n; return n;
} }
/// Return TRUE if virtual column "vcol" is in the rightmost column of window /// Check that virtual column "vcol" is in the rightmost column of window "wp".
/// "wp".
/// ///
/// @param wp /// @param wp window
/// @param vcol /// @param vcol column number
/// bool in_win_border(win_T *wp, colnr_T vcol)
/// @return TRUE if the virtual column is in the rightmost column. FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
int in_win_border(win_T *wp, colnr_T vcol)
{ {
int width1; // width of first line (after line number) int width1; // width of first line (after line number)
int width2; // width of further lines int width2; // width of further lines
if (wp->w_width == 0) { if (wp->w_width == 0) {
// there is no border // there is no border
return FALSE; return false;
} }
width1 = wp->w_width - win_col_off(wp); width1 = wp->w_width - win_col_off(wp);
if ((int)vcol < width1 - 1) { if ((int)vcol < width1 - 1) {
return FALSE; return false;
} }
if ((int)vcol == width1 - 1) { if ((int)vcol == width1 - 1) {
return TRUE; return true;
} }
width2 = width1 + win_col_off2(wp); width2 = width1 + win_col_off2(wp);
if (width2 <= 0) { if (width2 <= 0) {
return FALSE; return false;
} }
return (vcol - width1) % width2 == width2 - 1; return (vcol - width1) % width2 == width2 - 1;
} }
@@ -1571,10 +1578,14 @@ static char_u latin1lower[257] =
"\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee" "\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee"
"\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"; "\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
int vim_islower(int c) /// Check that the character is lower-case
///
/// @param c character to check
bool vim_islower(int c)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
if (c <= '@') { if (c <= '@') {
return FALSE; return false;
} }
if (c >= 0x80) { if (c >= 0x80) {
@@ -1588,7 +1599,7 @@ int vim_islower(int c)
} }
// islower() can't handle these chars and may crash // islower() can't handle these chars and may crash
return FALSE; return false;
} }
if (enc_latin1like) { if (enc_latin1like) {
@@ -1598,10 +1609,14 @@ int vim_islower(int c)
return islower(c); return islower(c);
} }
int vim_isupper(int c) /// Check that the character is upper-case
///
/// @param c character to check
bool vim_isupper(int c)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
if (c <= '@') { if (c <= '@') {
return FALSE; return false;
} }
if (c >= 0x80) { if (c >= 0x80) {
@@ -1614,8 +1629,8 @@ int vim_isupper(int c)
return iswupper(c); return iswupper(c);
} }
// islower() can't handle these chars and may crash // isupper() can't handle these chars and may crash
return FALSE; return false;
} }
if (enc_latin1like) { if (enc_latin1like) {
@@ -1744,12 +1759,10 @@ long getdigits_long(char_u **pp)
return (long)number; return (long)number;
} }
/// Return TRUE if "lbuf" is empty or only contains blanks. /// Check that "lbuf" is empty or only contains blanks.
/// ///
/// @param lbuf /// @param lbuf line buffer to check
/// bool vim_isblankline(char_u *lbuf)
/// @return TRUE if `lbuf` is empty or only contains blanks.
int vim_isblankline(char_u *lbuf)
{ {
char_u *p = skipwhite(lbuf); char_u *p = skipwhite(lbuf);
return *p == NUL || *p == '\r' || *p == '\n'; return *p == NUL || *p == '\r' || *p == '\n';
@@ -1922,8 +1935,8 @@ int hex2nr(int c)
return c - '0'; return c - '0';
} }
/// Return true if "str" starts with a backslash that should be removed. /// Check that "str" starts with a backslash that should be removed.
/// For WIN32 this is only done when the character after the /// For Windows this is only done when the character after the
/// backslash is not a normal file name character. /// backslash is not a normal file name character.
/// '$' is a valid file name character, we don't remove the backslash before /// '$' is a valid file name character, we don't remove the backslash before
/// it. This means it is not possible to use an environment variable after a /// it. This means it is not possible to use an environment variable after a
@@ -1934,10 +1947,9 @@ int hex2nr(int c)
/// character, assume that all multi-byte characters are valid file name /// character, assume that all multi-byte characters are valid file name
/// characters. /// characters.
/// ///
/// @param str /// @param str file path string to check
///
/// @return true if `str` starts with a backslash that should be removed.
bool rem_backslash(const char_u *str) bool rem_backslash(const char_u *str)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
return str[0] == '\\' return str[0] == '\\'