comparison src/charset.c @ 16:3ba373b54370 v7.0008

updated for version 7.0008
author vimboss
date Mon, 12 Jul 2004 15:53:54 +0000
parents 3fc0f57ecb91
children 410fa1a31baf
comparison
equal deleted inserted replaced
15:631143ac4a01 16:3ba373b54370
1544 return (*p == NUL || *p == '\r' || *p == '\n'); 1544 return (*p == NUL || *p == '\r' || *p == '\n');
1545 } 1545 }
1546 1546
1547 /* 1547 /*
1548 * Convert a string into a long and/or unsigned long, taking care of 1548 * Convert a string into a long and/or unsigned long, taking care of
1549 * hexadecimal and octal numbers. 1549 * hexadecimal and octal numbers. Accepts a '-' sign.
1550 * If "hexp" is not NULL, returns a flag to indicate the type of the number: 1550 * If "hexp" is not NULL, returns a flag to indicate the type of the number:
1551 * 0 decimal 1551 * 0 decimal
1552 * '0' octal 1552 * '0' octal
1553 * 'X' hex 1553 * 'X' hex
1554 * 'x' hex 1554 * 'x' hex
1568 unsigned long *unptr; /* return: unsigned result */ 1568 unsigned long *unptr; /* return: unsigned result */
1569 { 1569 {
1570 char_u *ptr = start; 1570 char_u *ptr = start;
1571 int hex = 0; /* default is decimal */ 1571 int hex = 0; /* default is decimal */
1572 int negative = FALSE; 1572 int negative = FALSE;
1573 long n = 0;
1574 unsigned long un = 0; 1573 unsigned long un = 0;
1575 1574
1576 if (ptr[0] == '-') 1575 if (ptr[0] == '-')
1577 { 1576 {
1578 negative = TRUE; 1577 negative = TRUE;
1601 if (hex == '0') 1600 if (hex == '0')
1602 { 1601 {
1603 /* octal */ 1602 /* octal */
1604 while ('0' <= *ptr && *ptr <= '7') 1603 while ('0' <= *ptr && *ptr <= '7')
1605 { 1604 {
1606 n = 8 * n + (long)(*ptr - '0');
1607 un = 8 * un + (unsigned long)(*ptr - '0'); 1605 un = 8 * un + (unsigned long)(*ptr - '0');
1608 ++ptr; 1606 ++ptr;
1609 } 1607 }
1610 } 1608 }
1611 else 1609 else
1612 { 1610 {
1613 /* hex */ 1611 /* hex */
1614 while (vim_isxdigit(*ptr)) 1612 while (vim_isxdigit(*ptr))
1615 { 1613 {
1616 n = 16 * n + (long)hex2nr(*ptr);
1617 un = 16 * un + (unsigned long)hex2nr(*ptr); 1614 un = 16 * un + (unsigned long)hex2nr(*ptr);
1618 ++ptr; 1615 ++ptr;
1619 } 1616 }
1620 } 1617 }
1621 } 1618 }
1622 else 1619 else
1623 { 1620 {
1624 /* decimal */ 1621 /* decimal */
1625 while (VIM_ISDIGIT(*ptr)) 1622 while (VIM_ISDIGIT(*ptr))
1626 { 1623 {
1627 n = 10 * n + (long)(*ptr - '0');
1628 un = 10 * un + (unsigned long)(*ptr - '0'); 1624 un = 10 * un + (unsigned long)(*ptr - '0');
1629 ++ptr; 1625 ++ptr;
1630 } 1626 }
1631 } 1627 }
1632
1633 if (!hex && negative) /* account for leading '-' for decimal numbers */
1634 n = -n;
1635 1628
1636 if (hexp != NULL) 1629 if (hexp != NULL)
1637 *hexp = hex; 1630 *hexp = hex;
1638 if (len != NULL) 1631 if (len != NULL)
1639 *len = (int)(ptr - start); 1632 *len = (int)(ptr - start);
1640 if (nptr != NULL) 1633 if (nptr != NULL)
1641 *nptr = n; 1634 {
1635 if (negative) /* account for leading '-' for decimal numbers */
1636 *nptr = -(long)un;
1637 else
1638 *nptr = (long)un;
1639 }
1642 if (unptr != NULL) 1640 if (unptr != NULL)
1643 *unptr = un; 1641 *unptr = un;
1644 } 1642 }
1645 1643
1646 /* 1644 /*