Subversion Repositories spk

Rev

Rev 101 | Rev 254 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 101 Rev 197
Line 16... Line 16...
16
{
16
{
17
	if ( m_pTexts ) delete m_pTexts;
17
	if ( m_pTexts ) delete m_pTexts;
18
	if ( m_pTextComment ) delete m_pTextComment;
18
	if ( m_pTextComment ) delete m_pTextComment;
19
}
19
}
20
 
20
 
21
void CTextDB::parseTextFile(int iFromPage, int iToPage, const Utils::String &sFile, int iLang)
21
void CTextDB::parseTextFile(int iFromPage, int iToPage, const Utils::WString &sFile, int iLang)
22
{
22
{
23
	// open and read the text file
23
	// open and read the text file
24
	CFileIO File(sFile);
24
	CFileIO File(sFile);
25
	if ( File.startRead() ) {
25
	if ( File.startRead() ) {
26
		while ( !File.atEnd() ) {
26
		while ( !File.atEnd() ) {
27
			this->_parseFileLine(iFromPage, iToPage, iLang, File.readEndOfLine());
27
			this->_parseFileLine(iFromPage, iToPage, iLang, File.readEndOfLineStr());
28
		}
28
		}
29
		File.close();
29
		File.close();
30
 
30
 
31
	}
31
	}
32
	m_iInPage = 0;
32
	m_iInPage = 0;
Line 45... Line 45...
45
{
45
{
46
	TextListItr itr = m_pTexts->find(_mapID(iLang, iPage, iID));
46
	TextListItr itr = m_pTexts->find(_mapID(iLang, iPage, iID));
47
	if ( itr != m_pTexts->end() ) return true;
47
	if ( itr != m_pTexts->end() ) return true;
48
	return false;
48
	return false;
49
}
49
}
50
Utils::String CTextDB::get(int iPage, int iID) const
50
Utils::WString CTextDB::get(int iPage, int iID) const
51
{
51
{
52
	return this->get(m_iLang, iPage, iID);
52
	return this->get(m_iLang, iPage, iID);
53
}
53
}
54
Utils::String CTextDB::get(int iLang, int iPage, int iID) const
54
Utils::WString CTextDB::get(int iLang, int iPage, int iID) const
55
{
55
{
56
	TextListItr itr = m_pTexts->find(_mapID(iLang, iPage, iID));
56
	TextListItr itr = m_pTexts->find(_mapID(iLang, iPage, iID));
57
	if ( itr != m_pTexts->end() ) return _parseText(iLang, itr->second);
57
	if ( itr != m_pTexts->end() ) return _parseText(iLang, itr->second);
58
	return "";	
58
	return L"";	
59
}
59
}
60
 
60
 
61
bool CTextDB::anyTextLoaded() const
61
bool CTextDB::anyTextLoaded() const
62
{
62
{
63
	return !m_pTexts->empty();
63
	return !m_pTexts->empty();
64
}
64
}
65
 
65
 
66
Utils::String CTextDB::_parseText(int iLang, const Utils::String &sText, const Utils::String &sReplace) const
66
Utils::WString CTextDB::_parseText(int iLang, const Utils::WString &sText, const Utils::WString &sReplace) const
67
{
67
{
68
	Utils::String::size_type pos = sReplace.find_first_of(",", 0);
68
	Utils::WString::size_type pos = sReplace.find_first_of(L",", 0);
69
	if ( pos != Utils::String::npos ) {
69
	if ( pos != Utils::WString::npos ) {
70
		int iPage = Utils::String(sReplace.substr(1, pos));
70
		int iPage = Utils::WString(sReplace.substr(1, pos));
71
		int iID = Utils::String(sReplace.substr(pos + 1, sReplace.length() - pos - 2));
71
		int iID = Utils::WString(sReplace.substr(pos + 1, sReplace.length() - pos - 2));
72
		return sText.findReplace(sReplace, this->get(iLang, iPage, iID));
72
		return sText.findReplace(sReplace, this->get(iLang, iPage, iID));
73
	}
73
	}
74
 
74
 
75
	return sText;
75
	return sText;
76
}
76
}
77
 
77
 
78
Utils::String CTextDB::_parseText(int iLang, const Utils::String &sText) const
78
Utils::WString CTextDB::_parseText(int iLang, const Utils::WString &sText) const
79
{
79
{
80
	Utils::String sNewText = sText;
80
	Utils::WString sNewText = sText;
81
 
81
 
82
	Utils::String::size_type pos = sNewText.find_first_of("{", 0);
82
	Utils::WString::size_type pos = sNewText.find_first_of(L"{", 0);
83
	while ( pos != Utils::String::npos ) {
83
	while ( pos != Utils::WString::npos ) {
84
		Utils::String::size_type endPos = sNewText.find_first_of("}", pos);
84
		Utils::WString::size_type endPos = sNewText.find_first_of(L"}", pos);
85
		if ( endPos != Utils::String::npos ) {
85
		if ( endPos != Utils::WString::npos ) {
86
			sNewText = this->_parseText(iLang, sNewText, sNewText.substr(pos, (endPos - pos) + 1));
86
			sNewText = this->_parseText(iLang, sNewText, sNewText.substr(pos, (endPos - pos) + 1));
87
			pos = sNewText.find_first_of("{", 0);
87
			pos = sNewText.find_first_of(L"{", 0);
88
		}
88
		}
89
		else
89
		else
90
			pos = sNewText.find_first_of("{", pos);
90
			pos = sNewText.find_first_of(L"{", pos);
91
	}
91
	}
92
	return sNewText;
92
	return sNewText;
93
}
93
}
94
 
94
 
95
void CTextDB::_parseFileLine(int iFromPage, int iToPage, int iLang, const Utils::String &sLine)
95
void CTextDB::_parseFileLine(int iFromPage, int iToPage, int iLang, const Utils::WString &sLine)
96
{
96
{
97
	if ( m_iInPage ) {
97
	if ( m_iInPage ) {
98
		// check for end of page
98
		// check for end of page
99
		size_t pos = sLine.find("</page>");
99
		size_t pos = sLine.find(L"</page>");
100
		if ( pos != Utils::String::npos ) {
100
		if ( pos != Utils::WString::npos ) {
101
			m_iInPage = 0;
101
			m_iInPage = 0;
102
		}
102
		}
103
		else {
103
		else {
104
			this->_parsePage(iLang, sLine);
104
			this->_parsePage(iLang, sLine);
105
		}
105
		}
106
	}
106
	}
107
	else {
107
	else {
108
		size_t pos = sLine.find("<page id=\"");
108
		size_t pos = sLine.find(L"<page id=\"");
109
		if ( pos != Utils::String::npos ) {
109
		if ( pos != Utils::WString::npos ) {
110
			pos += 10; // move to the end of the search string (after ")
110
			pos += 10; // move to the end of the search string (after ")
111
			size_t endPos = sLine.find("\"", pos);
111
			size_t endPos = sLine.find(L"\"", pos);
112
			int iPageID = Utils::String(sLine.substr(pos, endPos - pos));
112
			int iPageID = Utils::WString(sLine.substr(pos, endPos - pos));
113
			iPageID %= 10000; // make sure we remove the game id
113
			iPageID %= 10000; // make sure we remove the game id
114
			//TODO: mark the game id so we can overright if the game id is the same or higher
114
			//TODO: mark the game id so we can overright if the game id is the same or higher
115
			if ( iFromPage > 0 && iPageID < iFromPage ) return; // out of range
115
			if ( iFromPage > 0 && iPageID < iFromPage ) return; // out of range
116
			if ( iToPage > 0 && iPageID > iToPage) return; // out of range
116
			if ( iToPage > 0 && iPageID > iToPage) return; // out of range
117
 
117
 
Line 120... Line 120...
120
	}
120
	}
121
}
121
}
122
 
122
 
123
 
123
 
124
 
124
 
125
void CTextDB::_parsePage(int iLang, const Utils::String &sLine)
125
void CTextDB::_parsePage(int iLang, const Utils::WString &sLine)
126
{
126
{
127
	// move to the id number
127
	// move to the id number
128
	size_t pos = sLine.find("<t id=\"");
128
	size_t pos = sLine.find(L"<t id=\"");
129
	if ( pos == Utils::String::npos ) return;
129
	if ( pos == Utils::WString::npos ) return;
130
		
130
		
131
	pos += 7; // move past to the "
131
	pos += 7; // move past to the "
132
	size_t endPos = sLine.find("\"", pos);
132
	size_t endPos = sLine.find(L"\"", pos);
133
	if ( endPos == Utils::String::npos ) return;
133
	if ( endPos == Utils::WString::npos ) return;
134
 
134
 
135
	// get the number to add
135
	// get the number to add
136
	int iID = Utils::String(sLine.substr(pos, endPos - pos));
136
	int iID = Utils::WString(sLine.substr(pos, endPos - pos));
137
	
137
	
138
	// now find the text
138
	// now find the text
139
	pos = sLine.find(">", endPos);
139
	pos = sLine.find(L">", endPos);
140
	if ( pos == Utils::String::npos ) return;
140
	if ( pos == Utils::WString::npos ) return;
141
	++pos;
141
	++pos;
142
	endPos = sLine.find("</t>", pos);
142
	endPos = sLine.find(L"</t>", pos);
143
	if ( endPos == Utils::String::npos ) return;
143
	if ( endPos == Utils::WString::npos ) return;
144
 
144
 
145
	this->_addText(iLang, iID, sLine.substr(pos, endPos - pos));
145
	this->_addText(iLang, iID, sLine.substr(pos, endPos - pos));
146
}
146
}
147
 
147
 
148
void CTextDB::_addText(int iLang, int iID, const Utils::String &sText)
148
void CTextDB::_addText(int iLang, int iID, const Utils::WString &sText)
149
{
149
{
150
	// split the comment out
150
	// split the comment out
151
	Utils::String fullComment;
151
	Utils::WString fullComment;
152
	Utils::String text = sText;
152
	Utils::WString text = sText;
153
 
153
 
154
	while ( text.isin("(") && text.isin(")") ) {
154
	while ( text.contains(L"(") && text.contains(L")") ) {
155
		int iStart = text.findPos("(");
155
		int iStart = text.findPos(L"(");
156
		if ( iStart != -1 ) {
156
		if ( iStart != -1 ) {
157
			int iEnd = text.findPos(")", iStart);
157
			int iEnd = text.findPos(L")", iStart);
158
			if ( iEnd != -1 ) {
158
			if ( iEnd != -1 ) {
159
				Utils::String comment = text.mid(iStart, ++iEnd);
159
				Utils::WString comment = text.mid(iStart, ++iEnd);
160
				text.erase(iStart, iEnd - iStart);
160
				text.erase(iStart, iEnd - iStart);
161
				if ( !fullComment.empty() ) fullComment += ", ";
161
				if ( !fullComment.empty() ) fullComment += L", ";
162
				fullComment += comment;
162
				fullComment += comment;
163
			}
163
			}
164
		}
164
		}
165
	}
165
	}
166
 
166
 
Line 169... Line 169...
169
	(*m_pTexts)[_mapID(iLang, m_iInPage, iID)] = text;
169
	(*m_pTexts)[_mapID(iLang, m_iInPage, iID)] = text;
170
	if ( !fullComment.empty() )
170
	if ( !fullComment.empty() )
171
		(*m_pTextComment)[_mapID(iLang, m_iInPage, iID)] = fullComment;
171
		(*m_pTextComment)[_mapID(iLang, m_iInPage, iID)] = fullComment;
172
}
172
}
173
 
173
 
174
Utils::String CTextDB::_mapID(int iLang, int iPage, int iID) const
174
Utils::WString CTextDB::_mapID(int iLang, int iPage, int iID) const
175
{
175
{
176
	Utils::String sID;
176
	Utils::WString sID;
177
	sID += (long)iLang;
177
	sID += (long)iLang;
178
	sID += ":";
178
	sID += L":";
179
	sID += (long)iPage;
179
	sID += (long)iPage;
180
	sID += ":";
180
	sID += L":";
181
	sID += (long)iID;
181
	sID += (long)iID;
182
 
182
 
183
	return sID;
183
	return sID;
184
}
184
}
185
 
185