diff 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
line wrap: on
line diff
--- a/src/charset.c
+++ b/src/charset.c
@@ -1546,7 +1546,7 @@ vim_isblankline(lbuf)
 
 /*
  * Convert a string into a long and/or unsigned long, taking care of
- * hexadecimal and octal numbers.
+ * hexadecimal and octal numbers.  Accepts a '-' sign.
  * If "hexp" is not NULL, returns a flag to indicate the type of the number:
  *  0	    decimal
  *  '0'	    octal
@@ -1570,7 +1570,6 @@ vim_str2nr(start, hexp, len, dooct, dohe
     char_u	    *ptr = start;
     int		    hex = 0;		/* default is decimal */
     int		    negative = FALSE;
-    long	    n = 0;
     unsigned long   un = 0;
 
     if (ptr[0] == '-')
@@ -1603,7 +1602,6 @@ vim_str2nr(start, hexp, len, dooct, dohe
 	    /* octal */
 	    while ('0' <= *ptr && *ptr <= '7')
 	    {
-		n = 8 * n + (long)(*ptr - '0');
 		un = 8 * un + (unsigned long)(*ptr - '0');
 		++ptr;
 	    }
@@ -1613,7 +1611,6 @@ vim_str2nr(start, hexp, len, dooct, dohe
 	    /* hex */
 	    while (vim_isxdigit(*ptr))
 	    {
-		n = 16 * n + (long)hex2nr(*ptr);
 		un = 16 * un + (unsigned long)hex2nr(*ptr);
 		++ptr;
 	    }
@@ -1624,21 +1621,22 @@ vim_str2nr(start, hexp, len, dooct, dohe
 	/* decimal */
 	while (VIM_ISDIGIT(*ptr))
 	{
-	    n = 10 * n + (long)(*ptr - '0');
 	    un = 10 * un + (unsigned long)(*ptr - '0');
 	    ++ptr;
 	}
     }
 
-    if (!hex && negative)   /* account for leading '-' for decimal numbers */
-	n = -n;
-
     if (hexp != NULL)
 	*hexp = hex;
     if (len != NULL)
 	*len = (int)(ptr - start);
     if (nptr != NULL)
-	*nptr = n;
+    {
+	if (negative)   /* account for leading '-' for decimal numbers */
+	    *nptr = -(long)un;
+	else
+	    *nptr = (long)un;
+    }
     if (unptr != NULL)
 	*unptr = un;
 }