subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1125724 - in /subversion/trunk/subversion/libsvn_subr: config.c kitchensink.c
Date Sat, 21 May 2011 15:10:02 GMT
Author: stefan2
Date: Sat May 21 15:10:02 2011
New Revision: 1125724

URL: http://svn.apache.org/viewvc?rev=1125724&view=rev
Log:
Since string-to-boolean conversion is frequently needed in parameter
and configuration processing, make all variants supported by svn_config_*
interfaces today available to everyone.

* subversion/libsvn_subr/kitchensink.c
  (svn_tristate_from_word): ignore case; add "yes/no", "on/off", "1/0" support
* subversion/libsvn_subr/config.c
  (get_bool): call svn_tristate_from_word for str-to-bool conversion

Modified:
    subversion/trunk/subversion/libsvn_subr/config.c
    subversion/trunk/subversion/libsvn_subr/kitchensink.c

Modified: subversion/trunk/subversion/libsvn_subr/config.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/config.c?rev=1125724&r1=1125723&r2=1125724&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/config.c (original)
+++ subversion/trunk/subversion/libsvn_subr/config.c Sat May 21 15:10:02 2011
@@ -651,41 +651,25 @@ static svn_error_t *
 get_bool(svn_boolean_t *boolp, const char *input, svn_boolean_t default_value,
          const char *section, const char *option)
 {
-  if (input == NULL)
-    {
-      *boolp = default_value;
-    }
-  else if (0 == svn_cstring_casecmp(input, SVN_CONFIG_TRUE)
-           || 0 == svn_cstring_casecmp(input, "yes")
-           || 0 == svn_cstring_casecmp(input, "on")
-           || 0 == strcmp(input, "1"))
-    {
-      *boolp = TRUE;
-    }
-  else if (0 == svn_cstring_casecmp(input, SVN_CONFIG_FALSE)
-           || 0 == svn_cstring_casecmp(input, "no")
-           || 0 == svn_cstring_casecmp(input, "off")
-           || 0 == strcmp(input, "0"))
-    {
-      *boolp = FALSE;
-    }
-  else  /* unrecognized value */
-    {
-      if (section)
-        {
-          return svn_error_createf(SVN_ERR_BAD_CONFIG_VALUE, NULL,
-                                   _("Config error: invalid boolean "
-                                     "value '%s' for '[%s] %s'"),
-                                   input, section, option);
-        }
-      else
-        {
-          return svn_error_createf(SVN_ERR_BAD_CONFIG_VALUE, NULL,
-                                   _("Config error: invalid boolean "
-                                     "value '%s' for '%s'"),
-                                   input, option);
-        }
-    }
+  svn_tristate_t value = svn_tristate_from_word(input);
+  
+  if (value == svn_tristate_true)
+    *boolp = TRUE;
+  else if (value == svn_tristate_false)
+    *boolp = FALSE;
+  else if (input == NULL) /* no value provided */
+    *boolp = default_value;
+
+  else if (section) /* unrecognized value */
+    return svn_error_createf(SVN_ERR_BAD_CONFIG_VALUE, NULL,
+                             _("Config error: invalid boolean "
+                               "value '%s' for '[%s] %s'"),
+                             input, section, option);
+  else
+    return svn_error_createf(SVN_ERR_BAD_CONFIG_VALUE, NULL,
+                             _("Config error: invalid boolean "
+                               "value '%s' for '%s'"),
+                             input, option);
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_subr/kitchensink.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/kitchensink.c?rev=1125724&r1=1125723&r2=1125724&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/kitchensink.c (original)
+++ subversion/trunk/subversion/libsvn_subr/kitchensink.c Sat May 21 15:10:02 2011
@@ -200,9 +200,15 @@ svn_tristate_from_word(const char *word)
 {
   if (word == NULL)
     return svn_tristate_unknown;
-  else if (strcmp(word, "true") == 0)
+  else if (0 == svn_cstring_casecmp(word, "true")
+           || 0 == svn_cstring_casecmp(word, "yes")
+           || 0 == svn_cstring_casecmp(word, "on")
+           || 0 == strcmp(word, "1"))
     return svn_tristate_true;
-  else if (strcmp(word, "false") == 0)
+  else if (0 == svn_cstring_casecmp(word, "false")
+           || 0 == svn_cstring_casecmp(word, "no")
+           || 0 == svn_cstring_casecmp(word, "off")
+           || 0 == strcmp(word, "0"))
     return svn_tristate_false;
 
   return svn_tristate_unknown;



Mime
View raw message