Esempio n. 1
0
static void _int_put_keyword_x()
{
	DWORD xhex;

	patn++;
	
	if(!_isxdigit(*patn)) {
		return; // error
	}

	xhex = _to_xdigit(*patn++);
	if(_isxdigit(*patn)) {
		xhex = xhex << 4 | _to_xdigit(*patn++);
	} else {
		_internal_regex_put(xhex, _REGEX_XHEX);
		return;
	}
	if(_isxdigit(*patn)) {
		xhex = xhex << 4 | _to_xdigit(*patn++);
	} else {
		_internal_regex_put(xhex, _REGEX_XHEX);
		return;
	}
	if(_isxdigit(*patn)) {
		xhex = xhex << 4 | _to_xdigit(*patn++);
	}
	_internal_regex_put(xhex, _REGEX_UHEX);
}
Esempio n. 2
0
int isxdigit(int c) {
#if !CAM_DRYOS
    return _isxdigit(c);
#else
    return _ctype(c,(_X|_D));
#endif
}
Esempio n. 3
0
static int
unescape(gh_buf *ob, const uint8_t *src, size_t size, bool unescape_plus)
{
	size_t  i = 0, org;

	while (i < size) {
		org = i;
		while (i < size && src[i] != '%' && src[i] != '+')
			i++;

		if (likely(i > org)) {
			if (unlikely(org == 0)) {
				if (i >= size)
					return 0;

				gh_buf_grow(ob, HOUDINI_UNESCAPED_SIZE(size));
			}

			gh_buf_put(ob, src + org, i - org);
		}

		/* escaping */
		if (i >= size)
			break;

		if (src[i++] == '+') {
			gh_buf_putc(ob, unescape_plus ? ' ' : '+');
			continue;
		}

		if (i + 1 < size && _isxdigit(src[i]) && _isxdigit(src[i + 1])) {
			unsigned char new_char = (hex2c(src[i]) << 4) + hex2c(src[i + 1]);
			gh_buf_putc(ob, new_char);
			i += 2;
		} else {
			gh_buf_putc(ob, '%');
		}
	}

	return 1;
}
Esempio n. 4
0
int _to_xdigit(
	int ch
	)
{
	int ret;

	if (_isdigit(ch))
		ret = ch - '0';
	else if (_isxdigit(ch))
		ret = _to_lower(ch) - 'a' + 0xa;

	return ret;
}
Esempio n. 5
0
static size_t
unescape_ent(struct buf *ob, const uint8_t *src, size_t size)
{
	size_t i = 0;

	if (size > 3 && src[0] == '#') {
		int codepoint = 0;

		if (_isdigit(src[1])) {
			for (i = 1; i < size && _isdigit(src[i]); ++i)
				codepoint = (codepoint * 10) + (src[i] - '0');
		}

		else if (src[1] == 'x' || src[1] == 'X') {
			for (i = 2; i < size && _isxdigit(src[i]); ++i)
				codepoint = (codepoint * 16) + ((src[i] | 32) % 39 - 9);
		}

		if (i < size && src[i] == ';') {
			bufput_utf8(ob, codepoint);
			return i + 1;
		}
	}

	else {
		if (size > MAX_WORD_LENGTH)
			size = MAX_WORD_LENGTH;

		for (i = MIN_WORD_LENGTH; i < size; ++i) {
			if (src[i] == ' ')
				break;

			if (src[i] == ';') {
				const struct html_ent *entity = find_entity((char *)src, i);

				if (entity != NULL) {
					bufput(ob, entity->utf8, entity->utf8_len);
					return i + 1;
				}

				break;
			}
		}
	}

	bufputc(ob, '&');
	return 0;
}
Esempio n. 6
0
static size_t unescape_entity(lanli_buffer *ob, const uint8_t *data, size_t size) {
  size_t i = 0;

  if (size > 3 && data[0] == '#') {
    int codepoint = 0;

    if (_isdigit(data[1])) {
      for (i = 1; i < size && _isdigit(data[i]); ++i)
        codepoint = (codepoint * 10) + (data[i] - '0');
    }

    else if (data[1] == 'x' || data[1] == 'X') {
      for (i = 2; i < size && _isxdigit(data[i]); ++i)
        codepoint = (codepoint * 16) + ((data[i] | 32) % 39 - 9);
      if (i == 2) return 0;
    }

    if (i < size && data[i] == ';') {
      lanli_buffer_put_utf8(ob, codepoint);
      return i + 1;
    }
  }

  else {
    if (size > MAX_WORD_LENGTH)
      size = MAX_WORD_LENGTH;

    for (i = MIN_WORD_LENGTH; i < size; ++i) {
      if (data[i] == ' ')
        break;

      if (data[i] == ';') {
        const struct html_entity *entity = find_entity((const char *)data, i);

        if (entity != NULL) {
          lanli_buffer_put(ob, entity->utf8, entity->size);
          return i + 1;
        }

        break;
      }
    }
  }

  lanli_buffer_putc(ob, '&');
  return 0;
}
Esempio n. 7
0
int _isnxdigit(
	int ch
	)
{
	return !_isxdigit(ch);
}
Esempio n. 8
0
size_t
houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src, size_t size)
{
	size_t i = 0;

	if (size >= 3 && src[0] == '#') {
		int codepoint  = 0;
		int num_digits = 0;

		if (_isdigit(src[1])) {
			for (i = 1; i < size && _isdigit(src[i]); ++i) {
				codepoint = (codepoint * 10) + (src[i] - '0');

				if (codepoint >= 0x110000) {
					// Keep counting digits but
					// avoid integer overflow.
					codepoint = 0x110000;
				}
			}

			num_digits = i - 1;
		}

		else if (src[1] == 'x' || src[1] == 'X') {
			for (i = 2; i < size && _isxdigit(src[i]); ++i) {
				codepoint = (codepoint * 16) + ((src[i] | 32) % 39 - 9);

				if (codepoint >= 0x110000) {
					// Keep counting digits but
					// avoid integer overflow.
					codepoint = 0x110000;
				}
			}

			num_digits = i - 2;
		}

		if (num_digits >= 1 && num_digits <= 8 &&
		    i < size && src[i] == ';') {
			if (codepoint == 0 ||
			    (codepoint >= 0xD800 && codepoint < 0xE000) ||
			    codepoint >= 0x110000) {
				codepoint = 0xFFFD;
			}
			utf8proc_encode_char(codepoint, ob);
			return i + 1;
		}
	}

	else {
		if (size > MAX_WORD_LENGTH)
			size = MAX_WORD_LENGTH;

		for (i = MIN_WORD_LENGTH; i < size; ++i) {
			if (src[i] == ' ')
				break;

			if (src[i] == ';') {
				const struct html_ent *entity = find_entity((char *)src, i);

				if (entity != NULL) {
					int len = 0;
					while (len < 4 && entity->utf8[len] != '\0') {
						++len;
					}
					cmark_strbuf_put(ob, entity->utf8, len);
					return i + 1;
				}

				break;
			}
		}
	}

	return 0;
}
Esempio n. 9
0
_CODE_ACCESS int isxdigit(int c)
{
    return(_isxdigit(c));
}
Esempio n. 10
0
int isxdigit(int c) {
	return _isxdigit(c);
}
Esempio n. 11
0
_CODE_ACCESS unsigned long strtoul(const char *st, char **endptr, int base)
{
    register unsigned long result = 0;
    register char          cp;
    register const char   *fst = st;
    int                    digits = 0;
    int                    minus = 0;

    while (_isspace(*fst)) ++fst;  /* SKIP WHITE SPACE */
    if (base > 36) base = 0;  

    if ((cp = *fst) == '+') cp = *++fst;
    else if ((cp = *fst) == '-') { cp = *++fst; minus = 1; }

    /*-------------------------------------------------------------------*/
    /* DETERMINE BASE IF ZERO BASE ASKED FOR.                            */
    /*-------------------------------------------------------------------*/
    switch (base)
    {
	case  0 : if      (cp != '0')           base = 10;
		  else if ((cp = *++fst) == 'x' || cp == 'X')
		     if   (_isxdigit(fst[1])) { base = 16; cp = *++fst; }
		     else                     { base = 10; cp = *--fst; }
		  else 
		  {
		     base = 8; 
		     if (cp < '0' || cp > '7')  cp = *--fst;
		  }
	          break;

        case 16 : if (cp == '0' && ((fst[1] == 'x') || (fst[1] == 'X')) &&
		      _isxdigit(fst[2]))
	             cp = *(fst += 2);
    }

    /*-------------------------------------------------------------------*/
    /* CONVERT THE NUMBER USING THE SPECIFIED BASE.                      */
    /*-------------------------------------------------------------------*/
    for (;; cp = *++fst)
    {
	register unsigned long addval;

	if (!((_isdigit(cp) && (addval = cp - '0')      < base) ||
	      (_isupper(cp) && (addval = cp - 'A' + 10) < base) ||
	      (_islower(cp) && (addval = cp - 'a' + 10) < base)))  break;

        if (result == (addval = (result * base + addval))/base) result = addval;
	else 
	{   
	    errno = ERANGE;
	    if (endptr) *endptr = (char *)st;        
	    return ULONG_MAX; 
	}

	digits++;
    }

    /*-------------------------------------------------------------------*/
    /* MARK THE END OF THE CONVERTED INPUT.                              */
    /*-------------------------------------------------------------------*/
    if (endptr) *endptr = (char *)(digits ? fst : st);

    return minus ? -result : result;
}
Esempio n. 12
0
_CODE_ACCESS int iswxdigit(wint_t c)
   { return (c == WEOF || (char)c != c) ? 0 : _isxdigit((char)c); }
