public bool MoveLeft() { leftChar = null; bool result = position > 0; rightChar = '\0'; if (result) { LineBlock block = blocks[blockI]; Line line = block.array[blockILine]; if (iChar == 0) { if (blockILine == 0) { blockI--; block = blocks[blockI]; blockILine = block.count - 1; } else { blockILine--; } line = block.array[blockILine]; iChar = line.charsCount - 1; } else { iChar--; } rightChar = line.chars[iChar].c; position--; } return(result); }
override public bool Init() { bool allow = false; for (int i = 0; i < lines.blocksCount && !allow; i++) { LineBlock block = lines.blocks[i]; for (int j = 0; j < block.count; j++) { if (block.array[j].GetRN() != lines.lineBreak) { allow = true; break; } } } if (!allow) { return(false); } linesLineBreak = lines.lineBreak; mementos = GetSelectionMementos(); return(true); }
public bool MoveRight() { bool result = position < charsCount; if (result) { leftChar = rightChar; rightChar = '\0'; LineBlock block = blocks[blockI]; Line line = block.array[blockILine]; if (iChar == line.charsCount - 1) { if (blockILine == block.count - 1) { if (blockI >= blocksCount - 1) { rightChar = '\0'; iChar++; position++; return(true); } blockI++; block = blocks[blockI]; blockILine = 0; } else { blockILine++; } line = block.array[blockILine]; iChar = 0; rightChar = line.charsCount > 0 ? line.chars[iChar].c : '\0'; } else { iChar++; rightChar = line.chars[iChar].c; } position++; } else { rightChar = '\0'; } return(result); }
public int GetWWILine(int iLine) { int blockI = lines.GetBlockIndex(iLine); if (blockI == -1) { return(-1); } LineBlock block = lines.blocks[blockI]; int iInBlock = iLine - block.offset; int wwOffset = block.wwOffset; for (int i = 0; i < iInBlock; i++) { wwOffset += block.array[i].cutOffs.count + 1; } return(wwOffset); }
public int GetLeftCharsCount(char c) { int count = 0; if (position > 0) { LineBlock block = blocks[blockI]; Line line = block.array[blockILine]; for (int iChar = this.iChar; iChar-- > 0;) { if (line.chars[iChar].c != c) { break; } ++count; } } return(count); }
public void Validate(int wwSizeX) { if (wwSizeX < 1) { wwSizeX = 1; } if (lines.wwSizeX != wwSizeX) { lines.wwSizeX = wwSizeX; for (int i = 0; i < lines.blocksCount; i++) { LineBlock block = lines.blocks[i]; if (block.wwSizeX != wwSizeX) { int blockSizeY = 0; block.wwSizeX = wwSizeX; for (int j = 0; j < block.count; j++) { Line line = block.array[j]; if (line.wwSizeX != wwSizeX) { line.CalcCutOffs(wwSizeX); } blockSizeY += line.cutOffs.count + 1; } block.wwSizeY = blockSizeY; } } int wwOffset = 0; for (int i = 0; i < lines.blocksCount; i++) { LineBlock block = lines.blocks[i]; block.wwOffset = wwOffset; wwOffset += block.wwSizeY; } lines.wwSizeY = wwOffset; } }
public bool MoveNext() { bool result; if (direct) { result = index < endIndex; if (result) { LineBlock block = lines.blocks[blockI]; if (index - block.offset >= block.count) { blockI++; block = lines.blocks[blockI]; } current = block.array[index - block.offset]; index++; } } else { result = index > endIndex; if (result) { LineBlock block = lines.blocks[blockI]; if (index - block.offset < 0) { blockI--; block = lines.blocks[blockI]; } current = block.array[index - block.offset]; index--; } } return(result); }
public bool Parse(LineArray lines, int maxMilliseconds) { #if HIGHLIGHTER_DEBUG if (_debugStopwatch == null) { _debugStopwatch = new System.Diagnostics.Stopwatch(); _debugStopwatch.Start(); Console.WriteLine("HIGHLIGHTER START"); } #endif DateTime startTime = DateTime.Now; int changesBeforeTimeCheck = 0; bool timeElapsed = false; bool changed = false; stack = new PredictableList <Rules.Context>(8); stack.Add(contexts[0]); Rules.Context[] state = stack.ToArray(); bool needSetStack = false; bool lastLineChanged = false; for (int i = 0; i < lines.blocksCount; i++) { LineBlock block = lines.blocks[i]; if (timeElapsed && lastLineChanged) { while (block.count == 0) { i++; if (i >= lines.blocksCount) { block = null; break; } block = lines.blocks[i]; } if (block != null) { block.valid &= ~LineBlock.ColorValid; Line line = block.array[0]; line.startState = state; line.endState = null; } stack = null; return(changed); } { bool noChangesInBlock = (block.valid & LineBlock.ColorValid) != 0 && !lastLineChanged; if (noChangesInBlock && block.count > 0) { Rules.Context[] nextState = block.array[block.count - 1].endState; if (nextState == null) { noChangesInBlock = false; } else { state = nextState; } } if (noChangesInBlock) { needSetStack = true; continue; } } block.valid |= LineBlock.ColorValid; for (int j = 0; j < block.count; j++) { Line line = block.array[j]; if (AreEquals(line.startState, state) && line.endState != null) { state = line.endState; needSetStack = true; lastLineChanged = false; continue; } if (needSetStack) { needSetStack = false; stack.Resize(state.Length); Array.Copy(state, stack.buffer, stack.count); } line.startState = state; string text = line.Text; Array.Clear(awakePositions, 0, awakePositions.Length); int position = 0; int count = line.charsCount; Rules.Rule lastMatched = null; while (position < count) { Rules.Context context = stack.count > 0 ? stack.Peek() : contexts[0]; lastMatched = null; foreach (Rules.Rule rule in context.childs) { int nextPosition; if ((rule.column == -1 || position == rule.column) && rule.Match(text, position, out nextPosition)) { if (!rule.lookAhead) { for (; position < nextPosition; position++) { line.chars[position].style = rule.attribute.index; } } if (rule.childs != null && position < count) { foreach (Rules.Rule childRule in rule.childs) { int childNextPosition; if (childRule.Match(text, nextPosition, out childNextPosition)) { for (; position < childNextPosition; position++) { line.chars[position].style = childRule.attribute.index; } Switch(rule.context); } } } Switch(rule.context); lastMatched = rule; break; } } if (lastMatched == null) { if (context.fallthrough) { Switch(context.fallthroughContext); } else { line.chars[position].style = context.attribute.index; position++; } } } if (lastMatched == null || !lastMatched.isLineContinue) { while (stack.count > 0) { Rules.Context contextI = stack.Peek(); if (contextI.lineEndContext.next == null && contextI.lineEndContext.pops == 0) { break; } Switch(contextI.lineEndContext); } } if (AreEquals(stack, state)) { line.endState = state; } else { state = stack.ToArray(); line.endState = state; } changesBeforeTimeCheck++; lastLineChanged = true; changed = true; } if (changesBeforeTimeCheck > 50) { changesBeforeTimeCheck = 0; DateTime nextTime = DateTime.Now; timeElapsed = (nextTime - startTime).TotalMilliseconds > maxMilliseconds; if (timeElapsed) { startTime = nextTime; } } } stack = null; lastParsingChanged = changed; if (!changed && lines.ranges != null) { foreach (StyleRange range in lines.ranges) { lines.SetStyleRange(range); } } #if HIGHLIGHTER_DEBUG if (!changed) { _debugStopwatch.Stop(); Console.WriteLine("HIGHLIGHTER TIME: " + (_debugStopwatch.Elapsed.TotalMilliseconds / 1000).ToString("0.00")); } #endif return(changed); }
public void SwapCurrent(bool withPrev) { LineBlock block = lines.blocks[blockI]; int index = (direct ? this.index - 1 : this.index + 1) - block.offset; Line line; if (withPrev) { if (index - 1 < 0) { LineBlock prevBlock = lines.blocks[blockI - 1]; line = prevBlock.array[prevBlock.count - 1]; prevBlock.array[prevBlock.count - 1] = current; block.array[index] = line; prevBlock.valid = 0; prevBlock.wwSizeX = 0; } else { line = block.array[index - 1]; block.array[index - 1] = current; block.array[index] = line; } } else { if (index + 1 > block.count - 1) { LineBlock nextBlock = lines.blocks[blockI + 1]; line = nextBlock.array[0]; nextBlock.array[0] = current; block.array[index] = line; nextBlock.valid = 0; nextBlock.wwSizeX = 0; } else { line = block.array[index + 1]; block.array[index + 1] = current; block.array[index] = line; } } if (blockI == lines.blocksCount - 1 && (withPrev ? index : index + 1) == block.count - 1) { Line line0; Line line1; if (withPrev) { line0 = line; line1 = current; } else { line0 = current; line1 = line; } string rn = line0.RemoveRN(); for (int i = 0; i < rn.Length; i++) { line1.Chars_Add(new Char(rn[i])); } line0.cachedText = null; line0.cachedSize = -1; line0.wwSizeX = 0; line1.cachedText = null; line1.cachedSize = -1; line1.wwSizeX = 0; } current.endState = null; line.endState = null; block.valid = 0; block.wwSizeX = 0; lines.ResetTextCache(); }