line, lines all around, feel bad at naming things
public class Line
{
public int count;
public List<string> lines;
public List<int> indexes;
public Line()
{
count = 0;
lines = new List<string>(){};
indexes = new List<int>();
}
public Line( string line, int index )
{
count = 1;
lines = new List<string>(){ line };
indexes = new List<int>( index );
}
public void AddLine( string line, int index )
{
lines.Add( line );
indexes.Add( index );
count++;
}
}
public class TextProcessor
{
public Dictionary<string, Line> data;
public string[] keys;
public Line[] lines;
public void ProcessFile(string file , string[] words)
{
data = new Dictionary<string, Line>();
var spaces = new char[]{' ',' ','\r','\n'};
string[] lines = File.ReadAllLines(file);
if (lines != null)
{
int line_index = 0;
string word;
foreach(string line in lines)
{
line_index++;
// #1
//word = line.TrimStart(spaces).Split()[0].ToLower();
// #2
word = line.TrimStart(spaces);
int len = word.IndexOfAny( spaces );
word = word.Substring( 0, len < 0 ? word.Length : len ).ToLower();
// #3
//var chars = line.ToCharArray();
//int f1 = Array.FindIndex(chars, x => !char.IsWhiteSpace(x));
//if ( f1 < 0 ) continue;
//int f2 = Array.FindIndex(chars, f1, x => char.IsWhiteSpace(x));
//word = line.Substring( f1, f2 - f1 ).ToLower();
if (data.ContainsKey(word))
{
data[word].AddLine( line, line_index );
}
else
{
data[word] = new Line( line, line_index );
}
}
}
keys = new string[data.Keys.Count];
data.Keys.CopyTo(keys, 0);
this.lines = new Line[data.Values.Count];
data.Values.CopyTo(this.lines, 0);
}
}