Mercurial > repos > IBBoard.Ini
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fbde5e1920ba |
---|---|
1 // This file (IniLineParser.cs) is a part of [SOME APPLICATION] and is copyright 2009 IBBoard. | |
2 // | |
3 // 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. | |
4 | |
5 using System; | |
6 | |
7 namespace IBBoard.Ini | |
8 { | |
9 public class IniLineParser | |
10 { | |
11 /// <summary> | |
12 /// 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. | |
13 /// If there are multiple equals signs the the key is split from the value on the first one | |
14 /// </summary> | |
15 /// <param name="line"> | |
16 /// A <see cref="System.String"/> | |
17 /// </param> | |
18 /// <returns> | |
19 /// A <see cref="System.String"/> | |
20 /// </returns> | |
21 public static string[] GetKeyValuePair(string line) | |
22 { | |
23 line = line.Trim(); | |
24 int idx = line.IndexOf('='); | |
25 string[] keyValuePair; | |
26 | |
27 if (idx > 0) | |
28 { | |
29 keyValuePair = SplitAtIndex(line, idx); | |
30 } | |
31 else | |
32 { | |
33 keyValuePair = new string[0]; | |
34 } | |
35 | |
36 return keyValuePair; | |
37 } | |
38 | |
39 private static string[] SplitAtIndex(string line, int idx) | |
40 { | |
41 string[] keyValuePair = new string[2]; | |
42 keyValuePair[0] = line.Substring(0, idx).Trim(); | |
43 keyValuePair[1] = line.Substring(idx+1).Trim(); | |
44 return keyValuePair; | |
45 } | |
46 } | |
47 } |