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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169 | #include "fsCStringsFile.h"
#include <fsCore/fsIResourceNamePathAdjuster.h>
#include "../fsIFile.h"
#include "debug/fsAssert.h"
const fsStr fsCStringsFile::mRowOpenTag = "<Row";
const fsStr fsCStringsFile::mRowCloseTag = "</Row>";
const fsStr fsCStringsFile::mCellOpenTag = "<Cell";
const fsStr fsCStringsFile::mCellCloseTag = "</Cell>";
const fsStr fsCStringsFile::mStringPropertyTag = "ss:Type=\"String\"";
const fsStr fsCStringsFile::mNumberPropertyTag = "ss:Type=\"Number\"";
const fsStr fsCStringsFile::mEllipsisChar(0x2026u);
void fsCStringsFile::read()
{
read(mSrcFilename, this);
}
void fsCStringsFile::read(const fsStr& pFileName, fsCVariableTable* pStrings)<--- The member function 'fsCStringsFile::read' can be static.
{
std::vector<fsStr> lines = fsIFile::textFileReadToVector(
fsCResourceName(pFileName, fsCResourceName::eRES_LOCATION_LOG));
std::vector<fsStr>::iterator line = lines.begin();
fsStr key;
fsStr value;
while (nextKeyGet(key, lines, line))
{
nextValueGet(value, lines, line);
if (!key.emptyGet())
{
//value.formattingRemove();
value.replaceAll(mEllipsisChar, "...");
pStrings->strSet(key, value);
}
// fsCLogMsg(key + ": " + value + "\n");
}
}
fsBool fsCStringsFile::nextKeyGet(fsStr& pOutStr, std::vector<fsStr>& pLines, std::vector<fsStr>::iterator& pLine)
{
fsBool done = false;
fsBool found = false;
while (!done)
{
if (pLine != pLines.end())
{
pOutStr = *pLine;
++pLine;
if (fsStr::npos != pOutStr.find(mRowOpenTag))
{
found = nextValueGet(pOutStr, pLines, pLine);
done = true;
}
}
else
{
done = true;
}
}
return found;
}
fsBool fsCStringsFile::nextValueGet(fsStr& pOutStr, std::vector<fsStr>& pLines, std::vector<fsStr>::iterator& pLine)<--- Parameter 'pLines' can be declared as reference to const
{
fsBool found = false;
while (!found)
{
if (pLine != pLines.end())
{
pOutStr = *pLine;
++pLine;
if (fsStr::npos != pOutStr.find(mRowCloseTag))
{
pOutStr = "";
return false;
}
// Strip leading whitespace
while (pOutStr[0] == ' ' || pOutStr[0] == '\t')
{
pOutStr.erase(0, 1);
}
// Early exit if there's no string in the cell, or no cell
fsS32 strTagPos = pOutStr.find(mStringPropertyTag);
fsS32 numTagPos = pOutStr.find(mNumberPropertyTag);
fsS32 cellTagPos = pOutStr.find(mCellOpenTag);
if ((fsStr::npos == strTagPos && fsStr::npos == numTagPos) || fsStr::npos == cellTagPos)
{
pOutStr = "";
return true;
}
if (fsStr::npos != strTagPos)
{
pOutStr.erase(0, strTagPos + mStringPropertyTag.dataSizeGet());
}
else if (fsStr::npos != numTagPos)
{
pOutStr.erase(0, strTagPos + mNumberPropertyTag.dataSizeGet());
}
pOutStr.erase(0, pOutStr.find('>') + 1);
// Strip any other leading xml tags
while (pOutStr[0] == '<')
{
fsS32 closeTagPos;
do
{
closeTagPos = pOutStr.find('>');
if (fsStr::npos == closeTagPos)
{
pOutStr = *pLine;
++pLine;
}
else
{
pOutStr.erase(0, closeTagPos + 1);
}
}
while (fsStr::npos == closeTagPos);
}
fsS32 tagPos = pOutStr.find('<');
if (fsStr::npos != tagPos)
{
pOutStr.erase(tagPos);
}
found = true;
}
else
{
pOutStr = "";
return false;
}
}
return true;
}
void fsCStringsFile::write()
{
fsStr outFn = mSrcFilename;
outFn.erase(0, outFn.rfind(fsIResourceNamePathAdjuster::mPathSeparator) + 1);
outFn.erase(outFn.rfind('.'));
outFn += ".txt";
save(fsCResourceName(mOutPath + outFn, fsCResourceName::eRES_LOCATION_LOG));
}
fsCStringsFile::fsCStringsFile() :
fsCVariableTable()
{
}
fsCStringsFile::~fsCStringsFile()
{
}
|