aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/wutil.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-07-25 16:01:43 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-07-25 16:01:59 -0700
commitac72db8ef04ad2f467627f0f37b834acdfb01c87 (patch)
treec63f3c018e29e6882b069a22c38a539376835428 /src/wutil.cpp
parent9b4e365517f1509160aad36d769685d148a8c668 (diff)
Make our wgettext() implementation a little less terrifying
Use wchar_t* directly instead of wcstring.c_str()
Diffstat (limited to 'src/wutil.cpp')
-rw-r--r--src/wutil.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/wutil.cpp b/src/wutil.cpp
index 2faec257..7b6c5c71 100644
--- a/src/wutil.cpp
+++ b/src/wutil.cpp
@@ -56,9 +56,9 @@ const file_id_t kInvalidFileID = {(dev_t)-1LL, (ino_t)-1LL, (uint64_t)-1LL, -1,
/* Lock to protect wgettext */
static pthread_mutex_t wgettext_lock;
-/* Maps string keys to (immortal) pointers to string values */
-typedef std::map<wcstring, wcstring *> wgettext_map_t;
-static std::map<wcstring, wcstring *> wgettext_map;
+/* Maps string keys to (immortal) pointers to string values. */
+typedef std::map<wcstring, const wchar_t *> wgettext_map_t;
+static wgettext_map_t wgettext_map;
void wutil_init()
{
@@ -481,15 +481,16 @@ const wchar_t *wgettext(const wchar_t *in)
wcstring key = in;
scoped_lock lock(wgettext_lock);
- wcstring *& val = wgettext_map[key];
+ // Reference to pointer to string
+ const wchar_t *& val = wgettext_map[key];
if (val == NULL)
{
cstring mbs_in = wcs2string(key);
char *out = fish_gettext(mbs_in.c_str());
- val = new wcstring(format_string(L"%s", out)); //note that this writes into the map!
+ val = wcsdup(format_string(L"%s", out).c_str()); //note that this writes into the map!
}
errno = err;
- return val->c_str(); //looks dangerous but is safe, since the string is stored in the map
+ return val; //looks dangerous but is safe, since the string is stored in the map
}
int wmkdir(const wcstring &name, int mode)