[nemiver: 1/5] Start of Big overhaul of string / locale handling
- From: Jonathon Jongsma <jjongsma src gnome org>
- To: svn-commits-list gnome org
- Subject: [nemiver: 1/5] Start of Big overhaul of string / locale handling
- Date: Sun, 19 Apr 2009 22:56:13 -0400 (EDT)
commit 90e7ac8d4ff7fddf9ccbae368f3425d35b0528eb
Author: Jonathon Jongsma <jonathon jongsma collabora co uk>
Date: Fri Apr 10 22:17:25 2009 -0500
Start of Big overhaul of string / locale handling
* src/common/nmv-ustring.h: make the UString(std::string) constructor
explicit because we were getting a lot of unwanted implicit
conversions. This was compounded by the fact that this constructor
actually does a locale conversion. So the combination of unwanted
implicit conversions and charset conversion killed our gdbmi parsing
performance in some areas.
* src/common/nmv-log-stream.cc:
* src/common/nmv-log-stream.h: Add some overloaded operator<< for char*
and std::string so that when we log C strings or std::strings, they
don't need to be converted to UStrings first. Also, change the
operator<<(UString) to operator<<(Glib::ustring) because otherwise
attempting to log a Glib::ustring resulted in ambiguity and logging a
UString as a Glib::ustring should be just fine
* src/common/nmv-env.cc:
* src/dbgengine/nmv-gdb-engine.cc:
* src/dbgengine/nmv-gdbmi-parser.cc:
* src/dbgengine/nmv-i-debugger.h:
* src/persp/dbgperspective/nmv-dbg-perspective.cc:
* src/persp/dbgperspective/nmv-locate-file-dialog.cc:
* src/workbench/nmv-workbench.cc: fixed up all of the implicit
conversions from std::string to UString that were exposed when making
the constructor explicit
---
src/common/nmv-env.cc | 24 +++++-----
src/common/nmv-log-stream.cc | 18 ++++++-
src/common/nmv-log-stream.h | 12 ++++-
src/common/nmv-ustring.h | 2 +-
src/dbgengine/nmv-gdb-engine.cc | 12 ++--
src/dbgengine/nmv-gdbmi-parser.cc | 2 +-
src/dbgengine/nmv-i-debugger.h | 2 +-
src/persp/dbgperspective/nmv-dbg-perspective.cc | 53 ++++++++++---------
src/persp/dbgperspective/nmv-locate-file-dialog.cc | 2 +-
src/workbench/nmv-workbench.cc | 3 +-
10 files changed, 77 insertions(+), 53 deletions(-)
diff --git a/src/common/nmv-env.cc b/src/common/nmv-env.cc
index 24ca5b8..419cbd7 100644
--- a/src/common/nmv-env.cc
+++ b/src/common/nmv-env.cc
@@ -291,16 +291,16 @@ build_path_to_help_file (const UString &a_file_name)
//So the goal of this function is to go look in that directory
//to see if a_file_name exists there. If so, return the path to it.
//Otherwise, return an empty string.
- UString result;
+ std::string result;
UString prefix (get_install_prefix ());
- vector<string> path_elems;
- path_elems.push_back (prefix.c_str ());
+ vector<std::string> path_elems;
+ path_elems.push_back (Glib::filename_from_utf8 (prefix));
path_elems.push_back ("share");
path_elems.push_back ("gnome");
path_elems.push_back ("help");
path_elems.push_back ("nemiver");
- string help_dir = Glib::build_filename (path_elems);
+ std::string help_dir = Glib::build_filename (path_elems);
if (!Glib::file_test (help_dir, Glib::FILE_TEST_IS_DIR)) {
LOG_ERROR ("help dir " << help_dir << " does not exist");
@@ -310,7 +310,7 @@ build_path_to_help_file (const UString &a_file_name)
locale loc ("");
UString loc_name (loc.name ());
LOG_DD ("locale name: " << loc_name);
- string lang_dir = Glib::build_filename (help_dir, loc_name.c_str ());
+ std::string lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
LOG_DD ("lang dir '" << lang_dir << "' does not exist");
//let's try now to extract the <language>_<territory> part of the
@@ -322,7 +322,7 @@ build_path_to_help_file (const UString &a_file_name)
goto locale_language;
}
loc_name = tmp[0];
- lang_dir = Glib::build_filename (help_dir, loc_name.c_str ());
+ lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
LOG_DD ("trying locale name: " << lang_dir);
if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
LOG_DD ("lang dir '" << lang_dir << "' does not exist");
@@ -334,18 +334,18 @@ locale_language:
goto c_locale;
}
loc_name = tmp[0];
- lang_dir = Glib::build_filename (help_dir, loc_name.c_str ());
+ lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
LOG_DD ("trying locale name: " << lang_dir);
if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
LOG_DD ("lang dir '" << lang_dir << "' does not exist");
//okay so let's fall back to the C locale then.
c_locale:
loc_name = "C";
- lang_dir = Glib::build_filename (help_dir, loc_name.c_str ());
+ lang_dir = Glib::build_filename (help_dir, loc_name.raw ());
LOG_DD ("trying locale name: " << lang_dir);
if (!Glib::file_test (lang_dir, Glib::FILE_TEST_IS_DIR)) {
LOG_ERROR ("could not find a proper help dir");
- return result;
+ return UString ();
}
}
}
@@ -355,7 +355,7 @@ c_locale:
LOG_ERROR ("file " << result << " does not exist!");
result.clear ();
}
- return result;
+ return Glib::filename_to_utf8 (result);
}
@@ -363,10 +363,10 @@ bool
build_path_to_executable (const UString &a_exe_name,
UString &a_path_to_exe)
{
- UString path = Glib::find_program_in_path (a_exe_name);
+ std::string path = Glib::find_program_in_path (a_exe_name);
if (path.empty ())
return false;
- a_path_to_exe = path;
+ a_path_to_exe = Glib::filename_to_utf8 (path);
return true;
}
diff --git a/src/common/nmv-log-stream.cc b/src/common/nmv-log-stream.cc
index 0dc4647..c950962 100644
--- a/src/common/nmv-log-stream.cc
+++ b/src/common/nmv-log-stream.cc
@@ -124,7 +124,7 @@ public:
return *this ;
}
- LogSink& operator<< (const UString &a_string)
+ LogSink& operator<< (const Glib::ustring &a_string)
{
if (!m_out) throw runtime_error ("underlying ostream not initialized") ;
Glib::Mutex::Lock lock (m_ostream_mutex) ;
@@ -510,14 +510,26 @@ LogStream::pop_domain ()
}
LogStream&
-LogStream::write (const UString &a_msg, const string &a_domain)
+LogStream::write (const Glib::ustring &a_msg, const string &a_domain)
{
return write (a_msg.c_str (), a_msg.bytes (), a_domain) ;
}
LogStream&
-LogStream::operator<< (const UString &a_string)
+LogStream::operator<< (const char* a_c_string)
+{
+ return write (a_c_string, -1, m_priv->default_domains.front ()) ;
+}
+
+LogStream&
+LogStream::operator<< (const std::string &a_string)
+{
+ return write (a_string.c_str (), -1, m_priv->default_domains.front ()) ;
+}
+
+LogStream&
+LogStream::operator<< (const Glib::ustring &a_string)
{
return write (a_string, m_priv->default_domains.front ()) ;
}
diff --git a/src/common/nmv-log-stream.h b/src/common/nmv-log-stream.h
index 82ff40c..abed1c0 100644
--- a/src/common/nmv-log-stream.h
+++ b/src/common/nmv-log-stream.h
@@ -171,7 +171,7 @@ public:
/// \brief log a message to the stream
/// \param a_msg the message to log
/// \param a_domain the domain to log against
- LogStream& write (const UString &a_msg,
+ LogStream& write (const Glib::ustring &a_msg,
const string &a_domain=NMV_GENERAL_DOMAIN) ;
LogStream& write (int a_msg,
@@ -195,7 +195,15 @@ public:
/// \brief log zero teriminated strings
/// \param a_string the string to log
- LogStream& operator<< (const UString &a_string) ;
+ LogStream& operator<< (const char* a_c_string);
+
+ /// \brief log a string
+ /// \param a_string the string to log
+ LogStream& operator<< (const std::string &a_string);
+
+ /// \brief log a UTF-8 string
+ /// \param a_string the string to log
+ LogStream& operator<< (const Glib::ustring &a_string) ;
/// \brief log an integer
/// \param an_int the integer to log
diff --git a/src/common/nmv-ustring.h b/src/common/nmv-ustring.h
index bb98e87..eca1a6f 100644
--- a/src/common/nmv-ustring.h
+++ b/src/common/nmv-ustring.h
@@ -50,7 +50,7 @@ public:
UString (const char *a_cstr, long a_len=-1) ;
UString (const unsigned char *a_cstr, long a_len=-1) ;
UString (const Glib::ustring &an_other_string) ;
- UString (const string &an_other_string) ;
+ explicit UString (const string &an_other_string) ;
UString (UString const &an_other_string) ;
virtual ~UString () ;
UString& set (const gchar* a_buf, gulong a_len) ;
diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index c5fd75b..e45b6c9 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -529,11 +529,11 @@ public:
vector<UString>::const_iterator it;
string file_path;
for (it = path_dirs.begin (); it != path_dirs.end (); ++it) {
- file_path = Glib::build_filename (Glib::locale_from_utf8 (*it),
- Glib::locale_from_utf8 (a_prog));
+ file_path = Glib::build_filename (Glib::filename_from_utf8 (*it),
+ Glib::filename_from_utf8 (a_prog));
if (Glib::file_test (file_path,
Glib::FILE_TEST_IS_REGULAR)) {
- a_prog_path = Glib::locale_to_utf8 (file_path);
+ a_prog_path = Glib::filename_to_utf8 (file_path);
return true;
}
}
@@ -553,7 +553,7 @@ public:
UString prog_path;
if (a_prog != "") {
prog_path = a_prog;
- if (!Glib::file_test (Glib::locale_from_utf8 (prog_path),
+ if (!Glib::file_test (Glib::filename_from_utf8 (prog_path),
Glib::FILE_TEST_IS_REGULAR)) {
if (!find_prog_in_path (prog_path, prog_path)) {
LOG_ERROR ("Could not find program '" << prog_path << "'");
@@ -3409,7 +3409,7 @@ GDBEngine::extract_global_variable_list (Output &a_output,
//"<type of variable> <variable-name>;"
//*************************************************
UString str, file_name;
- string var_name, type_name, tmp_str;
+ string var_name, tmp_str;
SimpleDeclarationPtr simple_decl;
InitDeclaratorPtr init_decl;
ParserPtr parser;
@@ -3487,7 +3487,7 @@ fetch_variable:
}
LOG_DD ("globals: got variable name: " << var_name );
- var.reset (new IDebugger::Variable (var_name));
+ var.reset (new IDebugger::Variable (UString (var_name)));
var_list.push_back (var);
skip_oobr:
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index 741051b..6b95f7c 100644
--- a/src/dbgengine/nmv-gdbmi-parser.cc
+++ b/src/dbgengine/nmv-gdbmi-parser.cc
@@ -4060,7 +4060,7 @@ GDBMIParser::parse_gdbmi_tuple (UString::size_type a_from,
<< "', at offset '"
<< (int)cur
<< "' for text >>>"
- << m_priv->input.raw ()
+ << m_priv->input
<< "<<<",
GDBMI_PARSING_DOMAIN);
break;
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index 35ed562..b2717a5 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -335,7 +335,7 @@ public:
const UString& type () const {return m_type;}
void type (const UString &a_type) {m_type = a_type;}
- void type (const string &a_type) {m_type = a_type;}
+ void type (const string &a_type) {m_type = UString(a_type);}
Variable* parent () const {return m_parent;}
void parent (Variable *a_parent)
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index 2089ff1..1ecf20a 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -980,7 +980,7 @@ struct DBGPerspective::Priv {
UString buf_content;
if (is_buffer_valid_utf8 (a_input.c_str (), a_input.size ())) {
- a_output = a_input;
+ a_output = UString(a_input.c_str ());
return true;
}
UString utf8_content;
@@ -1005,9 +1005,9 @@ struct DBGPerspective::Priv {
LOG_DD ("trying to convert buffer from encoding "
<< it->c_str ()
<< " to UTF-8");
- utf8_content = Glib::convert (a_input,
- "UTF-8",
- it->c_str ());
+ utf8_content =
+ UString (Glib::convert (a_input, "UTF-8",
+ it->c_str ()));
} catch (Glib::Exception &e) {
LOG_DD ("tentative encoding conversion failed!");
continue;
@@ -1025,9 +1025,10 @@ struct DBGPerspective::Priv {
LOG_DD ("trying hardcoded encodings");
for (unsigned int i=0; i < SIZE_OF_SUPPORTED_ENCODINGS; i++) {
try {
- utf8_content = Glib::convert (a_input,
- "UTF-8",
- SUPPORTED_ENCODINGS[i]);
+ utf8_content =
+ UString (Glib::convert (a_input,
+ "UTF-8",
+ SUPPORTED_ENCODINGS[i]));
} catch (Glib::Exception &e) {
continue;
} catch (...) {
@@ -4164,8 +4165,9 @@ DBGPerspective::record_and_save_session (ISessMgr::Session &a_session)
// Don't save empty sessions.
return;
}
- UString session_name = Glib::path_get_basename
- (Glib::filename_from_utf8 (m_priv->prog_path));
+ UString session_name =
+ Glib::filename_to_utf8 (Glib::path_get_basename
+ (Glib::filename_from_utf8 (m_priv->prog_path)));
if (session_name == "") {return;}
@@ -4325,12 +4327,11 @@ DBGPerspective::load_file (const UString &a_path,
if (!file.good () && !file.eof ()) {
#endif
LOG_ERROR ("Could not open file " + path);
- ui_utils::display_error ("Could not open file: " + path);
+ ui_utils::display_error ("Could not open file: " + Glib::filename_to_utf8 (path));
return false;
}
- UString base_name = Glib::filename_to_utf8
- (Glib::path_get_basename (path));
+ UString base_name = Glib::filename_to_utf8 (Glib::path_get_basename (path));
UString mime_type;
#ifdef WITH_GIO
@@ -4700,9 +4701,10 @@ DBGPerspective::update_file_maps ()
(m_priv->sourceviews_notebook->get_nth_page (i));
THROW_IF_FAIL (se);
se->get_path (path);
- basename = Glib::path_get_basename (path.raw ());
+ basename = Glib::filename_to_utf8 (Glib::path_get_basename
+ (Glib::filename_from_utf8 (path)));
m_priv->path_2_pagenum_map[path] = i;
- m_priv->basename_2_pagenum_map[basename.raw ()] = i;
+ m_priv->basename_2_pagenum_map[basename] = i;
m_priv->pagenum_2_source_editor_map[i] = se;
m_priv->pagenum_2_path_map[i] = path;
}
@@ -4889,11 +4891,12 @@ DBGPerspective::execute_program
// in the $PATH environment variable and use the resulting absolute
// path.
// In the later form, nemiver will just use the absolute path.
- if (!Glib::file_test (prog, Glib::FILE_TEST_IS_REGULAR)) {
+ if (!Glib::file_test (Glib::filename_from_utf8 (prog),
+ Glib::FILE_TEST_IS_REGULAR)) {
// We didn't find prog. If the path to prog is not absolute,
// look it up in the directories pointed to by the
// $PATH environment variable.
- if (Glib::path_is_absolute (prog.raw ())
+ if (Glib::path_is_absolute (Glib::filename_from_utf8 (prog))
|| !env::build_path_to_executable (prog, prog)) {
UString msg;
msg.printf (_("Could not find file %s"), prog.c_str ());
@@ -5406,11 +5409,11 @@ DBGPerspective::append_visual_breakpoint (const UString &a_file_name,
UString file_path = dialog.file_location ();
THROW_IF_FAIL (Glib::file_test (file_path,
Glib::FILE_TEST_IS_REGULAR));
- UString parent_dir =
- Glib::path_get_dirname (dialog.file_location ());
- THROW_IF_FAIL (Glib::file_test
- (parent_dir,
- Glib::FILE_TEST_IS_DIR));
+ std::string raw_dir = Glib::path_get_dirname
+ (dialog.file_location ());
+ UString parent_dir = Glib::filename_to_utf8 (raw_dir);
+ THROW_IF_FAIL (Glib::file_test (raw_dir,
+ Glib::FILE_TEST_IS_DIR));
m_priv->search_paths.push_back (parent_dir);
if (!open_file (file_path)) {
return false;
@@ -5455,8 +5458,8 @@ DBGPerspective::append_visual_breakpoint (const UString &a_file_name,
Glib::FILE_TEST_IS_REGULAR));
THROW_IF_FAIL (Glib::path_get_basename(a_file_name) ==
Glib::path_get_basename(file_path));
- UString parent_dir =
- Glib::path_get_dirname (dialog.file_location ());
+ UString parent_dir = Glib::filename_to_utf8
+ (Glib::path_get_dirname (dialog.file_location ()));
THROW_IF_FAIL (Glib::file_test
(parent_dir, Glib::FILE_TEST_IS_DIR));
@@ -5916,10 +5919,10 @@ DBGPerspective::call_function (const UString &a_call_expr)
// saying that we are calling a_call_expr
std::stringstream s;
s << "<Nemiver call_function>"
- << a_call_expr
+ << a_call_expr.raw ()
<< "</Nemiver>"
<< "\n\r";
- get_terminal ().feed (s.str ());
+ get_terminal ().feed (UString (s.str ()));
// Really hit the debugger now.
debugger ()->call_function (a_call_expr);
diff --git a/src/persp/dbgperspective/nmv-locate-file-dialog.cc b/src/persp/dbgperspective/nmv-locate-file-dialog.cc
index 8722227..e6c0965 100644
--- a/src/persp/dbgperspective/nmv-locate-file-dialog.cc
+++ b/src/persp/dbgperspective/nmv-locate-file-dialog.cc
@@ -114,7 +114,7 @@ LocateFileDialog::file_location () const
THROW_IF_FAIL (m_priv->fcbutton_location);
NEMIVER_CATCH
- return m_priv->fcbutton_location->get_filename ();
+ return Glib::filename_to_utf8 (m_priv->fcbutton_location->get_filename ());
}
void
diff --git a/src/workbench/nmv-workbench.cc b/src/workbench/nmv-workbench.cc
index dcf9791..329d798 100644
--- a/src/workbench/nmv-workbench.cc
+++ b/src/workbench/nmv-workbench.cc
@@ -235,7 +235,8 @@ Workbench::on_contents_menu_item_action ()
THROW_IF_FAIL (!path_to_help.empty ());
UString cmd_line ("yelp " + path_to_help);
LOG_DD ("going to spawn: " << cmd_line);
- bool is_ok = g_spawn_command_line_async (cmd_line.c_str (), NULL);
+ bool is_ok = g_spawn_command_line_async (Glib::locale_from_utf8
+ (cmd_line).c_str (), NULL);
if (!is_ok) {
LOG_ERROR ("failed to spawn " << is_ok);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]