mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 11:14:58 -06:00
9.34
This commit is contained in:
committed by
Kornel Lesiński
parent
83f8ddcc5b
commit
f08f4dcc3c
74
CPP/Common/TextConfig.cpp
Executable file → Normal file
74
CPP/Common/TextConfig.cpp
Executable file → Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user