Locations::clear_ranges() leaves punch/loop/session ranges intact if they exist
[ardour.git] / libs / pbd / convert.cc
index 3d968d06279694f85e06a7c2a6d04f9312f90b17..940aa871899390a5278e3b0c430c71c2cc2501d5 100644 (file)
@@ -18,6 +18,9 @@
 */
 
 #include <cmath>
+#include <algorithm>
+#include <string> 
+
 #include <stdint.h>
 #include <stdlib.h>
 #include <cstdio>
@@ -28,6 +31,8 @@
 #endif
 #include <inttypes.h>
 
+#include <glib.h>
+
 #include "pbd/convert.h"
 
 #include "i18n.h"
@@ -49,6 +54,24 @@ capitalize (const string& str)
         return ret;
 }
 
+string
+downcase (const string& str)
+{
+       string copy (str);
+       std::transform (copy.begin(), copy.end(), copy.begin(), ::tolower);
+       return copy;
+}
+
+const char*
+downcase (const char* str)
+{
+       char *copy = strdup (str);
+       for (char* p = copy; *p; ++p) {
+               *p = tolower (*p);
+       }
+       return copy;
+}
+
 string
 short_version (string orig, string::size_type target_length)
 {
@@ -255,6 +278,26 @@ strings_equal_ignore_case (const string& a, const string& b)
        return false;
 }
 
+bool
+string_is_affirmative (const std::string& str)
+{
+       /* to be used only with XML data - not intended to handle user input */
+
+       if (str.empty ()) {
+               return false;
+       }
+
+       /* the use of g_ascii_strncasecmp() is solely to get around issues with
+        * charsets posed by trying to use C++ for the same
+        * comparison. switching a std::string to its lower- or upper-case
+        * version has several issues, but handled by default
+        * in the way we desire when doing it in C.
+        */
+
+       return str == "1" || str == "y" || str == "Y" || (!g_ascii_strncasecmp(str.c_str(), "yes", str.length())) ||
+               (!g_ascii_strncasecmp(str.c_str(), "true", str.length()));
+}
+
 /** A wrapper for dgettext that takes a msgid of the form Context|Text.
  *  If Context|Text is translated, the translation is returned, otherwise
  *  just Text is returned.  Useful for getting translations of words or phrases