use a wrapper to make std::unique_ptr less verbose
This commit is contained in:
		
							parent
							
								
									3d2c98b162
								
							
						
					
					
						commit
						506166230c
					
				
							
								
								
									
										11
									
								
								memory.hh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								memory.hh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					#ifndef MEMORY_HH
 | 
				
			||||||
 | 
					#define MEMORY_HH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template<typename T, typename Deleter>
 | 
				
			||||||
 | 
					std::unique_ptr<T, Deleter> make_unique(T *p, Deleter d) {
 | 
				
			||||||
 | 
					  return std::unique_ptr<T, Deleter>(p, d);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
@ -12,6 +12,7 @@
 | 
				
			|||||||
#include <vte/vte.h>
 | 
					#include <vte/vte.h>
 | 
				
			||||||
#include <vte/vteaccess.h>
 | 
					#include <vte/vteaccess.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "memory.hh"
 | 
				
			||||||
#include "url_regex.hh"
 | 
					#include "url_regex.hh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std::placeholders;
 | 
					using namespace std::placeholders;
 | 
				
			||||||
@ -133,7 +134,7 @@ static void find_urls(VteTerminal *vte, search_panel_info *panel_info) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void launch_url(const char *text, search_panel_info *info) {
 | 
					static void launch_url(const char *text, search_panel_info *info) {
 | 
				
			||||||
    std::unique_ptr<char, decltype(&free)> copy(strdup(text), free);
 | 
					    auto copy = make_unique(strdup(text), free);
 | 
				
			||||||
    for (char *s_ptr = copy.get(), *saveptr; ; s_ptr = nullptr) {
 | 
					    for (char *s_ptr = copy.get(), *saveptr; ; s_ptr = nullptr) {
 | 
				
			||||||
        const char *token = strtok_r(s_ptr, ",", &saveptr);
 | 
					        const char *token = strtok_r(s_ptr, ",", &saveptr);
 | 
				
			||||||
        if (!token) {
 | 
					        if (!token) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user