File diff r18726:6d5849476f85 → r18727:ac3e3b151022
src/strings.cpp
Show inline comments
 
@@ -129,26 +129,26 @@ static char *FormatString(char *buff, co
 
struct LanguagePack : public LanguagePackHeader {
 
	char data[]; // list of strings
 
};
 

	
 
static char **_langpack_offs;
 
static LanguagePack *_langpack;
 
static uint _langtab_num[32];   ///< Offset into langpack offs
 
static uint _langtab_start[32]; ///< Offset into langpack offs
 
static uint _langtab_num[TAB_COUNT];   ///< Offset into langpack offs
 
static uint _langtab_start[TAB_COUNT]; ///< Offset into langpack offs
 
static bool _keep_gender_data = false;  ///< Should we retain the gender data in the current string?
 

	
 

	
 
const char *GetStringPtr(StringID string)
 
{
 
	switch (GB(string, 11, 5)) {
 
	switch (GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)) {
 
		/* GetGRFStringPtr doesn't handle 0xD4xx ids, we need to convert those to 0xD0xx. */
 
		case 26: return GetStringPtr(GetGRFStringID(0, 0xD000 + GB(string, 0, 10)));
 
		case 28: return GetGRFStringPtr(GB(string, 0, 11));
 
		case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
 
		case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
 
		default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
 
		case 26: return GetStringPtr(GetGRFStringID(0, 0xD000 + GB(string, TAB_SIZE_OFFSET, 10)));
 
		case 28: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
 
		case 29: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x0800);
 
		case 30: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x1000);
 
		default: return _langpack_offs[_langtab_start[GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)] + GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS)];
 
	}
 
}
 

	
 
/**
 
 * Get a parsed string with most special stringcodes replaced by the string parameters.
 
 * @param buffr  Pointer to a string buffer where the formatted string should be written to.
 
@@ -159,14 +159,14 @@ const char *GetStringPtr(StringID string
 
 * @return       Pointer to the final zero byte of the formatted string.
 
 */
 
char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index)
 
{
 
	if (string == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, args, last);
 

	
 
	uint index = GB(string,  0, 11);
 
	uint tab   = GB(string, 11,  5);
 
	uint index = GB(string, TAB_SIZE_OFFSET,  TAB_SIZE_BITS);
 
	uint tab   = GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS);
 

	
 
	switch (tab) {
 
		case 4:
 
			if (index >= 0xC0) {
 
				return GetSpecialTownNameString(buffr, index - 0xC0, args->GetInt32(), last);
 
			}
 
@@ -1533,19 +1533,19 @@ bool ReadLanguagePack(const LanguageMeta
 
	if (end <= lang_pack->data || !lang_pack->IsValid()) {
 
		free(lang_pack);
 
		return false;
 
	}
 

	
 
#if TTD_ENDIAN == TTD_BIG_ENDIAN
 
	for (uint i = 0; i < 32; i++) {
 
	for (uint i = 0; i < TAB_COUNT; i++) {
 
		lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
 
	}
 
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
 

	
 
	uint count = 0;
 
	for (uint i = 0; i < 32; i++) {
 
	for (uint i = 0; i < TAB_COUNT; i++) {
 
		uint num = lang_pack->offsets[i];
 
		_langtab_start[i] = count;
 
		_langtab_num[i] = num;
 
		count += num;
 
	}
 

	
 
@@ -1846,18 +1846,18 @@ class LanguagePackGlyphSearcher : public
 
	{
 
		return FS_NORMAL;
 
	}
 

	
 
	/* virtual */ const char *NextString()
 
	{
 
		if (this->i >= 32) return NULL;
 
		if (this->i >= TAB_COUNT) return NULL;
 

	
 
		const char *ret = _langpack_offs[_langtab_start[i] + j];
 

	
 
		this->j++;
 
		while (this->j >= _langtab_num[this->i] && this->i < 32) {
 
		while (this->j >= _langtab_num[this->i] && this->i < TAB_COUNT) {
 
			i++;
 
			j = 0;
 
		}
 

	
 
		return ret;
 
	}