summaryrefslogtreecommitdiff
path: root/examples/network
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2019-11-18 09:25:37 +0100
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2019-11-18 09:25:37 +0100
commitd3f7d6109d396adb449a150fc2b9feb3045634d0 (patch)
tree66b4f68054b73e1d695bdef19c9ee7f2089c69fa /examples/network
parent89cfdff3e807d53efbe8afb2d3354151043bf70f (diff)
downloadglibmm-d3f7d6109d396adb449a150fc2b9feb3045634d0.tar.gz
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
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/resolver.cc18
1 files changed, 8 insertions, 10 deletions
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<Gio::SocketAddressEnumerator> enumerator)
Glib::RefPtr<Gio::SocketConnectable> global_connectable;
static void
-do_connectable(const std::string& arg, gboolean synchronous)
+do_connectable(const Glib::ustring& arg, gboolean synchronous)
{
std::vector<Glib::ustring> parts;
Glib::RefPtr<Gio::SocketConnectable> 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();