[gparted] Enhance regexp_label method to handle unicode characters
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Enhance regexp_label method to handle unicode characters
- Date: Tue, 1 Nov 2011 19:10:04 +0000 (UTC)
commit b6f1c56fb1e6119131a475ff6362f8cd59b1b33b
Author: Curtis Gedak <gedakc gmail com>
Date: Tue Nov 1 13:08:36 2011 -0600
Enhance regexp_label method to handle unicode characters
Prompted by Bug #662537 - Ext4 unicode labels not shown correctly
include/Utils.h | 5 +++--
src/Utils.cc | 35 ++++++++++++++++++-----------------
2 files changed, 21 insertions(+), 19 deletions(-)
---
diff --git a/include/Utils.h b/include/Utils.h
index 3ab76ae..508b03c 100644
--- a/include/Utils.h
+++ b/include/Utils.h
@@ -147,8 +147,9 @@ public:
Glib::ustring & output,
Glib::ustring & error,
bool use_C_locale = false ) ;
- static Glib::ustring regexp_label( const Glib::ustring & text,
- const Glib::ustring & regular_sub_expression ) ;
+ static Glib::ustring regexp_label( const Glib::ustring & text
+ , const Glib::ustring & pattern
+ ) ;
static Glib::ustring fat_compliant_label( const Glib::ustring & label ) ;
static Glib::ustring create_mtoolsrc_file( char file_name[],
const char drive_letter, const Glib::ustring & device_path ) ;
diff --git a/src/Utils.cc b/src/Utils.cc
index 1a72a57..eb07952 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -20,7 +20,7 @@
#include <sstream>
#include <iomanip>
-#include <regex.h>
+#include <glibmm/regex.h>
#include <locale.h>
@@ -327,23 +327,24 @@ int Utils::execute_command( const Glib::ustring & command,
return exit_status ;
}
-Glib::ustring Utils::regexp_label( const Glib::ustring & text,
- const Glib::ustring & regular_sub_expression )
+Glib::ustring Utils::regexp_label( const Glib::ustring & text
+ , const Glib::ustring & pattern
+ )
{
- //Extract text from a regular sub-expression. E.g., "text we don't want (text we want)"
- Glib::ustring label = "";
- regex_t preg ;
- int nmatch = 2 ;
- regmatch_t pmatch[ 2 ] ;
- int rc = regcomp( &preg, regular_sub_expression .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 ;
+ //Extract text from a regular sub-expression or pattern.
+ // E.g., "text we don't want (text we want)"
+ std::vector<Glib::ustring> results;
+ Glib::RefPtr<Glib::Regex> myregexp =
+ Glib::Regex::create( pattern
+ , Glib::REGEX_CASELESS | Glib::REGEX_MULTILINE
+ );
+
+ results = myregexp ->split( text );
+
+ if ( results .size() >= 2 )
+ return results[ 1 ] ;
+ else
+ return "" ;
}
Glib::ustring Utils::fat_compliant_label( const Glib::ustring & label )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]