Mercurial > repos > IBBoard.Ini
view IniLineParser.cs @ 0:fbde5e1920ba
Re #6 (Ini parsing library) - Initial commit of IBBoard Ini parsing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 08 Jan 2009 20:33:56 +0000 |
parents | |
children | f9444f1786cd |
line wrap: on
line source
// This file (IniLineParser.cs) is a part of [SOME APPLICATION] and is copyright 2009 IBBoard. // // The file and the library/program it is in are licensed under the GNU LGPL license. Please see COPYING.LGPL for more information and the full license. using System; namespace IBBoard.Ini { public class IniLineParser { /// <summary> /// Gets a key-value pair of strings from a string in the INI settings format. If the line does not contain an equals then a zero-length array is returned. /// If there are multiple equals signs the the key is split from the value on the first one /// </summary> /// <param name="line"> /// A <see cref="System.String"/> /// </param> /// <returns> /// A <see cref="System.String"/> /// </returns> public static string[] GetKeyValuePair(string line) { line = line.Trim(); int idx = line.IndexOf('='); string[] keyValuePair; if (idx > 0) { keyValuePair = SplitAtIndex(line, idx); } else { keyValuePair = new string[0]; } return keyValuePair; } private static string[] SplitAtIndex(string line, int idx) { string[] keyValuePair = new string[2]; keyValuePair[0] = line.Substring(0, idx).Trim(); keyValuePair[1] = line.Substring(idx+1).Trim(); return keyValuePair; } } }