[Swift-user] Treatment of booleans in Swift

Bronevetsky, Greg bronevetsky1 at llnl.gov
Mon May 19 18:31:11 CDT 2014


> -          tracef doesn't have a format option for Booleans, forcing

> me to convert them to strings. Running @toInt on a Boolean produces:

> "java.lang.NumberFormatException: For input string: "false"".



I think the documentation is lying (by omission) about that. Try "%b".

Thanks!





All of "True" and "true" and "TRUE" and "tRuE" (and all other case

combinations) should work. The implementation uses Java's Boolean.valueOf(String), which calls this:

    private static boolean toBoolean(String name) {

        return ((name != null) && name.equalsIgnoreCase("true"));

    }

Great! I must have had another bug that I thought was caused by mis-parsing of file contents.



Greg Bronevetsky

Lawrence Livermore National Lab

(925) 424-5756

bronevetsky at llnl.gov

http://greg.bronevetsky.com





-----Original Message-----
From: Mihael Hategan [mailto:hategan at mcs.anl.gov]
Sent: Monday, May 19, 2014 4:29 PM
To: Bronevetsky, Greg
Cc: swift-user at ci.uchicago.edu
Subject: Re: [Swift-user] Treatment of booleans in Swift



On Mon, 2014-05-19 at 23:22 +0000, Bronevetsky, Greg wrote:

> I've been working with Booleans recently and I've run into a couple of issues with them that might be a problem for others:

>

> -          tracef doesn't have a format option for Booleans, forcing

> me to convert them to strings. Running @toInt on a Boolean produces:

> "java.lang.NumberFormatException: For input string: "false"".



I think the documentation is lying (by omission) about that. Try "%b".



>

> -          It is not clear how to format files to be read by

> readData() if the data in question is a Boolean. Based on

> experimentation I discovered that the correct strings are

> "True"/"False" rather than "true"/"false" or "0"/"1". It would be

> useful to document this in the description of readData().



All of "True" and "true" and "TRUE" and "tRuE" (and all other case

combinations) should work. The implementation uses Java's Boolean.valueOf(String), which calls this:

    private static boolean toBoolean(String name) {

        return ((name != null) && name.equalsIgnoreCase("true"));

    }



Mihael


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-user/attachments/20140519/b0d21cf9/attachment.html>


More information about the Swift-user mailing list