private void FinalizeKeyValue(KVJ2D_Reader parser, ContextInfo context)
            {
                var key   = _currentKey.Trim();
                var value = _currentBody.Trim();

                List <KVJ2D_Data> list = null;

                if (!KeyValues.ContainsKey(key))
                {
                    list = new List <KVJ2D_Data>();
                    KeyValues.Add(key, list);
                }
                else
                {
                    list = KeyValues[key];
                }

                if (list.Count == 0 || parser._multiKeys)
                {
                    list.Add(new KVJ2D_Data(key, value));
                }
                else
                {
                    Debug.LogError($"Multiple same keys found {key}. Context: { context.Message }");
                }

                _currentKey  = "";
                _currentBody = "";
            }
            private void ProcessAwaitKey(KVJ2D_Reader parser, string trimmedLine, ContextInfo context)
            {
                //body starts here aswell:
                if (StringContainsAny(trimmedLine, parser._bodyStart))
                {
                    var splitted = trimmedLine.Split(parser._bodyStart, StringSplitOptions.RemoveEmptyEntries);
                    _currentKey = splitted[0].Trim();

                    _state = State.AwaitBodyEnd;

                    //also has some parts of the body here:
                    if (splitted.Length > 1)
                    {
                        Debug.Assert(splitted.Length == 2);
                        _currentBody = splitted[1].Trim();

                        //key and body is already complete in that line:
                        if (StringContainsAny(_currentBody, parser._bodyEnd))
                        {
                            _currentBody = ReplaceFromList(_currentBody, parser._bodyEnd, REPLACER).Trim();
                            FinalizeKeyValue(parser, context);
                            _state = State.AwaitKey;
                        }
                    }
                }
                else
                {
                    _currentKey = trimmedLine;
                    _state      = State.AwaitBodyStart;
                }
            }
 public void Process(KVJ2D_Reader parser, string trimmedLine, ContextInfo context)
 {
     if (_state == State.AwaitKey)
     {
         ProcessAwaitKey(parser, trimmedLine, context);
     }
     else if (_state == State.AwaitBodyStart)
     {
         ProcessAwaitBodyStart(parser, trimmedLine, context);
     }
     else if (_state == State.AwaitBodyEnd)
     {
         ProcessAwaitBodyEnd(parser, trimmedLine, context);
     }
 }
            private void ProcessAwaitBodyEnd(KVJ2D_Reader parser, string trimmedLine, ContextInfo context)
            {
                //either line starts or ends with bodyEnd string
                if (StringStartsWithAny(trimmedLine, parser._bodyEnd) || StringEndsWithAny(trimmedLine, parser._bodyEnd))
                {
                    AppendBody(ReplaceFromList(trimmedLine, parser._bodyEnd, REPLACER));

                    FinalizeKeyValue(parser, context);
                    _state = State.AwaitKey;
                }
                else
                {
                    //just part of the regular body;
                    AppendBody(trimmedLine);
                }
            }
            private void ProcessAwaitBodyStart(KVJ2D_Reader parser, string trimmedLine, ContextInfo context)
            {
                //we found the start of the body:
                if (StringStartsWithAny(trimmedLine, parser._bodyStart))
                {
                    _state = State.AwaitBodyEnd;

                    _currentBody = ReplaceFromList(trimmedLine, parser._bodyStart, REPLACER).Trim();

                    if (StringEndsWithAny(_currentBody, parser._bodyEnd))
                    {
                        _currentBody = ReplaceFromList(_currentBody, parser._bodyEnd, REPLACER).Trim();
                        _state       = State.AwaitKey;
                        FinalizeKeyValue(parser, context);
                    }
                }
            }