You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

114 lines
3.5 KiB

namespace com.hitrust.trustpay.client
{
using System;
using System.Collections;
using System.IO;
using System.Text;
public class IniFileParser
{
private string iFileName;
private SortedList iKeyValue;
public IniFileParser(string aFileName)
{
this.iFileName = aFileName;
this.initial();
}
public virtual string getTag(int aIndex)
{
return (string) this.iKeyValue.GetKey(aIndex);
}
public virtual string getValue(int aIndex)
{
return (string) this.iKeyValue.GetByIndex(aIndex);
}
public virtual string getValue(string aTag)
{
if (!this.iKeyValue.Contains(aTag))
{
return null;
}
return (string) this.iKeyValue.GetByIndex(this.iKeyValue.IndexOfKey(aTag));
}
private void initial()
{
try
{
string str;
StreamReader reader = new StreamReader(this.iFileName);
StreamReader reader2 = new StreamReader(reader.BaseStream, Encoding.UTF7);
this.iKeyValue = new SortedList();
while ((str = reader2.ReadLine()) != null)
{
if (((str.Length > 0) && (str[0] != '#')) && ((str[0] != ';') && (str[0] != ' ')))
{
this.parsingLine(str);
}
}
reader2.Close();
}
catch (IOException exception)
{
Console.Out.WriteLine(exception);
}
}
[STAThread]
public static void Main(string[] arguments)
{
if (arguments.Length == 0)
{
Console.Out.WriteLine("Usage: java ReadSource [FileName].");
}
else
{
IniFileParser parser = new IniFileParser(arguments[0]);
Console.Out.WriteLine("HiTRUST Java Utilities Class - IniFileParser Testing");
Console.Out.WriteLine("Initial File Name = [" + arguments[0] + "]");
Console.Out.WriteLine("Number of Elements = [" + parser.numberOfElements() + "]");
for (int i = 0; i < parser.numberOfElements(); i++)
{
Console.Out.WriteLine("[" + parser.getTag(i) + "] - [" + parser.getValue(i) + "]");
}
}
}
public virtual int numberOfElements()
{
return this.iKeyValue.Keys.Count;
}
private void parsingLine(string aLine)
{
int index = aLine.IndexOf("=");
int startIndex = index + 1;
int length = aLine.Length;
for (int i = startIndex; i < length; i++)
{
if (((aLine[i] == '#') || (aLine[i] == ';')) || (aLine[i] == ' '))
{
length = i;
break;
}
if (aLine[i] == '"')
{
length = aLine.LastIndexOf("\"");
startIndex++;
break;
}
}
this.iKeyValue.Add(aLine.Substring(0, index), aLine.Substring(startIndex, length - startIndex));
}
public virtual void reload()
{
this.initial();
}
}
}