This commit is contained in:
Igor Pavlov
2014-11-23 00:00:00 +00:00
committed by Kornel Lesiński
parent 83f8ddcc5b
commit f08f4dcc3c
1158 changed files with 76451 additions and 35082 deletions

74
CPP/Common/TextConfig.cpp Executable file → Normal file
View File

@@ -3,22 +3,19 @@
#include "StdAfx.h"
#include "TextConfig.h"
#include "Defs.h"
#include "UTFConvert.h"
static bool IsDelimitChar(char c)
static inline bool IsDelimitChar(char c)
{
return (c == ' ' || c == 0x0A || c == 0x0D ||
c == '\0' || c == '\t');
return (c == ' ' || c == 0x0A || c == 0x0D || c == '\0' || c == '\t');
}
static AString GetIDString(const char *string, int &finishPos)
static AString GetIDString(const char *s, unsigned &finishPos)
{
AString result;
for (finishPos = 0; ; finishPos++)
{
char c = string[finishPos];
char c = s[finishPos];
if (IsDelimitChar(c) || c == '=')
break;
result += c;
@@ -26,89 +23,78 @@ static AString GetIDString(const char *string, int &finishPos)
return result;
}
static bool WaitNextLine(const AString &string, int &pos)
static bool WaitNextLine(const AString &s, unsigned &pos)
{
for (;pos < string.Length(); pos++)
if (string[pos] == 0x0A)
for (; pos < s.Len(); pos++)
if (s[pos] == 0x0A)
return true;
return false;
}
static bool SkipSpaces(const AString &string, int &pos)
static bool SkipSpaces(const AString &s, unsigned &pos)
{
for (;pos < string.Length(); pos++)
for (; pos < s.Len(); pos++)
{
char c = string[pos];
char c = s[pos];
if (!IsDelimitChar(c))
{
if (c != ';')
return true;
if (!WaitNextLine(string, pos))
if (!WaitNextLine(s, pos))
return false;
}
}
return false;
}
bool GetTextConfig(const AString &string, CObjectVector<CTextConfigPair> &pairs)
bool GetTextConfig(const AString &s, CObjectVector<CTextConfigPair> &pairs)
{
pairs.Clear();
int pos = 0;
unsigned pos = 0;
/////////////////////
// read strings
for (;;)
{
if (!SkipSpaces(string, pos))
if (!SkipSpaces(s, pos))
break;
CTextConfigPair pair;
int finishPos;
AString temp = GetIDString(((const char *)string) + pos, finishPos);
unsigned finishPos;
AString temp = GetIDString(((const char *)s) + pos, finishPos);
if (!ConvertUTF8ToUnicode(temp, pair.ID))
return false;
if (finishPos == 0)
return false;
pos += finishPos;
if (!SkipSpaces(string, pos))
if (!SkipSpaces(s, pos))
return false;
if (string[pos] != '=')
if (s[pos] != '=')
return false;
pos++;
if (!SkipSpaces(string, pos))
if (!SkipSpaces(s, pos))
return false;
if (string[pos] != '\"')
if (s[pos] != '\"')
return false;
pos++;
AString message;
for (;;)
{
if (pos >= string.Length())
if (pos >= s.Len())
return false;
char c = string[pos++];
char c = s[pos++];
if (c == '\"')
break;
if (c == '\\')
{
char c = string[pos++];
char c = s[pos++];
switch(c)
{
case 'n':
message += '\n';
break;
case 't':
message += '\t';
break;
case '\\':
message += '\\';
break;
case '\"':
message += '\"';
break;
default:
message += '\\';
message += c;
break;
case 'n': message += '\n'; break;
case 't': message += '\t'; break;
case '\\': message += '\\'; break;
case '\"': message += '\"'; break;
default: message += '\\'; message += c; break;
}
}
else
@@ -123,8 +109,8 @@ bool GetTextConfig(const AString &string, CObjectVector<CTextConfigPair> &pairs)
int FindTextConfigItem(const CObjectVector<CTextConfigPair> &pairs, const UString &id)
{
for (int i = 0; i < pairs.Size(); i++)
if (pairs[i].ID.Compare(id) == 0)
FOR_VECTOR (i, pairs)
if (pairs[i].ID == id)
return i;
return -1;
}