Esempio n. 13
0
_CODE_ACCESS long long strtoll(const char *st, char **endptr, int base)
{
    register unsigned long long   result = 0;
    register unsigned int         uns_base;
    register char                 cp;
    register const char          *fst    = st;
    int                           digits = 0;
    unsigned long long            sign = 0;
    unsigned long long            max_prev_result;
    unsigned long long            max_curr_addval;
    unsigned long long            range_limit;

    while (_isspace(*fst)) ++fst;  /* SKIP WHITE SPACE */

    if ((cp = *fst) == '-')
    {
       sign = 1;
       cp = *++fst;
    }
    else if (cp == '+') cp = *++fst;

    if (base > 36) base = 0;

    /*-------------------------------------------------------------------*/
    /* DETERMINE BASE IF ZERO BASE ASKED FOR.                            */
    /*-------------------------------------------------------------------*/
    switch (base)
    {
	case  0 : if      (cp != '0')           base = 10;
		  else if ((cp = *++fst) == 'x' || cp == 'X')
		     if   (_isxdigit(fst[1])) { base = 16; cp = *++fst; }
		     else                     { base = 10; cp = *--fst; }
		  else 
		  {
		     base = 8; 
		     if (cp < '0' || cp > '7')  cp = *--fst;
		  } 
	          break;

        case 16 : if (cp == '0' && ((fst[1] == 'x') || (fst[1] == 'X')) &&
		      _isxdigit(fst[2]))
	             cp = *(fst += 2);
     }

    /*-------------------------------------------------------------------*/
    /* DETERMINE VALUES NEEDED TO DETECT RANGE ERROR.  THE MAX UNSIGNED  */
    /* VALUE THAT IS IN RANGE IS BASED ON THE SIGN OF THE INPUT STRING:  */
    /*   sign == 1 - RESULT WILL BE NEGATIVE, SO MUST BE <= LLONG_MAX+1  */
    /*   sign == 0 - RESULT WILL BE POSITIVE, SO MUST BE <= LLONG_MAX    */
    /* SO range_limit is LLONG_MAX + sign.                               */
    /*                                                                   */
    /* ALSO NEED max_prev_result AND max_curr_addval WHERE:              */
    /*    max_prev_result * uns_base + max_curr_addval == range_limit    */
    /*                                                                   */
    /* THIS ALLOWS US TO TEST FOR RANGE ERROR BEFORE WE COMPUTE THE NEXT */
    /* RESULT.  WE HAVE TWO CASES:                                       */
    /*  - PREVIOUS result IS GREATER THAN max_prev_result, SO NEXT       */
    /*    RESULT MUST BE OUT OF RANGE.                                   */
    /*  - PREVIOUS result IS EQUAL TO max_prev_result, SO NEXT RESULT    */
    /*    IS OUT OF RANGE IF addval >  max_curr_addval.                  */
    /*-------------------------------------------------------------------*/
    uns_base = (unsigned int) base;
    range_limit = (unsigned long long)LLONG_MAX + sign;
    max_prev_result = range_limit / uns_base;
    max_curr_addval = range_limit % uns_base;

    /*-------------------------------------------------------------------*/
    /* CONVERT THE NUMBER USING THE SPECIFIED BASE.                      */
    /*-------------------------------------------------------------------*/
    for (;; cp = *++fst)
    {
	register unsigned long long addval;

	if (!((_isdigit(cp) && (addval = cp - '0')      < uns_base) ||
	      (_isupper(cp) && (addval = cp - 'A' + 10) < uns_base) ||
	      (_islower(cp) && (addval = cp - 'a' + 10) < uns_base)))  break;

        /*--------------------------------------------------------------*/
        /* CHECK OVERFLOW STATUS BEFORE COMPUTATION.                    */
        /* result CONTAINS THE RESULT OF THE PREVIOUS COMPUTATION       */
        /*--------------------------------------------------------------*/
        if (result > max_prev_result ||
            (result == max_prev_result && addval > max_curr_addval))
        {
           /* SET ERRNO   */
            errno = ERANGE;
            if (endptr) *endptr = (char *)st;
            return sign ? LLONG_MIN : LLONG_MAX;
        }

        /*--------------------------------------------------------------*/
        /* COMPUTE NEXT RESULT.                                         */
        /*--------------------------------------------------------------*/
        result = result * uns_base + addval;

	digits++;
    }

    /*-------------------------------------------------------------------*/
    /* MARK THE END OF THE CONVERTED INPUT.  NEGATE THE RESULT IF A      */
    /* MINUS SIGN WAS SEEN.                                              */
    /*-------------------------------------------------------------------*/
    if (endptr) *endptr = (char *)(digits ? fst : st);
    if (sign)
        return (long long)-result;

    return (long long)result;
}