summaryrefslogtreecommitdiff
path: root/libs/pbd/convert.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-04-12 11:45:40 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-04-12 11:45:40 +0000
commitd6051c9953ea8778399ad72fc91c334c242d25e0 (patch)
tree34c9725486c0c7b9242c8b645aa2e4290218273a /libs/pbd/convert.cc
parent81a76cc0fdf569e96697c4cea58debb74d6e5545 (diff)
move string_is_affirmative() into libpbd
git-svn-id: svn://localhost/ardour2/branches/3.0@11936 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/convert.cc')
-rw-r--r--libs/pbd/convert.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/libs/pbd/convert.cc b/libs/pbd/convert.cc
index 3d968d0627..07407e2fad 100644
--- a/libs/pbd/convert.cc
+++ b/libs/pbd/convert.cc
@@ -255,6 +255,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_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_strncasecmp(str.c_str(), "yes", str.length())) ||
+ (!g_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