aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2015-04-23 00:03:36 -0300
committerFelipe Oliveira Carvalho <felipekde@gmail.com>2015-04-24 22:17:02 -0300
commitc96b933acc4d9ec7382d451055e44c85959772b9 (patch)
tree4a3aff2749eb0b70b7947ecfc7cd56d56ad4e29d /src
parentbcfc37ea98136c449077baa8d97e2334da20d9fc (diff)
downloadrneovim-c96b933acc4d9ec7382d451055e44c85959772b9.tar.gz
rneovim-c96b933acc4d9ec7382d451055e44c85959772b9.tar.bz2
rneovim-c96b933acc4d9ec7382d451055e44c85959772b9.zip
Improve comments and fix ascii_* attributes
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ascii.h46
-rw-r--r--src/nvim/indent.c3
-rw-r--r--src/nvim/ops.c2
-rw-r--r--src/nvim/search.c4
-rw-r--r--src/nvim/syntax.c5
5 files changed, 33 insertions, 27 deletions
diff --git a/src/nvim/ascii.h b/src/nvim/ascii.h
index 1442b2a50c..cc9d1202c2 100644
--- a/src/nvim/ascii.h
+++ b/src/nvim/ascii.h
@@ -9,7 +9,8 @@
#define NVIM_ASCII_H
#include <stdbool.h>
-#include "func_attr.h"
+
+#include "nvim/func_attr.h"
// Definitions of various common control characters.
@@ -90,32 +91,36 @@
# define PATHSEPSTR "/"
#endif
-static inline bool ascii_iswhite(int c) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST;
-static inline bool ascii_isdigit(int c) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST;
-static inline bool ascii_isxdigit(int c) FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST;
-static inline bool ascii_isspace(int x) 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) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_CONST;
+static inline bool ascii_isxdigit(int) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_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()
-/// because it doesn't include <CR> and <LF> and the like.
+/// Checks if `c` is a space or tab character.
+///
+/// @see {ascii_isdigit}
static inline bool ascii_iswhite(int c)
{
return c == ' ' || c == '\t';
}
-/// Use our own isdigit() replacement, because on MS-Windows isdigit() returns
-/// non-zero for superscript 1. Also avoids that isdigit() crashes for numbers
-/// below 0 and above 255.
+/// Check whether character is a decimal digit.
+///
+/// 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)
{
return c >= '0' && c <= '9';
}
-/// Variant of isxdigit() that can handle characters > 0x100.
-/// We don't use isxdigit() here, because on some systems it also considers
-/// superscript 1 to be a digit.
+/// Checks if `c` is a hexadecimal digit, that is, one of 0-9, a-f, A-F.
///
-/// @param c
-/// @return TRUE if the character is a hexadecimal digit.
+/// @see {ascii_isdigit}
static inline bool ascii_isxdigit(int c)
{
return (c >= '0' && c <= '9')
@@ -123,12 +128,13 @@ static inline bool ascii_isxdigit(int c)
|| (c >= 'A' && c <= 'F');
}
-/// Vim has its own isspace() function, because on some machines isspace()
-/// can't handle characters above 128.
-static inline bool ascii_isspace(int x)
+/// Checks if `c` is a white-space character, that is,
+/// one of \f, \n, \r, \t, \v.
+///
+/// @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 */
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index c1733346fc..d3008185dc 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -706,7 +706,8 @@ int get_lisp_indent(void)
if (vi_lisp || ((*that != '"') && (*that != '\'')
&& (*that != '#') && ((*that < '0') || (*that > '9')))) {
- while (*that && (!ascii_iswhite(*that) || quotecount || parencount)
+ while (*that
+ && (!ascii_iswhite(*that) || quotecount || parencount)
&& (!((*that == '(' || *that == '[')
&& !quotecount && !parencount && vi_lisp))) {
if (*that == '"') {
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index ed320a4851..9ee2edc814 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -3979,8 +3979,6 @@ static int ends_in_white(linenr_T lnum)
if (*s == NUL)
return FALSE;
- /* Don't use STRLEN() inside ascii_iswhite(), SAS/C complains: "macro
- * invocation may call function multiple times". */
l = STRLEN(s) - 1;
return ascii_iswhite(s[l]);
}
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 24e95efb03..d20bd77289 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1023,7 +1023,7 @@ int do_search(
else /* single '+' */
spats[0].off.off = 1;
++p;
- while (ascii_isdigit(*p)) /* skip number */
+ while (ascii_isdigit(*p)) /* skip number */
++p;
}
@@ -2921,7 +2921,7 @@ extend:
*/
if (start_blank) {
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))
decl(&curwin->w_cursor);
} else if (c = gchar_cursor(), !ascii_iswhite(c))
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 7e6e247bba..2df0e72f8f 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -7138,9 +7138,10 @@ int highlight_changed(void)
*/
attr = 0;
bool colon = false;
- for (; *p && *p != ','; ++p) { /* parse upto comma */
- if (ascii_iswhite(*p)) /* ignore white space */
+ for (; *p && *p != ','; ++p) { // parse upto comma
+ if (ascii_iswhite(*p)) { // ignore white space
continue;
+ }
if (colon) /* Combination with ':' is not allowed. */
return FAIL;