mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
utils: c++11
This commit is contained in:
@@ -32,16 +32,16 @@
|
||||
std::string utf8_to_locale_ign_err(const std::string& utf8_str)
|
||||
{
|
||||
gsize bytes_read, bytes_written;
|
||||
GError *err=NULL;
|
||||
GError *err=nullptr;
|
||||
std::string res;
|
||||
|
||||
const char * charset;
|
||||
if (g_get_charset(&charset))
|
||||
res=utf8_str;
|
||||
else {
|
||||
gchar *tmp=g_convert_with_fallback(utf8_str.c_str(), -1, charset, "UTF-8", NULL,
|
||||
gchar *tmp=g_convert_with_fallback(utf8_str.c_str(), -1, charset, "UTF-8", nullptr,
|
||||
&bytes_read, &bytes_written, &err);
|
||||
if (NULL==tmp){
|
||||
if (nullptr==tmp){
|
||||
fprintf(stderr, _("Can not convert %s to current locale.\n"), utf8_str.c_str());
|
||||
fprintf(stderr, "%s\n", err->message);
|
||||
g_error_free(err);
|
||||
@@ -56,14 +56,14 @@ std::string utf8_to_locale_ign_err(const std::string& utf8_str)
|
||||
|
||||
char *locale_to_utf8(const char *loc_str)
|
||||
{
|
||||
if(NULL==loc_str)
|
||||
return NULL;
|
||||
if(nullptr==loc_str)
|
||||
return nullptr;
|
||||
gsize bytes_read;
|
||||
gsize bytes_written;
|
||||
GError *err=NULL;
|
||||
gchar *str=NULL;
|
||||
GError *err=nullptr;
|
||||
gchar *str=nullptr;
|
||||
str=g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, &err);
|
||||
if(NULL==str){
|
||||
if(nullptr==str){
|
||||
fprintf(stderr, _("Can not convert %s to utf8.\n"), loc_str);
|
||||
fprintf(stderr, "%s\n", err->message);
|
||||
g_error_free(err);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _UTILS_HPP_
|
||||
#define _UTILS_HPP_
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
#include <string>
|
||||
@@ -7,10 +6,12 @@
|
||||
template <typename T, typename unref_res_t, void (*unref_res)(unref_res_t *)>
|
||||
class ResourceWrapper {
|
||||
public:
|
||||
ResourceWrapper(T *p = NULL) : p_(p) {}
|
||||
ResourceWrapper(T *p = nullptr) : p_(p) {}
|
||||
~ResourceWrapper() { free_resource(); }
|
||||
ResourceWrapper(const ResourceWrapper&) = delete;
|
||||
ResourceWrapper& operator=(const ResourceWrapper&) = delete;
|
||||
T *operator->() const { return p_; }
|
||||
bool operator!() const { return p_ == NULL; }
|
||||
bool operator!() const { return p_ == nullptr; }
|
||||
|
||||
void reset(T *newp) {
|
||||
if (p_ != newp) {
|
||||
@@ -33,18 +34,18 @@ private:
|
||||
|
||||
// Helper for enabling 'if (sp)'
|
||||
struct Tester {
|
||||
Tester() {}
|
||||
private:
|
||||
void operator delete(void*);
|
||||
};
|
||||
Tester() {}
|
||||
private:
|
||||
void operator delete(void*);
|
||||
};
|
||||
public:
|
||||
// enable 'if (sp)'
|
||||
operator Tester*() const
|
||||
{
|
||||
if (!*this) return 0;
|
||||
static Tester t;
|
||||
return &t;
|
||||
}
|
||||
operator Tester*() const {
|
||||
if (!*this)
|
||||
return 0;
|
||||
static Tester t;
|
||||
return &t;
|
||||
}
|
||||
};
|
||||
|
||||
namespace glib {
|
||||
@@ -56,4 +57,3 @@ namespace glib {
|
||||
extern char *locale_to_utf8(const char *locstr);
|
||||
extern std::string utf8_to_locale_ign_err(const std::string& utf8_str);
|
||||
|
||||
#endif//!_UTILS_HPP_
|
||||
|
||||
Reference in New Issue
Block a user