Files
vcmi/lib/CGeneralTextHandler.h
T

150 lines
5.3 KiB
C++
Raw Normal View History

/*
* CGeneralTextHandler.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
2013-10-27 13:05:01 +00:00
#include "JsonNode.h"
2013-10-25 21:45:14 +00:00
/// Namespace that provides utilites for unicode support (UTF-8)
namespace Unicode
{
/// evaluates size of UTF-8 character
size_t DLL_LINKAGE getCharacterSize(char firstByte);
2013-10-25 21:45:14 +00:00
/// test if character is a valid UTF-8 symbol
/// maxSize - maximum number of bytes this symbol may consist from ( = remainer of string)
bool DLL_LINKAGE isValidCharacter(const char * character, size_t maxSize);
2013-10-25 21:45:14 +00:00
/// test if text contains ASCII-string (no need for unicode conversion)
2013-11-09 13:49:36 +00:00
bool DLL_LINKAGE isValidASCII(const std::string & text);
bool DLL_LINKAGE isValidASCII(const char * data, size_t size);
2013-10-25 21:45:14 +00:00
/// test if text contains valid UTF-8 sequence
2013-11-09 13:49:36 +00:00
bool DLL_LINKAGE isValidString(const std::string & text);
bool DLL_LINKAGE isValidString(const char * data, size_t size);
2013-10-25 21:45:14 +00:00
/// converts text to unicode from specified encoding or from one specified in settings
2013-11-09 13:49:36 +00:00
std::string DLL_LINKAGE toUnicode(const std::string & text);
std::string DLL_LINKAGE toUnicode(const std::string & text, const std::string & encoding);
2013-10-25 21:45:14 +00:00
/// converts text from unicode to specified encoding or to one specified in settings
/// NOTE: usage of these functions should be avoided if possible
2013-11-09 13:49:36 +00:00
std::string DLL_LINKAGE fromUnicode(const std::string & text);
std::string DLL_LINKAGE fromUnicode(const std::string & text, const std::string & encoding);
///delete (amount) UTF characters from right
DLL_LINKAGE void trimRight(std::string & text, const size_t amount = 1);
2013-10-25 21:45:14 +00:00
};
2012-08-25 08:44:51 +00:00
class CInputStream;
/// Parser for any text files from H3
2013-11-09 13:49:36 +00:00
class DLL_LINKAGE CLegacyConfigParser
2012-08-25 08:44:51 +00:00
{
std::unique_ptr<char[]> data;
char * curr;
char * end;
void init(const std::unique_ptr<CInputStream> & input);
/// extracts part of quoted string.
std::string extractQuotedPart();
/// extracts quoted string. Any end of lines are ignored, double-quote is considered as "escaping"
std::string extractQuotedString();
/// extracts non-quoted string
std::string extractNormalString();
2013-10-25 21:45:14 +00:00
/// reads "raw" string without encoding conversion
std::string readRawString();
2012-08-25 08:44:51 +00:00
public:
/// read one entry from current line. Return ""/0 if end of line reached
std::string readString();
float readNumber();
2012-12-14 15:32:53 +00:00
template <typename numeric>
std::vector<numeric> readNumArray(size_t size)
{
std::vector<numeric> ret;
ret.reserve(size);
while (size--)
ret.push_back(readNumber());
return ret;
}
2012-08-25 08:44:51 +00:00
/// returns true if next entry is empty
2013-06-23 19:35:54 +00:00
bool isNextEntryEmpty() const;
2012-08-25 08:44:51 +00:00
/// end current line
bool endLine();
CLegacyConfigParser(std::string URI);
CLegacyConfigParser(const std::unique_ptr<CInputStream> & input);
};
class DLL_LINKAGE CGeneralTextHandler //Handles general texts
2009-01-10 22:08:18 +00:00
{
public:
2013-10-27 13:05:01 +00:00
JsonNode localizedTexts;
2009-01-10 22:08:18 +00:00
std::vector<std::string> allTexts;
std::vector<std::string> arraytxt;
std::vector<std::string> primarySkillNames;
std::vector<std::string> jktexts;
std::vector<std::string> heroscrn;
std::vector<std::string> overview;//text for Kingdom Overview window
std::vector<std::string> colors; //names of player colors ("red",...)
std::vector<std::string> capColors; //names of player colors with first letter capitalized ("Red",...)
std::vector<std::string> turnDurations; //turn durations for pregame (1 Minute ... Unlimited)
2009-01-10 22:08:18 +00:00
//towns
std::vector<std::string> tcommands, hcommands, fcommands; //texts for town screen, town hall screen and fort screen
std::vector<std::string> tavernInfo;
std::vector<std::string> tavernRumors;
2009-01-10 22:08:18 +00:00
2016-10-29 17:00:12 +02:00
std::vector<std::pair<std::string,std::string>> zelp;
2012-08-25 08:44:51 +00:00
std::vector<std::string> lossCondtions;
std::vector<std::string> victoryConditions;
//objects
std::vector<std::string> creGens; //names of creatures' generators
std::vector<std::string> creGens4; //names of multiple creatures' generators
std::vector<std::string> advobtxt;
std::vector<std::string> xtrainfo;
std::vector<std::string> restypes; //names of resources
2009-10-22 02:09:14 +00:00
std::vector<std::string> terrainNames;
2009-03-19 14:17:19 +00:00
std::vector<std::string> randsign;
2016-10-29 17:00:12 +02:00
std::vector<std::pair<std::string,std::string>> mines; //first - name; second - event description
2010-01-26 19:43:15 +00:00
std::vector<std::string> seerEmpty;
2016-10-29 17:00:12 +02:00
std::vector<std::vector<std::vector<std::string>>> quests; //[quest][type][index]
2009-12-31 11:43:37 +00:00
//type: quest, progress, complete, rollover, log OR time limit //index: 0-2 seer hut, 3-5 border guard
std::vector<std::string> seerNames;
2012-07-08 16:36:20 +00:00
std::vector<std::string> tentColors;
2009-01-10 22:08:18 +00:00
//sec skills
2009-01-10 22:08:18 +00:00
std::vector<std::string> levels;
std::vector<std::string> zcrexp; //more or less useful content of that file
2017-05-26 21:58:33 +02:00
//commanders
std::vector<std::string> znpc00; //more or less useful content of that file
2009-01-10 22:08:18 +00:00
2010-02-12 15:04:01 +00:00
//campaigns
2016-10-29 17:00:12 +02:00
std::vector<std::string> campaignMapNames;
std::vector<std::vector<std::string>> campaignRegionNames;
static void readToVector(std::string sourceName, std::vector<std::string> &dest);
2010-02-12 15:04:01 +00:00
int32_t pluralText(const int32_t textIndex, const int32_t count) const;
2009-01-10 22:08:18 +00:00
CGeneralTextHandler();
2016-10-29 17:00:12 +02:00
CGeneralTextHandler(const CGeneralTextHandler&) = delete;
CGeneralTextHandler operator=(const CGeneralTextHandler&) = delete;
2009-01-10 22:08:18 +00:00
};