View Javadoc

1   package net.sf.asterisk.util;
2   
3   /***
4    * Some static utility methods to handle Asterisk specific stuff.<br>
5    * See Asterisk's <code>util.c</code>.
6    * 
7    * @author srt
8    * @version $Id: AstUtil.java,v 1.1 2005/07/26 12:16:03 srt Exp $
9    */
10  public class AstUtil
11  {
12      // hide constructor
13      private AstUtil()
14      {
15      }
16  
17      /***
18       * Checks if a String represents <code>true</code> or <code>false</code>
19       * according to Asterisk's logic.<br>
20       * The original implementation is <code>util.c</code> is as follows:
21       * 
22       * <pre>
23       *    int ast_true(const char *s)
24       *    {
25       *        if (!s || ast_strlen_zero(s))
26       *            return 0;
27       *     
28       *        if (!strcasecmp(s, &quot;yes&quot;) ||
29       *            !strcasecmp(s, &quot;true&quot;) ||
30       *            !strcasecmp(s, &quot;y&quot;) ||
31       *            !strcasecmp(s, &quot;t&quot;) ||
32       *            !strcasecmp(s, &quot;1&quot;) ||
33       *            !strcasecmp(s, &quot;on&quot;))
34       *            return -1;
35       *    
36       *        return 0;
37       *    }
38       * </pre>
39       * 
40       * @param s the String to check for <code>true</code>.
41       * @return <code>true</code> if s represents <code>true</code>,
42       * <code>false</code> otherwise.
43       */
44      public static boolean isTrue(String s)
45      {
46          if (s == null || s.length() == 0)
47          {
48              return false;
49          }
50  
51          if (("yes".equalsIgnoreCase(s) || "true".equalsIgnoreCase(s))
52                  || "y".equalsIgnoreCase(s) || "t".equalsIgnoreCase(s)
53                  || "1".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s))
54          {
55              return true;
56          }
57          else
58          {
59              return false;
60          }
61      }
62  }