コード例 #1
0
ファイル: wutil.cpp プロジェクト: JanKanis/fish-shell
wcstring wgettext2(const wcstring &in)
{
    wgettext_init_if_necessary();
    std::string mbs_in = wcs2string(in);
    char *out = gettext(mbs_in.c_str());
    wcstring result = format_string(L"%s", out);
    return result;
}
コード例 #2
0
ファイル: wutil.cpp プロジェクト: scorphus/fish-shell
const wcstring &wgettext(const wchar_t *in) {
    // Preserve errno across this since this is often used in printing error messages.
    int err = errno;
    wcstring key = in;

    wgettext_init_if_necessary();
    auto wmap = wgettext_map.acquire();
    wcstring &val = wmap.value[key];
    if (val.empty()) {
        cstring mbs_in = wcs2string(key);
        char *out = fish_gettext(mbs_in.c_str());
        val = format_string(L"%s", out);
    }
    errno = err;

    // The returned string is stored in the map.
    // TODO: If we want to shrink the map, this would be a problem.
    return val;
}
コード例 #3
0
ファイル: wutil.cpp プロジェクト: jeffxr/fish-shell
const wchar_t *wgettext(const wchar_t *in)
{
    if (!in)
        return in;

    // preserve errno across this since this is often used in printing error messages
    int err = errno;

    wgettext_init_if_necessary();

    wcstring key = in;
    scoped_lock lock(wgettext_lock);

    wcstring *& val = wgettext_map[key];
    if (val == NULL)
    {
        cstring mbs_in = wcs2string(key);
        char *out = gettext(mbs_in.c_str());
        val = new wcstring(format_string(L"%s", out));
    }
    errno = err;
    return val->c_str();
}
コード例 #4
0
ファイル: wutil.cpp プロジェクト: FUNK88/fish-shell
const wchar_t *wgettext(const wchar_t *in)
{
    if (!in)
        return in;

    // preserve errno across this since this is often used in printing error messages
    int err = errno;

    wgettext_init_if_necessary();

    wcstring key = in;
    scoped_lock lock(wgettext_lock);

    wcstring *& 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!
    }
    errno = err;
    return val->c_str(); //looks dangerous but is safe, since the string is stored in the map
}