[vte] terminal: Use string_view



commit bd108b0845609079961bbd42701518b0b0b8c3ef
Author: Christian Persch <chpe src gnome org>
Date:   Thu Nov 21 20:01:30 2019 +0100

    terminal: Use string_view

 src/vte.cc         | 18 ++++++++++++++----
 src/vteinternal.hh |  3 ++-
 src/widget.cc      |  3 +++
 3 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index ee60dfd1..6e9806a7 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -4155,6 +4155,12 @@ Terminal::pty_io_write(int const fd,
         return _vte_byte_array_length(m_outgoing) != 0;
 }
 
+void
+Terminal::send_child(std::string_view const& str)
+{
+        send_child(str.data(), str.size());
+}
+
 /* Send some UTF-8 data to the child. */
 void
 Terminal::send_child(char const* data,
@@ -4352,11 +4358,15 @@ Terminal::reply(vte::parser::Sequence const& seq,
 }
 
 void
-Terminal::im_commit(char const* text)
+Terminal::im_commit(std::string_view const& str)
 {
-       _vte_debug_print(VTE_DEBUG_EVENTS,
-                       "Input method committed `%s'.\n", text);
-       send_child(text, strlen(text));
+        if (!m_input_enabled)
+                return;
+
+        _vte_debug_print(VTE_DEBUG_EVENTS,
+                         "Input method committed `%s'.\n", std::string{str}.c_str());
+        send_child(str);
+
        /* Committed text was committed because the user pressed a key, so
         * we need to obey the scroll-on-keystroke setting. */
         if (m_scroll_on_keystroke && m_input_enabled) {
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 823e7f0e..c8716c07 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -972,6 +972,7 @@ public:
         bool pty_io_write(int const fd,
                           GIOCondition const condition);
 
+        void send_child(std::string_view const& str);
         void send_child(char const* data,
                         gssize length) noexcept;
 
@@ -981,7 +982,7 @@ public:
                               int status);
         void emit_child_exited();
 
-        void im_commit(char const* text);
+        void im_commit(std::string_view const& str);
         void im_preedit_set_active(bool active) noexcept;
         void im_preedit_reset() noexcept;
         void im_preedit_changed(char const* str,
diff --git a/src/widget.cc b/src/widget.cc
index 423c2336..c93b3a2e 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -40,6 +40,9 @@ im_commit_cb(GtkIMContext* im_context,
              char const* text,
              Widget* that)
 {
+        if (text == nullptr)
+                return;
+
         that->terminal()->im_commit(text);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]