Improve comments and fix ascii_* attributes

This commit is contained in:
Felipe Oliveira Carvalho
2015-04-23 00:03:36 -03:00
parent bcfc37ea98
commit c96b933acc
6 changed files with 34 additions and 28 deletions

View File

@@ -186,7 +186,7 @@ strcpy() STRCPY() Includes cast to (char *), for char_u * args
strchr() vim_strchr() Accepts special characters strchr() vim_strchr() Accepts special characters
strrchr() vim_strrchr() Accepts special characters strrchr() vim_strrchr() Accepts special characters
isspace() ascii_isspace() Can handle characters > 128 isspace() ascii_isspace() Can handle characters > 128
iswhite() ascii_iswhite() Only TRUE for tab and space iswhite() ascii_iswhite() Only true for tab and space
memcpy() mch_memmove() Handles overlapped copies memcpy() mch_memmove() Handles overlapped copies
bcopy() mch_memmove() Handles overlapped copies bcopy() mch_memmove() Handles overlapped copies
memset() vim_memset() Uniform for all systems memset() vim_memset() Uniform for all systems

View File

@@ -9,7 +9,8 @@
#define NVIM_ASCII_H #define NVIM_ASCII_H
#include <stdbool.h> #include <stdbool.h>
#include "func_attr.h"
#include "nvim/func_attr.h"
// Definitions of various common control characters. // Definitions of various common control characters.
@@ -90,32 +91,36 @@
# define PATHSEPSTR "/" # define PATHSEPSTR "/"
#endif #endif
static inline bool ascii_iswhite(int c) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST; static inline bool ascii_iswhite(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
static inline bool ascii_isdigit(int c) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST; static inline bool ascii_isdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
static inline bool ascii_isxdigit(int c) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST; static inline bool ascii_isxdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
static inline bool ascii_isspace(int x) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST; static inline bool ascii_isspace(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
/// ascii_iswhite() is used for "^" and the like. It differs from isspace() /// Checks if `c` is a space or tab character.
/// because it doesn't include <CR> and <LF> and the like. ///
/// @see {ascii_isdigit}
static inline bool ascii_iswhite(int c) static inline bool ascii_iswhite(int c)
{ {
return c == ' ' || c == '\t'; return c == ' ' || c == '\t';
} }
/// Use our own isdigit() replacement, because on MS-Windows isdigit() returns /// Check whether character is a decimal digit.
/// non-zero for superscript 1. Also avoids that isdigit() crashes for numbers ///
/// below 0 and above 255. /// Library isdigit() function is officially locale-dependent and, for
/// example, returns true for superscript 1 (¹) in locales where encoding
/// contains it in lower 8 bits. Also avoids crashes in case c is below
/// 0 or above 255: library functions are officially defined as accepting
/// only EOF and unsigned char values (otherwise it is undefined behaviour)
/// what may be used for some optimizations (e.g. simple `return
/// isdigit_table[c];`).
static inline bool ascii_isdigit(int c) static inline bool ascii_isdigit(int c)
{ {
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }
/// Variant of isxdigit() that can handle characters > 0x100. /// Checks if `c` is a hexadecimal digit, that is, one of 0-9, a-f, A-F.
/// We don't use isxdigit() here, because on some systems it also considers
/// superscript 1 to be a digit.
/// ///
/// @param c /// @see {ascii_isdigit}
/// @return TRUE if the character is a hexadecimal digit.
static inline bool ascii_isxdigit(int c) static inline bool ascii_isxdigit(int c)
{ {
return (c >= '0' && c <= '9') return (c >= '0' && c <= '9')
@@ -123,12 +128,13 @@ static inline bool ascii_isxdigit(int c)
|| (c >= 'A' && c <= 'F'); || (c >= 'A' && c <= 'F');
} }
/// Vim has its own isspace() function, because on some machines isspace() /// Checks if `c` is a white-space character, that is,
/// can't handle characters above 128. /// one of \f, \n, \r, \t, \v.
static inline bool ascii_isspace(int x) ///
/// @see {ascii_isdigit}
static inline bool ascii_isspace(int c)
{ {
return (x >= 9 && x <= 13) || x == ' '; return (c >= 9 && c <= 13) || c == ' ';
} }
#endif /* NVIM_ASCII_H */ #endif /* NVIM_ASCII_H */

View File

@@ -706,7 +706,8 @@ int get_lisp_indent(void)
if (vi_lisp || ((*that != '"') && (*that != '\'') if (vi_lisp || ((*that != '"') && (*that != '\'')
&& (*that != '#') && ((*that < '0') || (*that > '9')))) { && (*that != '#') && ((*that < '0') || (*that > '9')))) {
while (*that && (!ascii_iswhite(*that) || quotecount || parencount) while (*that
&& (!ascii_iswhite(*that) || quotecount || parencount)
&& (!((*that == '(' || *that == '[') && (!((*that == '(' || *that == '[')
&& !quotecount && !parencount && vi_lisp))) { && !quotecount && !parencount && vi_lisp))) {
if (*that == '"') { if (*that == '"') {

View File

@@ -3979,8 +3979,6 @@ static int ends_in_white(linenr_T lnum)
if (*s == NUL) if (*s == NUL)
return FALSE; return FALSE;
/* Don't use STRLEN() inside ascii_iswhite(), SAS/C complains: "macro
* invocation may call function multiple times". */
l = STRLEN(s) - 1; l = STRLEN(s) - 1;
return ascii_iswhite(s[l]); return ascii_iswhite(s[l]);
} }

View File

@@ -1023,7 +1023,7 @@ int do_search(
else /* single '+' */ else /* single '+' */
spats[0].off.off = 1; spats[0].off.off = 1;
++p; ++p;
while (ascii_isdigit(*p)) /* skip number */ while (ascii_isdigit(*p)) /* skip number */
++p; ++p;
} }
@@ -2921,7 +2921,7 @@ extend:
*/ */
if (start_blank) { if (start_blank) {
find_first_blank(&curwin->w_cursor); find_first_blank(&curwin->w_cursor);
c = gchar_pos(&curwin->w_cursor); /* ascii_iswhite() is a macro */ c = gchar_pos(&curwin->w_cursor);
if (ascii_iswhite(c)) if (ascii_iswhite(c))
decl(&curwin->w_cursor); decl(&curwin->w_cursor);
} else if (c = gchar_cursor(), !ascii_iswhite(c)) } else if (c = gchar_cursor(), !ascii_iswhite(c))

View File

@@ -7138,9 +7138,10 @@ int highlight_changed(void)
*/ */
attr = 0; attr = 0;
bool colon = false; bool colon = false;
for (; *p && *p != ','; ++p) { /* parse upto comma */ for (; *p && *p != ','; ++p) { // parse upto comma
if (ascii_iswhite(*p)) /* ignore white space */ if (ascii_iswhite(*p)) { // ignore white space
continue; continue;
}
if (colon) /* Combination with ':' is not allowed. */ if (colon) /* Combination with ':' is not allowed. */
return FAIL; return FAIL;