public static TextIndexList FromBitArray(BitArray bits, TextIndex index) { string bitString = BitArrayString(bits); TextIndexList tl = new TextIndexList(); int currentStart = -1; int lastBit = Math.Min(index.Start + index.Length, bits.Length); for (int i = index.Start; i < lastBit; i++) { if (bits[i]) { if (currentStart == -1) { currentStart = i; } } else { if (currentStart != -1) { tl.Add(TextIndex.FromStartEnd(currentStart, i)); currentStart = -1; } } } if (currentStart != -1) { tl.Add(TextIndex.FromStartEnd(currentStart, index.End)); } return(tl); }
/// <summary> /// Merges TextIndexes and sorts the textindexes /// </summary> public void Simplify() { BitArray ba = this.ToBitArray(); TextIndexList til = TextIndexList.FromBitArray(ba); this.Clear(); this.AddRange(til); }
public TextIndexList Clone() { TextIndexList tl = new TextIndexList(); foreach (TextIndex t in this) { tl.Add(new TextIndex(t.Start, t.Length)); } return(tl); }
public TextIndexList SubtractedFrom(TextIndexList tl) { int arraySize = Math.Max(this.Bounds.End, tl.Bounds.End); BitArray bArray = this.ToBitArray(arraySize); BitArray btlArray = tl.ToBitArray(arraySize); BitArray bXor = bArray.Xor(btlArray); return(TextIndexList.FromBitArray(btlArray.And(bXor))); }
public TextIndexList SymetricDifference(TextIndexList tl) { int arraySize = Math.Max(this.Bounds.End, tl.Bounds.End); BitArray bArray = this.ToBitArray(arraySize); BitArray btlArray = tl.ToBitArray(arraySize); BitArray bResult = bArray.Xor(btlArray); return(TextIndexList.FromBitArray(bResult)); }
public TextIndexList Intersection(TextIndexList tl) { int arraySize = Math.Max(this.Bounds.End, tl.Bounds.End); BitArray bArray = this.ToBitArray(arraySize); BitArray btlArray = tl.ToBitArray(arraySize); BitArray bResult = bArray.And(btlArray); return(TextIndexList.FromBitArray(bResult)); }
public static TextIndexList Parse(string value) { TextIndexList tl = new TextIndexList(); string[] strTextIndexes = value.Split(new string[1] { ":" }, StringSplitOptions.RemoveEmptyEntries); foreach (string strTextIndex in strTextIndexes) { string[] strSplit = strTextIndex.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries); if (strSplit.Length != 2) { throw new Exception("Bad format"); } else { tl.Add(new TextIndex(Int32.Parse(strSplit[0]), Int32.Parse(strSplit[1]))); } } return(tl); }
public TextIndex RangeDifferentFrom(TextIndexList tl) { TextIndexList diff = this.SymetricDifference(tl); return(diff.Bounds); }