mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
34 lines
850 B
C
34 lines
850 B
C
|
// Minetest
|
||
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||
|
|
||
|
#pragma once
|
||
|
#include <string_view>
|
||
|
#include <memory>
|
||
|
|
||
|
// Note that this only implements a subset of C expressions. See:
|
||
|
// https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-runtime/intl/plural.y
|
||
|
class GettextPluralForm
|
||
|
{
|
||
|
public:
|
||
|
using NumT = unsigned long;
|
||
|
using Ptr = std::shared_ptr<GettextPluralForm>;
|
||
|
|
||
|
size_t size() const
|
||
|
{
|
||
|
return nplurals;
|
||
|
};
|
||
|
virtual NumT operator()(const NumT) const = 0;
|
||
|
virtual operator bool() const
|
||
|
{
|
||
|
return size() > 0;
|
||
|
}
|
||
|
virtual ~GettextPluralForm() {};
|
||
|
|
||
|
static GettextPluralForm::Ptr parse(const size_t nplurals, const std::wstring_view &str);
|
||
|
static GettextPluralForm::Ptr parseHeaderLine(const std::wstring_view &str);
|
||
|
protected:
|
||
|
GettextPluralForm(size_t nplurals): nplurals(nplurals) {};
|
||
|
private:
|
||
|
const size_t nplurals;
|
||
|
};
|