DtsodV23 fixed

This commit is contained in:
timerix 2022-09-26 20:43:38 +06:00
parent b2f1b7cb36
commit dde887f1d1

View File

@ -73,7 +73,7 @@ public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
case ']': case ']':
case '{': case '{':
case '}': case '}':
throw new Exception($"DtsodV23.Deserialize() error: unexpected {c}"); throw new Exception($"unexpected {c}");
default: default:
b.Append(c); b.Append(c);
break; break;
@ -98,7 +98,7 @@ public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
{ {
prevIsBackslash = c == '\\' && !prevIsBackslash; prevIsBackslash = c == '\\' && !prevIsBackslash;
b.Append(c); b.Append(c);
if (++i >= text.Length) throw new Exception("DtsodV23.Deserialize() error: end of text\ntext:\n" + _text); if (++i >= text.Length) throw new Exception("end of text\ntext:\n" + _text);
c = text[i]; c = text[i];
} }
b.Append('"'); b.Append('"');
@ -107,9 +107,11 @@ public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
DtsodV23 ReadDtsod() DtsodV23 ReadDtsod()
{ {
short bracketBalance = 1; short bracketBalance = 1;
c = text[++i]; //пропускает начальный символ '{'
while (bracketBalance != 0) while (bracketBalance != 0)
{ {
if (++i >= text.Length) //пропускает начальный символ '{'
throw new Exception("end of text\ntext:\n" + _text);
c = text[i];
switch (c) switch (c)
{ {
case ' ': case ' ':
@ -136,9 +138,6 @@ public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
b.Append(c); b.Append(c);
break; break;
} }
if (++i >= text.Length) throw new Exception("DtsodV23.Deserialize() error: end of text\ntext:\n" + _text);
c = text[i];
} }
var __text = b.ToString(); var __text = b.ToString();
@ -217,6 +216,7 @@ public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
}; };
} }
object value = null;
while (++i < text.Length) while (++i < text.Length)
{ {
c = text[i]; c = text[i];
@ -236,32 +236,32 @@ public class DtsodV23 : DtsodDict<string, dynamic>, IDtsod
case '\'': case '\'':
b.Append(c).Append(text[++i]); b.Append(c).Append(text[++i]);
c = text[++i]; c = text[++i];
if (c != '\'') throw new Exception("after <\'> should be char"); if (c != '\'')
else b.Append(c); throw new Exception("after <\'> should be char");
b.Append(c);
break; break;
case ';': case ';':
case ',': case ',':
if(b.Length == 0) if(b.Length == 0)
{ return value;
if(endOfList)
return null;
throw new Exception("zero length value");
}
string str = b.ToString(); string str = b.ToString();
b.Clear(); b.Clear();
return ParseValue(str); return ParseValue(str);
case '[': case '[':
return ReadList(); value=ReadList();
goto case ';';
break;
case ']': case ']':
endOfList = true; endOfList = true;
break; break;
case '{': case '{':
return ReadDtsod(); value=ReadDtsod();
break;
case '=': case '=':
case ':': case ':':
case '}': case '}':
case '$': case '$':
throw new Exception($"DtsodV23.Deserialize() error: unexpected {c}"); throw new Exception($"unexpected {c}");
default: default:
b.Append(c); b.Append(c);
break; break;