Skip to content

Commit

Permalink
Use handcraft locale-insensitive routines.
Browse files Browse the repository at this point in the history
Redo 2256809.
  • Loading branch information
lichray committed Dec 29, 2015
1 parent 4a2eef0 commit 834f889
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
10 changes: 6 additions & 4 deletions common/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ extern KEYLIST keylist[];
* can't use the standard isspace(3) macro because it returns true for
* characters like ^K in the ASCII character set. The POSIX isblank(3)
* has the same problem for non-ASCII locale, so we need a standalone one.
*
* XXX
* Note side effect, ch is evaluated multiple times.
*/
#define cmdskip(ch) ((ch) == ' ' || (ch) == '\t')

static __inline int
cmdskip(CHAR_T ch)
{
return ch == L(' ') || ch == L('\t');
}

/* The "standard" tab width, for displaying things to users. */
#define STANDARD_TAB 6
Expand Down
34 changes: 34 additions & 0 deletions common/multibyte.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,38 @@ typedef char RCHAR_T;

#define SIZE(w) (sizeof(w) / sizeof(*w))

/*
* Locale insensitive character category detection.
*/

static __inline int
isatoz(CHAR_T c)
{
return L('a') <= c && c <= L('z');
}

static __inline int
isAtoZ(CHAR_T c)
{
return L('A') <= c && c <= L('Z');
}

static __inline int
is0to9(CHAR_T c)
{
return L('0') <= c && c <= L('9');
}

static __inline int
isazAZ(CHAR_T c)
{
return isatoz(c) || isAtoZ(c);
}

static __inline int
is09azAZ(CHAR_T c)
{
return is0to9(c) || isazAZ(c);
}

#endif
7 changes: 3 additions & 4 deletions ex/ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "config.h"

#ifndef lint
static const char sccsid[] = "$Id: ex.c,v 10.80 2012/10/03 16:24:40 zy Exp $";
static const char sccsid[] = "$Id: ex.c,v 10.81 2015/12/29 11:30:58 zy Exp $";
#endif /* not lint */

#include <sys/types.h>
Expand Down Expand Up @@ -388,7 +388,7 @@ loop: ecp = SLIST_FIRST(gp->ecq);
} else {
for (p = ecp->cp;
ecp->clen > 0; --ecp->clen, ++ecp->cp)
if (!isascii(*ecp->cp) || !isalpha(*ecp->cp))
if (!isazAZ(*ecp->cp))
break;
if ((namelen = ecp->cp - p) == 0) {
msgq(sp, M_ERR, "080|Unknown command name");
Expand Down Expand Up @@ -732,8 +732,7 @@ skip_srch: if (ecp->cmd == &cmds[C_VISUAL_EX] && F_ISSET(sp, SC_VI))
if (!cmdskip(ecp->cp[0]))
break;

if (!isascii(ecp->cp[0]) ||
isalnum(ecp->cp[0]) || ecp->cp[0] == '|') {
if (is09azAZ(ecp->cp[0]) || ecp->cp[0] == '|') {
ecp->rcmd = cmds[C_SUBSTITUTE];
ecp->rcmd.fn = ex_subagain;
ecp->cmd = &ecp->rcmd;
Expand Down
4 changes: 2 additions & 2 deletions ex/ex_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "config.h"

#ifndef lint
static const char sccsid[] = "$Id: ex_global.c,v 10.32 2011/12/26 23:37:01 zy Exp $";
static const char sccsid[] = "$Id: ex_global.c,v 10.33 2015/12/29 11:30:58 zy Exp $";
#endif /* not lint */

#include <sys/types.h>
Expand Down Expand Up @@ -91,7 +91,7 @@ ex_g_setup(SCR *sp, EXCMD *cmdp, enum which cmd)
if (cmdp->argc == 0)
goto usage;
for (p = cmdp->argv[0]->bp; cmdskip(*p); ++p);
if (!isascii(*p) || *p == '\0' || isalnum(*p) ||
if (*p == '\0' || is09azAZ(*p) ||
*p == '\\' || *p == '|' || *p == '\n') {
usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
return (1);
Expand Down
4 changes: 2 additions & 2 deletions ex/ex_subst.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "config.h"

#ifndef lint
static const char sccsid[] = "$Id: ex_subst.c,v 10.53 2011/12/21 20:40:35 zy Exp $";
static const char sccsid[] = "$Id: ex_subst.c,v 10.54 2015/12/29 11:30:58 zy Exp $";
#endif /* not lint */

#include <sys/types.h>
Expand Down Expand Up @@ -78,7 +78,7 @@ ex_s(SCR *sp, EXCMD *cmdp)
subagain: return (ex_subagain(sp, cmdp));

delim = *p++;
if (!isascii(delim) || isalnum(delim) || delim == '\\')
if (is09azAZ(delim) || delim == '\\')
return (s(sp, cmdp, p, &sp->subre_c, SUB_MUSTSETR));

/*
Expand Down

0 comments on commit 834f889

Please sign in to comment.