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 ProcessProperty(IniTextBuffer buffer, IniData iniData) { IniLineRange range = buffer.Range.DeepCopy(); buffer.TrimStart(range); int assigmentStartIndex = buffer.FindString(range, schemeStyle.PropertyAssigmentString); if (assigmentStartIndex < 0) { return(ProcessLineState.Unrecognized); } if (string.IsNullOrEmpty(tempSectionName)) { if (readerStyle.AllowKeysWithoutSection) { tempSectionName = IniData.GLOBAL_SECTION_NAME; } else { if (!readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException("Error:The section is not found for property", buffer.LineNumber, buffer.LineContent); } } IniLineRange keyRange = new IniLineRange(); keyRange.Start = range.Start; keyRange.Size = assigmentStartIndex - range.Start; buffer.Trim(keyRange); if (buffer.IsEmpty(keyRange)) { if (readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException("Error:The key of property is empty.", buffer.LineNumber, buffer.LineContent); } IniLineRange valueRange = new IniLineRange(); valueRange.Start = assigmentStartIndex + schemeStyle.PropertyAssigmentString.Length; valueRange.Size = range.End - valueRange.Start + 1; if (readerStyle.IsTrimProperties) { buffer.Trim(valueRange); } string propertyKey = buffer.GetString(keyRange); IniSection section = iniData.GetSection(tempSectionName, true); if (section.ContainsProperty(propertyKey)) { if (readerStyle.ThrowExceptionsOnError) { return(ProcessLineState.Error); } throw new IniReaderException("Error:The key of property is repeated.", buffer.LineNumber, buffer.LineContent); } string propertyValue = buffer.GetString(valueRange); IniProperty property = section.AddProperty(propertyKey, propertyValue); if (readerStyle.IsParseComments && tempComments.Count > 0) { property.Comments = tempComments; tempComments.Clear(); } if (readerStyle.IsParseOptionalValues && tempOptionalValues.Count > 0) { property.OptionalValues = tempOptionalValues; tempOptionalValues.Clear(); } return(ProcessLineState.Success); }