1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

curl_ctype: private is*() type macros and functions

... since the libc provided one are locale dependent in a way we don't
want. Also, the "native" isalnum() (for example) works differently on
different platforms which caused test 1307 failures on macos only.

Closes #2269
This commit is contained in:
Daniel Stenberg 2018-01-29 00:58:59 +01:00
parent 93836e2ba0
commit 4272a0b0fc
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
7 changed files with 176 additions and 38 deletions

View File

@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
# Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@ -54,7 +54,7 @@ LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
http_ntlm.c curl_ntlm_wb.c curl_ntlm_core.c curl_sasl.c rand.c \
curl_multibyte.c hostcheck.c conncache.c pipeline.c dotdot.c \
x509asn1.c http2.c smb.c curl_endian.c curl_des.c system_win32.c \
mime.c sha256.c setopt.c curl_path.c
mime.c sha256.c setopt.c curl_path.c curl_ctype.c
LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h if2ip.h \
@ -74,7 +74,7 @@ LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
curl_setup_once.h multihandle.h setup-vms.h pipeline.h dotdot.h \
x509asn1.h http2.h sigpipe.h smb.h curl_endian.h curl_des.h \
curl_printf.h system_win32.h rand.h mime.h curl_sha256.h setopt.h \
curl_path.h
curl_path.h curl_ctype.h
LIB_RCFILES = libcurl.rc

114
lib/curl_ctype.c Normal file
View File

@ -0,0 +1,114 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curl_setup.h"
#define _U (1<<0) /* upper case */
#define _L (1<<1) /* lower case */
#define _N (1<<2) /* decimal numerical digit */
#define _S (1<<3) /* space */
#define _P (1<<4) /* punctuation */
#define _C (1<<5) /* control */
#define _X (1<<6) /* hexadecimal letter */
#define _B (1<<7) /* blank */
static const unsigned char ascii[128] = {
_C, _C, _C, _C, _C, _C, _C, _C,
_C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
_C, _C, _C, _C, _C, _C, _C, _C,
_C, _C, _C, _C, _C, _C, _C, _C,
_S|_B, _P, _P, _P, _P, _P, _P, _P,
_P, _P, _P, _P, _P, _P, _P, _P,
_N, _N, _N, _N, _N, _N, _N, _N,
_N, _N, _P, _P, _P, _P, _P, _P,
_P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
_U, _U, _U, _U, _U, _U, _U, _U,
_U, _U, _U, _U, _U, _U, _U, _U,
_U, _U, _U, _P, _P, _P, _P, _P,
_P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
_L, _L, _L, _L, _L, _L, _L, _L,
_L, _L, _L, _L, _L, _L, _L, _L,
_L, _L, _L, _P, _P, _P, _P, _C
};
int Curl_isspace(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & _S);
}
int Curl_isdigit(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & _N);
}
int Curl_isalnum(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & (_N|_U|_L));
}
int Curl_isxdigit(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & (_N|_X));
}
int Curl_isgraph(int c)
{
if((c < 0) || (c >= 0x80) || (c == ' '))
return FALSE;
return (ascii[c] & (_N|_X|_U|_L|_P|_S));
}
int Curl_isprint(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & (_N|_X|_U|_L|_P|_S));
}
int Curl_isalpha(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & (_U|_L));
}
int Curl_isupper(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & (_U));
}
int Curl_islower(int c)
{
if((c < 0) || (c >= 0x80))
return FALSE;
return (ascii[c] & (_L));
}

