Exemple #1
0
        public static string WriteToString(IniData iniData, IniSchemeStyle schemeStyle = null, IniWriterStyle writerStyle = null)
        {
            BeginWrite();

            TextWriter writer = new StringWriter(new StringBuilder());

            IniSection globalSection = iniData.GetSection(IniData.GLOBAL_SECTION_NAME, false);

            if (globalSection != null)
            {
                WriteSection(globalSection, writer);
            }
            foreach (var section in iniData)
            {
                if (section.Name != IniData.GLOBAL_SECTION_NAME)
                {
                    WriteSection(section, writer);
                }
            }

            EndWrite();

            writer.Flush();
            string iniString = writer.ToString();

            writer.Close();
            return(iniString);
        }
Exemple #2
0
        public static string WriteToString(IniConfig iniData, IniSchemeStyle schemeStyle = null, IniWriterStyle writerStyle = null)
        {
            IniWriter.schemeStyle = schemeStyle ?? new IniSchemeStyle();
            IniWriter.writerStyle = writerStyle ?? new IniWriterStyle();

            TextWriter writer         = new StringWriter(new StringBuilder());
            bool       isFirstSection = true;

            foreach (var section in iniData)
            {
                WriteSection(section, writer, isFirstSection);
                if (!isFirstSection)
                {
                    isFirstSection = false;
                }
            }

            writer.Flush();

            string iniString = writer.ToString();

            writer.Close();

            return(iniString);
        }
 private static void EndRead()
 {
     schemeStyle = null;
     readerStyle = null;
     tempComments.Clear();
     tempOptionalValues.Clear();
     tempSectionName = null;
     tempExceptions.Clear();
 }
Exemple #4
0
 private static void BeginWrite()
 {
     if (schemeStyle == null)
     {
         schemeStyle = new IniSchemeStyle();
     }
     if (writerStyle == null)
     {
         writerStyle = new IniWriterStyle();
     }
 }
Exemple #5
0
        public static IniConfig ReadFromString(string iniString, IniSchemeStyle schemeStyle = null, IniReaderStyle readerStyle = null)
        {
            if (string.IsNullOrEmpty(iniString))
            {
                return(null);
            }

            IniReader.schemeStyle = schemeStyle ?? new IniSchemeStyle();
            IniReader.readerStyle = readerStyle ?? new IniReaderStyle();
            cachedComments.Clear();
            cachedOptionalValues.Clear();
            cachedSectionName = null;

            textBuffer.Text = iniString;
            IniConfig    iniConfig = new IniConfig();
            IniLineRange iniLine   = new IniLineRange();

            int lineStartIndex = 0;

            while (textBuffer.ReadLine(lineStartIndex, ref iniLine))
            {
                lineStartIndex = iniLine.End + 1;
                if (textBuffer.IsContentWhitespace(iniLine))
                {
                    continue;
                }
                if (ProcessCommentLine(iniLine))
                {
                    continue;
                }
                if (ProcessSection(iniLine, out var section))
                {
                    iniConfig.AddSection(section);
                    section.Comments.AddRange(cachedComments);
                    cachedComments.Clear();
                    continue;
                }
                if (ProcessOptionalValue(iniLine))
                {
                    continue;
                }
                if (ProcessProperty(iniLine, out var property))
                {
                    property.Comments.AddRange(cachedComments);
                    property.OptionalValues.AddRange(cachedOptionalValues);

                    var s = iniConfig.GetSection(cachedSectionName);
                    s.AddProperty(property);
                    continue;
                }
            }

            return(iniConfig);
        }
 private static void BeginRead()
 {
     if (schemeStyle == null)
     {
         schemeStyle = new IniSchemeStyle();
     }
     if (readerStyle == null)
     {
         readerStyle = new IniReaderStyle();
     }
     tempComments.Clear();
     tempOptionalValues.Clear();
     tempSectionName = null;
     tempExceptions.Clear();
 }
        public static IniData ReadFromString(string iniString, IniSchemeStyle schemeStyle = null, IniReaderStyle readerStyle = null)
        {
            IniReader.schemeStyle = schemeStyle;
            IniReader.readerStyle = readerStyle;

            BeginRead();

            IniData iniData = new IniData();

            IniTextBuffer stringBuffer = new IniTextBuffer(iniString);

            while (stringBuffer.ReadLine())
            {
                try
                {
                    ProcessLine(stringBuffer, iniData);
                }
                catch (Exception e)
                {
                    tempExceptions.Add(e);

                    if (readerStyle.ThrowExceptionsOnError)
                    {
                        EndRead();

                        throw;
                    }
                }
            }

            if (tempExceptions.Count > 0)
            {
                iniData = null;
            }

            EndRead();

            return(iniData);
        }
Exemple #8
0
 private static void EndWrite()
 {
     schemeStyle = null;
     writerStyle = null;
 }