jed-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: jed 0.99-17 looks good


> 
> G. Milde <g.milde@xxxxxx> wrote:
> >Is there a function, that checks whether a string contains characters except
> >0-9?

On Fri, 26 Nov 2004 10:10:21 -0500, "John E. Davis" <davis@xxxxxxxxxxxxx> said:
> 
> You can use:
> 
>    i = array_map (Int_Type, &string_match, files, "^[0-9]+$", 1);
>    files = files[where(i)];
> 
> to prune the files array to values that consist only of digits.
> 
> Instead of atoi, I may add a function like strtol that allows a radix
> to be specified so that "09" will be converted to 9 for radix 10.  At
> the moment, integer("09") will attempt to interpret this as octal
> (radix 8) resulting in an exception.

I believe this is exactly the behavior of the Python "int" function:

`int(x[, radix])'
     Convert a string or number to a plain integer.  If the argument is
     a string, it must contain a possibly signed decimal number
     representable as a Python integer, possibly embedded in whitespace;
     this behaves identical to `string.atoi(X[, RADIX])'.  The RADIX
     parameter gives the base for the conversion and may be any integer
     in the range [2, 36], or zero.  If RADIX is zero, the proper radix
     is guessed based on the contents of string; the interpretation is
     the same as for integer literals.  If RADIX is specified and X is
     not a string, `TypeError' is raised.  Otherwise, the argument may
     be a plain or long integer or a floating point number.  Conversion
     of floating point numbers to integers is defined by the C
     semantics; normally the conversion truncates towards zero.(2)

I suppose you could simply add an optional "radix" argument to integer(). It
would still have the annoying properties of guessing (often wrong) that the
number is octal when it starts with a "0" and no radix is specified, and of
raising an error when the string is not a number, necessitating the array_map
above if you want to convert an array of strings.

So I wrapped the libc atoi() function which has none of these drawbacks.
You can find it at http://www.cheesit.com/downloads/slang/slatoi
I've also updated the gdbm and gettext modules to work in S-Lang 2.

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]