From d6051c9953ea8778399ad72fc91c334c242d25e0 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 12 Apr 2012 11:45:40 +0000 Subject: move string_is_affirmative() into libpbd git-svn-id: svn://localhost/ardour2/branches/3.0@11936 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd/convert.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'libs/pbd/convert.cc') 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 -- cgit v1.2.3