Merge pull request #564 from 0xcpy/master

Use std::make_unique from c++14
This commit is contained in:
jelle van der Waa 2018-02-11 02:08:44 +01:00 committed by GitHub
commit 7138bc4949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View File

@ -4,7 +4,7 @@ GTK = gtk+-3.0
VTE = vte-2.91
TERMINFO = ${PREFIX}/share/terminfo
CXXFLAGS := -std=c++11 -O3 \
CXXFLAGS := -std=c++14 -O3 \
-Wall -Wextra -pedantic \
-Winit-self \
-Wshadow \
@ -32,7 +32,7 @@ endif
LDFLAGS := -s -Wl,--as-needed ${LDFLAGS}
LDLIBS := ${shell pkg-config --libs ${GTK} ${VTE}}
termite: termite.cc url_regex.hh util/clamp.hh util/maybe.hh util/memory.hh
termite: termite.cc url_regex.hh util/clamp.hh util/maybe.hh
${CXX} ${CXXFLAGS} ${LDFLAGS} $< ${LDLIBS} -o $@
install: termite termite.desktop termite.terminfo

View File

@ -42,7 +42,6 @@
#include "url_regex.hh"
#include "util/clamp.hh"
#include "util/maybe.hh"
#include "util/memory.hh"
using namespace std::placeholders;
@ -297,18 +296,18 @@ static void launch_in_directory(VteTerminal *vte) {
g_printerr("no directory uri set\n");
return;
}
auto dir = make_unique(g_filename_from_uri(uri, nullptr, nullptr), g_free);
auto dir = std::make_unique<gchar*>(g_filename_from_uri(uri, nullptr, nullptr));
char term[] = "termite"; // maybe this should be argv[0]
char *cmd[] = {term, nullptr};
g_spawn_async(dir.get(), cmd, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr);
g_spawn_async(*dir.get(), cmd, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, nullptr);
}
static void find_urls(VteTerminal *vte, search_panel_info *panel_info) {
GRegex *regex = g_regex_new(url_regex, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, nullptr);
GArray *attributes = g_array_new(FALSE, FALSE, sizeof(VteCharAttributes));
auto content = make_unique(vte_terminal_get_text(vte, nullptr, nullptr, attributes), g_free);
auto content = std::make_unique<gchar*>(vte_terminal_get_text(vte, nullptr, nullptr, attributes));
for (char *s_ptr = content.get(), *saveptr; ; s_ptr = nullptr) {
for (char *s_ptr = *content.get(), *saveptr; ; s_ptr = nullptr) {
const char *token = strtok_r(s_ptr, "\n", &saveptr);
if (!token) {
break;
@ -323,7 +322,7 @@ static void find_urls(VteTerminal *vte, search_panel_info *panel_info) {
g_match_info_fetch_pos(info, 0, &pos, nullptr);
const long first_row = g_array_index(attributes, VteCharAttributes, 0).row;
const auto attr = g_array_index(attributes, VteCharAttributes, token + pos - content.get());
const auto attr = g_array_index(attributes, VteCharAttributes, token + pos - *content.get());
panel_info->url_list.emplace_back(g_match_info_fetch(info, 0),
attr.column,
@ -570,9 +569,9 @@ static void open_selection(char *browser, VteTerminal *vte) {
}
if (browser) {
auto selection = make_unique(vte_terminal_get_selection(vte), g_free);
auto selection = std::make_unique<gchar*>(vte_terminal_get_selection(vte));
if (selection && *selection) {
launch_browser(browser, selection.get());
launch_browser(browser, *selection.get());
}
} else {
g_printerr("no browser to open url\n");
@ -1183,21 +1182,21 @@ gboolean position_overlay_cb(GtkBin *overlay, GtkWidget *widget, GdkRectangle *a
gboolean button_press_cb(VteTerminal *vte, GdkEventButton *event, const config_info *info) {
if (info->clickable_url && event->type == GDK_BUTTON_PRESS) {
#if VTE_CHECK_VERSION (0, 49, 1)
auto match = make_unique(vte_terminal_hyperlink_check_event(vte, (GdkEvent*)event), g_free);
auto match = std::make_unique<gchar*>(vte_terminal_hyperlink_check_event(vte, (GdkEvent*)event));
if (!match) {
match = make_unique(check_match(vte, event), g_free);
match = std::make_unique<gchar*>(check_match(vte, event));
}
#else
auto match = make_unique(check_match(vte, event), g_free);
auto match = std::make_unique<gchar*>(check_match(vte, event));
#endif
if (!match)
return FALSE;
if (event->button == 1) {
launch_browser(info->browser, match.get());
launch_browser(info->browser, *match.get());
} else if (event->button == 3) {
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, match.get(), -1);
gtk_clipboard_set_text(clipboard, *match.get(), -1);
}
return TRUE;