private static ProcessLineState ProcessComment(IniTextBuffer buffer, IniData iniData) { IniLineRange range = buffer.Range.DeepCopy(); buffer.TrimStart(range); if (!buffer.IsStartWith(range, schemeStyle.CommentString)) { return(ProcessLineState.Unrecognized); } if (!readerStyle.IsParseComments) { return(ProcessLineState.Success); } int startIndex = buffer.FindString(range, schemeStyle.CommentString) + schemeStyle.CommentString.Length; int endIndex = range.End; range.Start = startIndex; range.Size = endIndex - startIndex + 1; if (readerStyle.IsTrimComments) { buffer.Trim(range); } string comment = buffer.GetString(range); tempComments.Add(comment); return(ProcessLineState.Success); }
private static ProcessLineState ProcessOptionalValue(IniTextBuffer buffer, IniData iniData) { IniLineRange range = buffer.Range.DeepCopy(); buffer.Trim(range); if (!buffer.IsStartWith(range, schemeStyle.OptionalValueStartString)) { return(ProcessLineState.Unrecognized); } if (!buffer.IsEndWith(range, schemeStyle.OptionalValueEndString)) { if (!readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException($"Error:No closing option value({schemeStyle.OptionalValueEndString}). ", buffer.LineNumber, buffer.LineContent); } if (!readerStyle.IsParseOptionalValues) { return(ProcessLineState.Success); } int startIndex = range.Start + schemeStyle.OptionalValueStartString.Length; int endIndex = range.End - schemeStyle.OptionalValueEndString.Length; range.Start = startIndex; range.Size = endIndex - startIndex + 1; string optionalValueStr = buffer.GetString(range); if (string.IsNullOrEmpty(optionalValueStr)) { if (!readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException($"Error:The value of optionalValue is empty. ", buffer.LineNumber, buffer.LineContent); } string[] optionalValues = optionalValueStr.Split(new string[] { schemeStyle.OptionalValueAssigmentString }, StringSplitOptions.RemoveEmptyEntries); if (readerStyle.IsTrimOptionalValues) { foreach (var v in optionalValues) { string trimedValue = v.Trim(); if (!string.IsNullOrEmpty(trimedValue)) { tempOptionalValues.Add(trimedValue); } } } else { tempOptionalValues.AddRange(optionalValues); } return(ProcessLineState.Success); }
private static ProcessLineState ProcessSection(IniTextBuffer buffer, IniData iniData) { IniLineRange range = buffer.Range.DeepCopy(); buffer.Trim(range); if (!buffer.IsStartWith(range, schemeStyle.SectionStartString)) { return(ProcessLineState.Unrecognized); } if (!buffer.IsEndWith(range, schemeStyle.SectionEndString)) { if (!readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException($"Error:No closing section value({schemeStyle.SectionEndString}). ", buffer.LineNumber, buffer.LineContent); } int startIndex = range.Start + schemeStyle.SectionStartString.Length; int endIndex = range.End - schemeStyle.SectionEndString.Length; range.Start = startIndex; range.Size = endIndex - startIndex + 1; if (readerStyle.IsTrimSections) { buffer.Trim(range); } string sectionName = buffer.GetString(range); if (string.IsNullOrEmpty(sectionName)) { if (!readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException($"Error:The name of section is empty. ", buffer.LineNumber, buffer.LineContent); } tempSectionName = sectionName; IniSection section = iniData.AddSection(tempSectionName); if (readerStyle.IsParseComments && tempComments.Count > 0) { section.Comments = tempComments; tempComments.Clear(); } return(ProcessLineState.Success); }