-
Notifications
You must be signed in to change notification settings - Fork 6
/
MoParser.h
74 lines (56 loc) · 1.84 KB
/
MoParser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef Gettext_MoParser_H
#define Gettext_MoParser_H
#include <vector>
#ifdef _MSC_VER
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int32 uint64_t;
#else
#include <stdint.h>
#endif
struct GettextMessage {
char* string;
int length;
};
struct TranslatedMessage {
GettextMessage* original;
GettextMessage* translated;
};
typedef std::vector<TranslatedMessage*> TranslatedMessages;
class GettextMoParser {
public:
GettextMoParser();
~GettextMoParser();
bool parseFile(const char* filePath);
bool parse(char* moData);
void clearData();
GettextMessage* getTranslation(const char* originalString, int originalLength);
char* charset() const;
inline bool ready() const { return ready_; }
static const int32_t HEADER_MAGIC_NUMBER;
static const int32_t HEADER_MAGIC_NUMBER_SW;
private:
struct MoFileHeader {
int32_t magic; // offset +00: magic id
int32_t revision; // +04: revision
int32_t numStrings; // +08: number of strings in the file
int32_t offsetOriginalStrings; // +0C: start of original string table
int32_t offsetTranslatedStrings; // +10: start of translated string table
int32_t hashTableSize; // +14: hash table size
int32_t offsetHashTable; // +18: offset of hash table start
};
struct MoOffsetTableItem {
int32_t length; // length of the string
int32_t offset; // pointer to the string
};
int32_t swap_(int32_t ui) const;
bool swappedBytes_;
MoFileHeader* moFileHeader_;
char* moData_;
TranslatedMessages messages_;
mutable char* charset_;
mutable bool charsetParsed_;
bool ready_;
};
#endif // Gettext_MoParser_H