From d3f7d6109d396adb449a150fc2b9feb3045634d0 Mon Sep 17 00:00:00 2001 From: Kjell Ahlstedt Date: Mon, 18 Nov 2019 09:25:37 +0100 Subject: Avoid unnecessary conversions between std::string and Glib::ustring A few implicit conversions in tests/ have been kept. They are probably deliberate, to test implicit conversion. Inspired by issue #65 --- examples/dbus/server_without_bus.cc | 4 ++-- examples/network/resolver.cc | 18 ++++++++---------- examples/options/main.cc | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/dbus/server_without_bus.cc b/examples/dbus/server_without_bus.cc index d97eed3d..15c558c4 100644 --- a/examples/dbus/server_without_bus.cc +++ b/examples/dbus/server_without_bus.cc @@ -113,7 +113,7 @@ on_server_new_connection(const Glib::RefPtr& connection) { auto credentials = connection->get_peer_credentials(); - std::string credentials_str; + Glib::ustring credentials_str; if (!credentials) credentials_str = "(no credentials received)"; @@ -177,7 +177,7 @@ main(int, char**) Glib::RefPtr server; - const Glib::ustring address = "unix:abstract=myadd"; + const std::string address = "unix:abstract=myadd"; try { server = Gio::DBus::Server::create_sync(address, Gio::DBus::generate_guid()); diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc index a651a1a7..949a0d04 100644 --- a/examples/network/resolver.cc +++ b/examples/network/resolver.cc @@ -347,12 +347,12 @@ do_async_connectable(Glib::RefPtr enumerator) Glib::RefPtr global_connectable; static void -do_connectable(const std::string& arg, gboolean synchronous) +do_connectable(const Glib::ustring& arg, gboolean synchronous) { std::vector parts; Glib::RefPtr connectable; - if (arg.find('/') != std::string::npos) + if (arg.find('/') != Glib::ustring::npos) { /* service/protocol/domain */ parts = split_service_parts(arg); @@ -366,18 +366,16 @@ do_connectable(const std::string& arg, gboolean synchronous) } else { - std::string host, port_str; - guint16 port; + Glib::ustring host; + guint16 port = 0; const auto pos = arg.find(':'); - if (pos != std::string::npos) + if (pos != Glib::ustring::npos) { host = arg.substr(0, pos); - port_str = arg.substr(pos); - port = std::stoul(port_str); + auto port_str = arg.substr(pos); + port = std::stoul(port_str.raw()); } - else - port = 0; if (Gio::hostname_is_ip_address(host)) { @@ -385,7 +383,7 @@ do_connectable(const std::string& arg, gboolean synchronous) connectable = Gio::InetSocketAddress::create(addr, port); } else - connectable = Gio::NetworkAddress::create(arg, port); + connectable = Gio::NetworkAddress::create(arg.raw(), port); } const auto enumerator = connectable->enumerate(); diff --git a/examples/options/main.cc b/examples/options/main.cc index cf6796fc..fc673cb1 100644 --- a/examples/options/main.cc +++ b/examples/options/main.cc @@ -43,7 +43,7 @@ public: Glib::OptionGroup::vecustrings m_arg_list; Glib::OptionGroup::vecustrings m_remaining_list; Glib::ustring m_arg_x_string; - std::string m_arg_x_filename; + Glib::ustring m_arg_x_filename; }; ExampleOptionGroup::ExampleOptionGroup() -- cgit v1.2.1