Implement fallback if Glib::Regex class is missing (#695279)
GParted fails to compile on RHEL/CentOS 5.9 because it doesn't provide
the Glib::Regex class. Glib::Regex class requires glibmm >= 2.14,
however RHEL/CentOS 5.9 only provides glibmm 2.12.
Add an autoconf check for the Glib::Regex class and fallback code using
the POSIX regex function. Fall back code is the same as that used prior
to commit:
b6f1c56fb1
Enhance regexp_label method to handle unicode characters
Bug #695279 - GParted doesn't compile on RHEL / CentOS 5.9
This commit is contained in:
parent
5b737b224d
commit
456932846b
11
configure.in
11
configure.in
|
@ -252,6 +252,17 @@ AC_SUBST([GTKMM_LIBS])
|
|||
AC_SUBST([GTKMM_CFLAGS])
|
||||
|
||||
|
||||
dnl Check for glibmm >= 2.14 to determine availability of Glib::Regex class
|
||||
AC_MSG_CHECKING([for Glib::Regex class])
|
||||
PKG_CHECK_EXISTS(
|
||||
[glibmm-2.4 >= 2.14.0],
|
||||
[AC_DEFINE([HAVE_GLIB_REGEX], 1, [Define to 1 if glibmm provides Glib::Regex class.])
|
||||
AC_MSG_RESULT([yes])
|
||||
],
|
||||
[AC_MSG_RESULT([no])]
|
||||
)
|
||||
|
||||
|
||||
dnl GTKMM 2.16 needed for gtk_show_uri()
|
||||
PKG_CHECK_EXISTS([gtkmm-2.4 >= 2.16.0],
|
||||
[AC_DEFINE([HAVE_GTK_SHOW_URI], 1, [Define to 1 if you have gtk_show_uri])],
|
||||
|
|
19
src/Utils.cc
19
src/Utils.cc
|
@ -23,7 +23,11 @@
|
|||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#ifdef HAVE_GLIB_REGEX
|
||||
#include <glibmm/regex.h>
|
||||
#else
|
||||
#include <regex.h>
|
||||
#endif
|
||||
#include <locale.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <cerrno>
|
||||
|
@ -506,6 +510,7 @@ Glib::ustring Utils::regexp_label( const Glib::ustring & text
|
|||
{
|
||||
//Extract text from a regular sub-expression or pattern.
|
||||
// E.g., "text we don't want (text we want)"
|
||||
#ifdef HAVE_GLIB_REGEX
|
||||
std::vector<Glib::ustring> results;
|
||||
Glib::RefPtr<Glib::Regex> myregexp =
|
||||
Glib::Regex::create( pattern
|
||||
|
@ -518,6 +523,20 @@ Glib::ustring Utils::regexp_label( const Glib::ustring & text
|
|||
return results[ 1 ] ;
|
||||
else
|
||||
return "" ;
|
||||
#else /* ! HAVE_GLIB_REGEX */
|
||||
Glib::ustring label = "" ;
|
||||
regex_t preg ;
|
||||
int nmatch = 2 ;
|
||||
regmatch_t pmatch[ 2 ] ;
|
||||
int rc = regcomp( &preg, pattern .c_str(), REG_EXTENDED | REG_ICASE | REG_NEWLINE ) ;
|
||||
if ( rc == 0 )
|
||||
{
|
||||
if ( regexec( &preg, text .c_str(), nmatch, pmatch, 0 ) == 0 )
|
||||
label = text .substr( pmatch[ 1 ] .rm_so, pmatch[ 1 ] .rm_eo - pmatch[ 1 ] .rm_so ) ;
|
||||
regfree( &preg ) ;
|
||||
}
|
||||
return label ;
|
||||
#endif
|
||||
}
|
||||
|
||||
Glib::ustring Utils::trim( const Glib::ustring & src, const Glib::ustring & c /* = " \t\r\n" */ )
|
||||
|
|
Loading…
Reference in New Issue