public virtual bool ReadNextTag(out SmFileAttribute tag)
        {
            _buffer.Clear();

            while (!_reader.EndOfStream)
            {
                if (_reader.Peek() != ':')
                {
                    _buffer.Append((char)_reader.Read());
                }
                else
                {
                    tag = _buffer.SkipWhile(c => c != '#').ToString().Trim('#').AsSmFileAttribute();

                    //if the tag could not be read, skip this tag and read the next one
                    if (tag == SmFileAttribute.UNDEFINED)
                    {
                        _reader.Read(); //toss ':' token
                        _buffer.Clear();
                        continue;
                    }

                    _lastReadTag = tag;
                    State        = tag == SmFileAttribute.NOTES ? ReaderState.ReadingChartMetadata : ReaderState.ReadingTagValue;
                    return(true);
                }
            }

            tag   = SmFileAttribute.UNDEFINED;
            State = ReaderState.Default;
            return(false);
        }
        internal SmFileReader(string smFilePath)
        {
            if (string.IsNullOrEmpty(smFilePath))
            {
                throw new ArgumentNullException(nameof(smFilePath), "*.sm file path cannot be null or empty");
            }

            _stream = new FileStream(smFilePath, FileMode.Open, FileAccess.Read);
            _reader = new StreamReader(_stream);
            _buffer = new StringBuilder();

            _lastReadTag = SmFileAttribute.UNDEFINED;

            FilePath = smFilePath;
            State    = ReaderState.Default;
        }
        public override bool ReadNextTag(out SmFileAttribute tag)
        {
            var success = base.ReadNextTag(out tag);

            if (success)
            {
                State = tag == SmFileAttribute.NOTEDATA
                    ? ReaderState.ReadingChartMetadata
                    : ReaderState.ReadingTagValue;
            }
            else
            {
                State = ReaderState.Default;
            }

            return(success);
        }
Beispiel #4
0
 public string this[SmFileAttribute attribute] =>
 Attributes.ContainsKey(attribute) ? Attributes[attribute] : string.Empty;