The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
po_message.hpp
Go to the documentation of this file.
1// (C) Copyright 2015 - 2017 Christopher Beck
2
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef SPIRIT_PO_PO_MESSAGE_HPP_INCLUDED
7#define SPIRIT_PO_PO_MESSAGE_HPP_INCLUDED
8
9#include <boost/optional/optional.hpp>
10#include <string>
11#include <utility>
12#include <vector>
13
14namespace spirit_po {
15
16typedef std::pair<std::string, std::vector<std::string>> plural_and_strings_type;
17
18struct po_message {
19 boost::optional<std::string> context;
20 std::string id;
22
23 std::size_t line_no;
24
25 // Get the 'id_plural', 'strings' fields from the pair.
26 // It is arranged as a pair here to allow for simpler parsing with spirit attributes.
27 std::string & id_plural() { return plural_and_strings.first; }
28 const std::string & id_plural() const { return plural_and_strings.first; }
29
30 std::vector<std::string> & strings() { return plural_and_strings.second; }
31 const std::vector<std::string> & strings() const { return plural_and_strings.second; }
32
33 // Check if message is plural. We do this for now by testing msgid_plural.size().
34 // Recommended to use this method in case we change it in the future.
35 bool is_plural() const { return id_plural().size() > 0; }
36};
37
38/***
39 * Debug printer
40 */
41#ifdef SPIRIT_PO_DEBUG
42inline std::string debug_string(const po_message & msg) {
43 std::string result = "{\n";
44 if (msg.context) {
45 result += " context: \"" + *msg.context + "\"\n";
46 }
47 result += " id: \"" + msg.id + "\"\n";
48 result += " id_plural: \"" + msg.id_plural() + "\"\n";
49 result += " strings: { ";
50 for (uint i = 0; i < msg.strings().size(); ++i) {
51 if (i) { result += ", "; }
52 result += '"' + msg.strings()[i] + '"';
53 }
54 result += " }\n";
55 result += "}";
56 return result;
57}
58#endif // SPIRIT_PO_DEBUG
59
60} // end namespace spirit_po
61
62#endif // SPIRIT_PO_PO_MESSAGE_HPP_INCLUDED
unsigned int uint
Definition catalog.hpp:39
std::pair< std::string, std::vector< std::string > > plural_and_strings_type
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
Definition unicode.cpp:81
plural_and_strings_type plural_and_strings
const std::string & id_plural() const
boost::optional< std::string > context
bool is_plural() const
const std::vector< std::string > & strings() const
std::vector< std::string > & strings()
std::string & id_plural()
#define i