Menu

[327ada]: / Source / Tools / LangCheck / LangFile.cpp  Maximize  Restore  History

Download this file

70 lines (58 with data), 1.6 kB

 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
#include "LangFile.h"
LangFile::LangFile() {
}
LangFile::LangFile(const char* FileName) {
OpenFile(FileName);
}
LangFile::~LangFile() {
}
void LangFile::OpenFile(const char* FileName) {
FILE* file = fopen(FileName,"rb");
if(file) {
char linebuffer[512];
char textbuffer[512];
string formatspec = "csdioxXufFeEaAgGnp";
int ID;
while(fgets(linebuffer,512,file)) {
if(sscanf(linebuffer,"%d=%[^\r\n]",&ID,textbuffer) == 2) {
LangItem item;
item.ID = ID;
item.text = textbuffer;
item.formatspec = "";
// Find formatting specifiers
// Loop through format options
size_t pos = item.text.find('%',0);
while(pos != string::npos) {
item.formatspec += '%';
size_t offset = pos+1;
while(offset < item.text.length()) {
item.formatspec += item.text[offset];
// Stop at format specifier
if(formatspec.find(item.text[offset]) != string::npos) {
break;
}
offset++;
}
item.formatspec += ",";
pos = item.text.find('%',pos+1);
}
// Trim last ","
if(item.formatspec != "") {
item.formatspec = item.formatspec.substr(0,item.formatspec.length()-1);
}
// Add to list
contents.push_back(item);
}
}
Log("INFO: Found %d items in file %s\r\n",contents.size(),FileName);
fclose(file);
}
}
LangItem* LangFile::FindID(int ID) {
for(unsigned int i = 0; i < contents.size(); i++) {
if(contents[i].ID == ID) {
return &contents[i];
}
}
return NULL;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.