Exemple #1
0
/*
 * This function behaves exactly like rxStr2Number(), except it is for 32-bit
 * numbers, and ERANGE can differentiate between a valid ULONG_MAX and an error
 * return.
 */
bool rxStr2Number32(RexxMethodContext *c, CSTRING str, uint32_t *number, size_t pos)
{
    char *end;
    *number = strtoul(str, &end, 0);
    if ( (end - str != strlen(str)) || errno == ERANGE )
    {
        invalidTypeException(c->threadContext, pos, " number");
        return false;
    }
    return true;
}
Exemple #2
0
/**
 * Converts a string representing a number into an unsigned 64 bit number and
 * raises an exception if the conversion fails.
 *
 * The string must have a format of 123456789 or 0xFFAB. A leading 0 without the
 * following X will cause the string to be interpreted as an octal number, which
 * may or may not trigger a failure.  It is not the intent that this function be
 * used for octal numbers.
 *
 * Note that it is the use of 0 as the third argument that allows _strtoui64()
 * to interpret the string as decimal or hexadecimal based.
 *
 * @param c       Method context we are operating in.
 * @param str     String to convert.
 * @param number  [OUT]  Converted number is returned here.
 * @param pos     Argument position.  Used for exception.
 *
 * @return True if the number was converted, false if an exceptions is raised.
 *
 * @note  There is no way to tell the difference between a valid _UI64_MAX
 *        number and an error.  The function simply assumes a return of
 *        _UI64_MAX is an error signal.
 */
bool rxStr2Number(RexxMethodContext *c, CSTRING str, uint64_t *number, size_t pos)
{
    char *end;
    *number = _strtoui64(str, &end, 0);
    if ( (end - str != strlen(str)) || errno == EINVAL || *number == _UI64_MAX )
    {
        invalidTypeException(c->threadContext, pos, " number");
        return false;
    }
    return true;
}
Exemple #3
0
/**
 * Translate a keyword to its equivalent numeric value.
 *
 * @param  symbol  The keyword to translate.
 *
 * @return  The numeric value for symbol on success, (int)value == -1 on
 *          failure.
 */
static uint32_t winKeyword2ID(CSTRING symbol, RexxThreadContext *c, int pos, CSTRING type)
{
    static String2Int *winConstantsMap = NULL;

    if ( winConstantsMap == NULL )
    {
        winConstantsMap = winCommonInitMap();
    }

    int id = getKeywordValue(winConstantsMap, symbol);
    if ( id == -1 )
    {
        invalidTypeException(c, pos, type);
    }
    return (uint32_t)id;
}