ScummVM API documentation
po_parser.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "common/str.h"
23#include "common/file.h"
24
25#ifndef COMMON_FORMATS_PO_PARSER_H
26#define COMMON_FORMATS_PO_PARSER_H
27
28namespace Common {
29
34public:
37
38 void insert(const char *msg);
39 int findIndex(const char *msg);
40
41 int size() const;
42 const char *operator[](int) const;
43
44private:
45 char **_messages;
46 int _size;
47 int _allocated;
48};
49
54 char *msgstr;
55 char *msgid;
56 char *msgctxt;
57
58 PlainPoMessageEntry(const char *translation, const char *message, const char *context = NULL) : msgstr(NULL), msgid(NULL), msgctxt(NULL) {
59 if (translation != NULL && *translation != '\0') {
60 size_t len = 1 + strlen(translation);
61 msgstr = new char[len];
62 Common::strlcpy(msgstr, translation, len);
63 }
64 if (message != NULL && *message != '\0') {
65 size_t len = 1 + strlen(message);
66 msgid = new char[len];
67 Common::strlcpy(msgid, message, len);
68 }
69 if (context != NULL && *context != '\0') {
70 size_t len = 1 + strlen(context);
71 msgctxt = new char[len];
72 Common::strlcpy(msgctxt, context, len);
73 }
74 }
76 delete[] msgstr;
77 delete[] msgid;
78 delete[] msgctxt;
79 }
80};
85public:
86 PlainPoMessageEntryList(const char *language);
88
89 void addMessageEntry(const char *translation, const char *message, const char *context = NULL);
90
91 const char *language() const;
92 const char *languageName() const;
93 bool useUTF8() const;
94
95 int size() const;
96 const PlainPoMessageEntry *entry(int) const;
97
98private:
99 char *_lang;
100 char *_langName;
101 char *_langNameAlt;
102
103 bool _useUTF8;
104
105 PlainPoMessageEntry **_list;
106 int _size;
107 int _allocated;
108};
109
110PlainPoMessageEntryList *parsePoFile(const char *file, PlainPoMessageList &);
111char *stripLine(char *);
112char *parseLine(const char *line, const char *field);
113
114} // End of namespace Common
115
116#endif // COMMON_FORMATS_PO_PARSER_H
Definition: po_parser.h:84
Definition: po_parser.h:33
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: algorithm.h:29
Definition: po_parser.h:53