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.
96 lines
3.2 KiB
96 lines
3.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Collections;
|
|
using System.IO;
|
|
|
|
namespace n5coredll
|
|
{
|
|
class N5PropertyOper : System.Collections.Hashtable {
|
|
private string fileName = "";
|
|
private ArrayList list = new ArrayList();
|
|
public ArrayList List {
|
|
get { return list; }
|
|
set { list = value; }
|
|
}
|
|
public N5PropertyOper(string fileName) {
|
|
this.fileName = fileName;
|
|
this.Load(fileName);
|
|
}
|
|
|
|
public override void Add(object key, object value) {
|
|
base.Add(key, value);
|
|
list.Add(key);
|
|
|
|
}
|
|
|
|
public override ICollection Keys {
|
|
get {
|
|
return list;
|
|
}
|
|
}
|
|
|
|
private void Load(string filePath) {
|
|
char[] convertBuf = new char[1024];
|
|
int limit;
|
|
int keyLen;
|
|
int valueStart;
|
|
char c;
|
|
string bufLine = string.Empty;
|
|
bool hasSep;
|
|
bool precedingBackslash;
|
|
using (StreamReader sr = new StreamReader(filePath)) {
|
|
while (sr.Peek() >= 0) {
|
|
bufLine = sr.ReadLine();
|
|
limit = bufLine.Length;
|
|
keyLen = 0;
|
|
valueStart = limit;
|
|
hasSep = false;
|
|
precedingBackslash = false;
|
|
if (bufLine.StartsWith("#"))
|
|
keyLen = bufLine.Length;
|
|
while (keyLen < limit) {
|
|
c = bufLine[keyLen];
|
|
if ((c == '=' || c == ':') & !precedingBackslash) {
|
|
valueStart = keyLen + 1;
|
|
hasSep = true;
|
|
break;
|
|
}
|
|
else if ((c == ' ' || c == '\t' || c == '\f') & !precedingBackslash) {
|
|
valueStart = keyLen + 1;
|
|
break;
|
|
}
|
|
if (c == '\\') {
|
|
precedingBackslash = !precedingBackslash;
|
|
}
|
|
else {
|
|
precedingBackslash = false;
|
|
}
|
|
keyLen++;
|
|
}
|
|
while (valueStart < limit) {
|
|
c = bufLine[valueStart];
|
|
if (c != ' ' && c != '\t' && c != '\f') {
|
|
if (!hasSep && (c == '=' || c == ':')) {
|
|
hasSep = true;
|
|
}
|
|
else {
|
|
break;
|
|
}
|
|
}
|
|
valueStart++;
|
|
}
|
|
string key = bufLine.Substring(0, keyLen);
|
|
string values = bufLine.Substring(valueStart, limit - valueStart);
|
|
if (key == "")
|
|
key += "#";
|
|
while (key.StartsWith("#") & this.Contains(key)) {
|
|
key += "#";
|
|
}
|
|
this.Add(key, values);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|