#define cv_isprint(c) ((uchar)(c) >= (uchar)' ')
#define cv_isprint_or_tab(c) ((uchar)(c) >= (uchar)' ' || (c) == '\t')
+static inline bool cv_isalnum(char c)
+{
+ return ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
+}
+
+static inline bool cv_isalpha(char c)
+{
+ return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
+}
+
+static inline bool cv_isdigit(char c)
+{
+ return '0' <= c && c <= '9';
+}
+
+static inline bool cv_isspace(char c)
+{
+ return (9 <= c && c <= 13) || c == ' ';
+}
+
static char* icv_itoa( int _val, char* buffer, int /*radix*/ )
{
const int radix = 10;
char* name = name_buf;
// name must start with letter or '_'
- if( !isalpha(*ptr) && *ptr!= '_' ){
+ if( !cv_isalpha(*ptr) && *ptr!= '_' ){
*name++ = '_';
}
while( ptr < ptr2 )
{
char c = *ptr++;
- if( !isalnum(c) && c != '-' && c != '_' )
+ if( !cv_isalnum(c) && c != '-' && c != '_' )
c = '_';
*name++ = c;
}
sprintf( buf, fmt, value );
if( *ptr == '+' || *ptr == '-' )
ptr++;
- for( ; isdigit(*ptr); ptr++ )
+ for( ; cv_isdigit(*ptr); ptr++ )
;
if( *ptr == ',' )
*ptr = '.';
sprintf( buf, fmt, value );
if( *ptr == '+' || *ptr == '-' )
ptr++;
- for( ; isdigit(*ptr); ptr++ )
+ for( ; cv_isdigit(*ptr); ptr++ )
;
if( *ptr == ',' )
*ptr = '.';
*endptr = dot_pos;
}
- if( *endptr == ptr || isalpha(**endptr) )
+ if( *endptr == ptr || cv_isalpha(**endptr) )
icvProcessSpecialDouble( fs, ptr, &fval, endptr );
return fval;
}
}
- if( isdigit(c) ||
- ((c == '-' || c == '+') && (isdigit(d) || d == '.')) ||
- (c == '.' && isalnum(d))) // a number
+ if( cv_isdigit(c) ||
+ ((c == '-' || c == '+') && (cv_isdigit(d) || d == '.')) ||
+ (c == '.' && cv_isalnum(d))) // a number
{
double fval;
int ival;
endptr = ptr + (c == '-' || c == '+');
- while( isdigit(*endptr) )
+ while( cv_isdigit(*endptr) )
endptr++;
if( *endptr == '.' || *endptr == 'e' )
{
force_real:
fval = icv_strtod( fs, ptr, &endptr );
- /*if( endptr == ptr || isalpha(*endptr) )
+ /*if( endptr == ptr || cv_isalpha(*endptr) )
icvProcessSpecialDouble( fs, endptr, &fval, &endptr ));*/
node->tag = CV_NODE_REAL;
for( len = 0; len < CV_FS_MAX_LEN; )
{
c = *++ptr;
- if( isalnum(c) || (c != '\'' && cv_isprint(c)))
+ if( cv_isalnum(c) || (c != '\'' && cv_isprint(c)))
buf[len++] = c;
else if( c == '\'' )
{
for( len = 0; len < CV_FS_MAX_LEN; )
{
c = *++ptr;
- if( isalnum(c) || (c != '\\' && c != '\"' && cv_isprint(c)))
+ if( cv_isalnum(c) || (c != '\\' && c != '\"' && cv_isprint(c)))
buf[len++] = c;
else if( c == '\"' )
{
buf[len++] = '\r';
else if( d == 't' )
buf[len++] = '\t';
- else if( d == 'x' || (isdigit(d) && d < '8') )
+ else if( d == 'x' || (cv_isdigit(d) && d < '8') )
{
int val, is_hex = d == 'x';
c = ptr[3];
else if( is_first )
break;
}
- else if( isalnum(*ptr) || *ptr=='_')
+ else if( cv_isalnum(*ptr) || *ptr=='_')
{
if( !is_first )
CV_PARSE_ERROR( "The YAML streams must start with '---', except the first one" );
if( key )
{
- if( !isalpha(key[0]) && key[0] != '_' )
+ if( !cv_isalpha(key[0]) && key[0] != '_' )
CV_Error( CV_StsBadArg, "Key must start with a letter or _" );
ptr = icvFSResizeWriteBuffer( fs, ptr, keylen );
int c = key[i];
ptr[i] = (char)c;
- if( !isalnum(c) && c != '-' && c != '_' && c != ' ' )
+ if( !cv_isalnum(c) && c != '-' && c != '_' && c != ' ' )
CV_Error( CV_StsBadArg, "Key names may only contain alphanumeric characters [a-zA-Z0-9], '-', '_' and ' '" );
}
{
char c = str[i];
- if( !need_quote && !isalnum(c) && c != '_' && c != ' ' && c != '-' &&
+ if( !need_quote && !cv_isalnum(c) && c != '_' && c != ' ' && c != '-' &&
c != '(' && c != ')' && c != '/' && c != '+' && c != ';' )
need_quote = 1;
- if( !isalnum(c) && (!cv_isprint(c) || c == '\\' || c == '\'' || c == '\"') )
+ if( !cv_isalnum(c) && (!cv_isprint(c) || c == '\\' || c == '\'' || c == '\"') )
{
*data++ = '\\';
if( cv_isprint(c) )
else
*data++ = c;
}
- if( !need_quote && (isdigit(str[0]) ||
+ if( !need_quote && (cv_isdigit(str[0]) ||
str[0] == '+' || str[0] == '-' || str[0] == '.' ))
need_quote = 1;
char c = *ptr, d;
char* endptr;
- if( isspace(c) || c == '\0' || (c == '<' && ptr[1] == '!' && ptr[2] == '-') )
+ if( cv_isspace(c) || c == '\0' || (c == '<' && ptr[1] == '!' && ptr[2] == '-') )
{
ptr = icvXMLSkipSpaces( fs, ptr, 0 );
have_space = 1;
}
if( value_type != CV_NODE_STRING &&
- (isdigit(c) || ((c == '-' || c == '+') &&
- (isdigit(d) || d == '.')) || (c == '.' && isalnum(d))) ) // a number
+ (cv_isdigit(c) || ((c == '-' || c == '+') &&
+ (cv_isdigit(d) || d == '.')) || (c == '.' && cv_isalnum(d))) ) // a number
{
double fval;
int ival;
endptr = ptr + (c == '-' || c == '+');
- while( isdigit(*endptr) )
+ while( cv_isdigit(*endptr) )
endptr++;
if( *endptr == '.' || *endptr == 'e' )
{
fval = icv_strtod( fs, ptr, &endptr );
- /*if( endptr == ptr || isalpha(*endptr) )
+ /*if( endptr == ptr || cv_isalpha(*endptr) )
icvProcessSpecialDouble( fs, ptr, &fval, &endptr ));*/
elem->tag = CV_NODE_REAL;
elem->data.f = fval;
for( ;; )
{
c = *++ptr;
- if( !isalnum(c) )
+ if( !cv_isalnum(c) )
{
if( c == '\"' )
{
++ptr;
break;
}
- else if( !cv_isprint(c) || c == '<' || (!is_quoted && isspace(c)))
+ else if( !cv_isprint(c) || c == '<' || (!is_quoted && cv_isspace(c)))
{
if( is_quoted )
CV_PARSE_ERROR( "Closing \" is expected" );
{
endptr = ptr;
do c = *++endptr;
- while( isalnum(c) );
+ while( cv_isalnum(c) );
if( c != ';' )
CV_PARSE_ERROR( "Invalid character in the symbol entity name" );
len = (int)(endptr - ptr);
CV_PARSE_ERROR( "Tag should start with \'<\'" );
ptr++;
- if( isalnum(*ptr) || *ptr == '_' )
+ if( cv_isalnum(*ptr) || *ptr == '_' )
tag_type = CV_XML_OPENING_TAG;
else if( *ptr == '/' )
{
{
CvStringHashNode* attrname;
- if( !isalpha(*ptr) && *ptr != '_' )
+ if( !cv_isalpha(*ptr) && *ptr != '_' )
CV_PARSE_ERROR( "Name should start with a letter or underscore" );
endptr = ptr - 1;
do c = *++endptr;
- while( isalnum(c) || c == '_' || c == '-' );
+ while( cv_isalnum(c) || c == '_' || c == '-' );
attrname = cvGetHashedKey( fs, ptr, (int)(endptr - ptr), 1 );
ptr = endptr;
}
c = *ptr;
- have_space = isspace(c) || c == '\0';
+ have_space = cv_isspace(c) || c == '\0';
if( c != '>' )
{
*ptr++ = '/';
}
- if( !isalpha(key[0]) && key[0] != '_' )
+ if( !cv_isalpha(key[0]) && key[0] != '_' )
CV_Error( CV_StsBadArg, "Key should start with a letter or _" );
ptr = icvFSResizeWriteBuffer( fs, ptr, len );
for( i = 0; i < len; i++ )
{
char c = key[i];
- if( !isalnum(c) && c != '_' && c != '-' )
+ if( !cv_isalnum(c) && c != '_' && c != '-' )
CV_Error( CV_StsBadArg, "Key name may only contain alphanumeric characters [a-zA-Z0-9], '-' and '_'" );
ptr[i] = c;
}
else
*data++ = c;
}
- if( !need_quote && (isdigit(str[0]) ||
+ if( !need_quote && (cv_isdigit(str[0]) ||
str[0] == '+' || str[0] == '-' || str[0] == '.' ))
need_quote = 1;
char compression = '\0';
if( dot_pos && dot_pos[1] == 'g' && dot_pos[2] == 'z' &&
- (dot_pos[3] == '\0' || (isdigit(dot_pos[3]) && dot_pos[4] == '\0')) )
+ (dot_pos[3] == '\0' || (cv_isdigit(dot_pos[3]) && dot_pos[4] == '\0')) )
{
if( append )
CV_Error(CV_StsNotImplemented, "Appending data to compressed file is not implemented" );
{
char c = dt[k];
- if( isdigit(c) )
+ if( cv_isdigit(c) )
{
int count = c - '0';
- if( isdigit(dt[k+1]) )
+ if( cv_isdigit(dt[k+1]) )
{
char* endptr = 0;
count = (int)strtol( dt+k, &endptr, 10 );
flags = CV_SEQ_MAGIC_VAL;
- if( isdigit(flags_str[0]) )
+ if( cv_isdigit(flags_str[0]) )
{
const int OLD_SEQ_ELTYPE_BITS = 9;
const int OLD_SEQ_ELTYPE_MASK = (1 << OLD_SEQ_ELTYPE_BITS) - 1;
edge_items_per_elem += fmt_pairs[i];
if( edge_dt[2] == 'f' || (edge_dt[2] == '1' && edge_dt[3] == 'f') )
- dst_edge_dt = edge_dt + 3 + isdigit(edge_dt[2]);
+ dst_edge_dt = edge_dt + 3 + cv_isdigit(edge_dt[2]);
else
{
int val = (int)strtol( edge_dt + 2, &endptr, 10 );
"(is_instance, release, read or write) are NULL");
c = _info->type_name[0];
- if( !isalpha(c) && c != '_' )
+ if( !cv_isalpha(c) && c != '_' )
CV_Error( CV_StsBadArg, "Type name should start with a letter or _" );
len = (int)strlen(_info->type_name);
for( i = 0; i < len; i++ )
{
c = _info->type_name[i];
- if( !isalnum(c) && c != '-' && c != '_' )
+ if( !cv_isalnum(c) && c != '-' && c != '_' )
CV_Error( CV_StsBadArg,
"Type name should contain only letters, digits, - and _" );
}
{
const char* dt = fmt.c_str();
cn = 1;
- if( isdigit(dt[0]) )
+ if( cv_isdigit(dt[0]) )
{
cn = dt[0] - '0';
dt++;
}
else if( fs.state == NAME_EXPECTED + INSIDE_MAP )
{
- if( !isalpha(*_str) )
+ if( !cv_isalpha(*_str) )
CV_Error_( CV_StsError, ("Incorrect element name %s", _str) );
fs.elname = str;
fs.state = VALUE_EXPECTED + INSIDE_MAP;