48
lib/curl_ctype.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef HEADER_CURL_CTYPE_H
#define HEADER_CURL_CTYPE_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
int Curl_isspace(int c);
int Curl_isdigit(int c);
int Curl_isalnum(int c);
int Curl_isxdigit(int c);
int Curl_isgraph(int c);
int Curl_isprint(int c);
int Curl_isalpha(int c);
int Curl_isupper(int c);
int Curl_islower(int c);
#define ISSPACE(x) (Curl_isspace((int) ((unsigned char)x)))
#define ISDIGIT(x) (Curl_isdigit((int) ((unsigned char)x)))
#define ISALNUM(x) (Curl_isalnum((int) ((unsigned char)x)))
#define ISXDIGIT(x) (Curl_isxdigit((int) ((unsigned char)x)))
#define ISGRAPH(x) (Curl_isgraph((int) ((unsigned char)x)))
#define ISALPHA(x) (Curl_isalpha((int) ((unsigned char)x)))
#define ISPRINT(x) (Curl_isprint((int) ((unsigned char)x)))
#define ISUPPER(x) (Curl_isupper((int) ((unsigned char)x)))
#define ISLOWER(x) (Curl_islower((int) ((unsigned char)x)))
#define ISASCII(x) (((x) >= 0) && ((x) <= 0x80))
#define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
(((unsigned char)x) == '\t'))
#endif /* HEADER_CURL_CTYPE_H */

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -101,7 +101,6 @@
# endif
#endif
/*
* Definition of timeval struct for platforms that don't have it.
*/
@ -274,25 +273,6 @@ struct timeval {
# define sfcntl fcntl
#endif
/*
* Uppercase macro versions of ANSI/ISO is*() functions/macros which
* avoid negative number inputs with argument byte codes > 127.
*/
#define ISSPACE(x) (isspace((int) ((unsigned char)x)))
#define ISDIGIT(x) (isdigit((int) ((unsigned char)x)))
#define ISALNUM(x) (isalnum((int) ((unsigned char)x)))
#define ISXDIGIT(x) (isxdigit((int) ((unsigned char)x)))
#define ISGRAPH(x) (isgraph((int) ((unsigned char)x)))
#define ISALPHA(x) (isalpha((int) ((unsigned char)x)))
#define ISPRINT(x) (isprint((int) ((unsigned char)x)))
#define ISUPPER(x) (isupper((int) ((unsigned char)x)))
#define ISLOWER(x) (islower((int) ((unsigned char)x)))
#define ISASCII(x) (isascii((int) ((unsigned char)x)))
#define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
(((unsigned char)x) == '\t'))
#define TOLOWER(x) (tolower((int) ((unsigned char)x)))
@ -347,6 +327,7 @@ struct timeval {
#define FALSE false
#endif
#include "curl_ctype.h"
/*
* Macro WHILE_FALSE may be used to build single-iteration do-while loops,

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -74,15 +74,6 @@
*/
/* Check for an ASCII hex digit.
We avoid the use of isxdigit to accommodate non-ASCII hosts. */
static bool Curl_isxdigit(char digit)
{
return ( (digit >= 0x30 && digit <= 0x39) /* 0-9 */
|| (digit >= 0x41 && digit <= 0x46) /* A-F */
|| (digit >= 0x61 && digit <= 0x66) /* a-f */) ? TRUE : FALSE;
}
void Curl_httpchunk_init(struct connectdata *conn)
{
struct Curl_chunker *chunk = &conn->chunk;

View File

@ -12,13 +12,15 @@
CURLX_CFILES = \
../lib/strtoofft.c \
../lib/nonblock.c \
../lib/warnless.c
../lib/warnless.c \
../lib/curl_ctype.c
CURLX_HFILES = \
../lib/curl_setup.h \
../lib/strtoofft.h \
../lib/nonblock.h \
../lib/warnless.h
../lib/warnless.h \
../lib/curl_ctype.h
CURL_CFILES = \
slist_wc.c \

View File

@ -4,13 +4,15 @@ CURLX_SRCS = \
../../lib/mprintf.c \
../../lib/nonblock.c \
../../lib/strtoofft.c \
../../lib/warnless.c
../../lib/warnless.c \
../../lib/curl_ctype.c
CURLX_HDRS = \
../../lib/curlx.h \
../../lib/nonblock.h \
../../lib/strtoofft.h \
../../lib/warnless.h
../../lib/warnless.h \
../../lib/curl_ctype.h
USEFUL = \
getpart.c \