core: move gasname() to struct gasmix

Also, turn it to use std::string instead of writing into a
global(!) buffer. This was not reentrant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-07-02 12:38:36 +02:00 committed by bstoeger
parent 9c726d8d6f
commit 22a1120b30
14 changed files with 46 additions and 52 deletions

View file

@ -2,6 +2,7 @@
#include "gas.h"
#include "pref.h"
#include "errorhelper.h"
#include "format.h"
#include "gettext.h"
#include <stdio.h>
#include <string.h>
@ -183,3 +184,15 @@ const char *gastype_name(enum gastype type)
return "";
return translate("gettextFromC", gastype_names[type]);
}
std::string gasmix::name() const
{
if (gasmix_is_air(*this))
return translate("gettextFromC", "air");
else if (get_he(*this) == 0 && get_o2(*this) < 1000)
return format_string_std(translate("gettextFromC", "EAN%d"), (get_o2(*this) + 5) / 10);
else if (get_he(*this) == 0 && get_o2(*this) == 1000)
return translate("gettextFromC", "oxygen");
else
return format_string_std("(%d/%d)", (get_o2(*this) + 5) / 10, (get_he(*this) + 5) / 10);
}