Beispiel #1
0
bool g_CheckAlphabet(const string& str, const CTempString& param_name,
        ECharacterClass char_class, char* bad_char)
{
    const char* ch = str.data();
    size_t len = str.length();

    switch (char_class) {
    case eCC_Alphabetic:
        for (; len > 0; ++ch, --len)
            if (NOT_ALPHA(*ch))
                break;
        break;

    case eCC_Alphanumeric:
        for (; len > 0; ++ch, --len)
            if (NOT_ALPHA(*ch) && NOT_DIGIT(*ch))
                break;
        break;

    case eCC_StrictId:
        for (; len > 0; ++ch, --len)
            if (NOT_ALPHA(*ch) && NOT_DIGIT(*ch) && *ch != '_')
                break;
        break;

    case eCC_BASE64URL:
        for (; len > 0; ++ch, --len)
            if (NOT_ALPHA(*ch) && NOT_DIGIT(*ch) && *ch != '_' && *ch != '-')
                break;
        break;

    case eCC_BASE64_PI:
        for (; len > 0; ++ch, --len)
            if (NOT_ALPHA(*ch) && NOT_DIGIT(*ch) && *ch != '_' && *ch != '.')
                break;
        break;

    case eCC_RelaxedId:
        for (; len > 0; ++ch, --len)
            if (NOT_ALPHA(*ch) && NOT_DIGIT(*ch) && *ch != '_' &&
                    *ch != '-' && *ch != '.' && *ch != ':' &&
                    *ch != '@' && *ch != '|')
                break;
        break;
    }

    if (len != 0) {
        *bad_char = *ch;
        return false;
    }

    return true;
}
Beispiel #2
0
double bb_strtod(const char *arg, char **endp)
{
	double v;
	char *endptr;

	if (arg[0] != '-' && NOT_DIGIT(arg[0])) goto err;
	errno = 0;
	v = strtod(arg, &endptr);
	if (endp) *endp = endptr;
	if (endptr[0]) {
		/* "1234abcg" or out-of-range? */
		if (isalnum(endptr[0]) || errno) {
 err:
			errno = ERANGE;
			return HUGE_VAL;
		}
		/* good number, just suspicious terminator */
		errno = EINVAL;
	}
	return v;
}
double FAST_FUNC bb_strtod(const char *arg, char **endp)
{
	double v;
	char *endptr;

	/* Allow .NN form. People want to use "sleep .15" etc */
	if (arg[0] != '-' && arg[0] != '.' && NOT_DIGIT(arg[0]))
		goto err;
	errno = 0;
	v = strtod(arg, &endptr);
	if (endp)
		*endp = endptr;
	if (endptr[0]) {
		/* "1234abcg" or out-of-range? */
		if (isalnum(endptr[0]) || errno) {
 err:
			errno = ERANGE;
			return HUGE_VAL;
		}
		/* good number, just suspicious terminator */
		errno = EINVAL;
	}
	return v;
}