std::messag...ges::do_get(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::messag...ges::do_get(3) πŸŽ€

okay bestie so this little page lives in the C++ Standard Libary manual and it's all about std::messages::get and std::messages::do_get β€” the message-catalog girlies. i18n slay, no cap ✨


🌸 NAME 🌸

std::messages::get, std::messages::do_get β€” literally the exact same two names, that's the whole NAME section, we move πŸ’…

std::messages::get, std::messages::do_get


✨ Synopsis ✨

Defined in header <locale>, bestie:

public:
string_type get( catalog cat, int set, int msgid, const string_type&
dfault )   (1)
const;
protected:
virtual string_type do_get( catalog cat, int set, int msgid, const
string_type& (2)
dfault ) const;
  1. the public member function β€” it just calls the protected virtual member function do_get of the most derived class 🫢
  2. the actual worker β€” it obtains a message from the open message catalog cat, using the values set, msgid and dfault in an implementation-defined manner. and if the expected message is not found in the catalog, it returns a copy of dfault. periodt πŸ’–

πŸ¦‹ Parameters πŸ¦‹

  • cat β€” identifier of message catalog obtained from open() and not yet passed to close() πŸ‘‘ (do not be messy about this)
  • set β€” implementation-defined argument, message set in POSIX
  • msgid β€” implementation-defined argument, message id in POSIX
  • dfault β€” the string to look up in the catalog (if the catalog uses string look-up) and also the string to return in case of a failure. she's doing double duty, main character energy fr fr 🌟

🌈 Return value 🌈

The message from the catalog, or a copy of dfault if none was found. simple as that πŸ“


πŸ’œ Notes πŸ’œ

On POSIX systems, this function call usually translates to a call to catgets(), and the parameters set, msgid, and dfault are passed to catgets() as-is. iconic, no notes 😌

In GNU libstdc++, this function ignores set and msgid and simply calls GNU gettext(dfault) in the required locale. the way that it just does its own thing πŸ˜­πŸ’€


🧚 Example 🧚

The following example demonstrated retrieval of messages: on a typical GNU/Linux system it reads from /usr/share/locale/de/LC_MESSAGES/sed.mo. lowkey obsessed with how specific that is πŸŽ€

// Run this code

#include <iostream>
#include <locale>

int main()
{
    std::locale loc("de_DE.utf8");
    std::cout.imbue(loc);
    auto& facet = std::use_facet<std::messages<char>>(loc);
    auto cat = facet.open("sed", loc);
    if (cat < 0)
        std::cout << "Could not open german \"sed\" message catalog\n";
    else
        std::cout << "\"No match\" in German: "
                  << facet.get(cat, 0, 0, "No match") << '\n'
                  << "\"Memory exhausted\" in German: "
                  << facet.get(cat, 0, 0, "Memory exhausted") << '\n';
    facet.close(cat);
}

Possible output:

"No match" in German: Keine Übereinstimmung
"Memory exhausted" in German: Speicher erschΓΆpft

she ate that 🍽️πŸ”₯


⭐ See also ⭐

ngl this section as printed doesn't list any cross-reference entries β€” it's giving empty, but we're keeping the heading because we keep everything, iykyk πŸ™ˆπŸ’…


and that's the whole page, bestie 🫢 β€” brought to you by http://cppreference.com, edition 2024.06.10, filed under std::messag...ges::do_get(3). go read a message catalog, ily πŸ’–βœ¨

πŸ“¦ where this page comes from