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); }
public TextIndexList Clone() { TextIndexList tl = new TextIndexList(); foreach (TextIndex t in this) { tl.Add(new TextIndex(t.Start, t.Length)); } return(tl); }
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); }