private bool CursorInBlock(CssBlock block, int line, int col) { if (line < block.LineFrom || line > block.LineTo) { return(false); } if (line == block.LineFrom && col <= block.ColFrom) { return(false); } if (line == block.LineTo && col > block.ColTo) { return(false); } return(true); }
private List <CssBlock> ParseBlocks(ScintillaControl sci) { List <CssBlock> blocks = new List <CssBlock>(); blocks.Clear(); int lines = sci.LineCount; int inString = 0; bool inComment = false; CssBlock block = null; for (int i = 0; i < lines; i++) { string line = sci.GetLine(i); int len = line.Length; int safeLen = len - 1; for (int j = 0; j < len; j++) { char c = line[j]; if (inComment) { if (c == '*' && j < safeLen && line[j + 1] == '/') { inComment = false; } else { continue; } } else if (inString > 0) { if (inString == 1 && c == '\'') { inString = 0; } else if (inString == 2 && c == '"') { inString = 0; } else { continue; } } else if (c == '\'') { inString = 1; } else if (c == '"') { inString = 2; } else if (c == '/' && j < safeLen && line[j + 1] == '/') { break; } else if (c == '/' && j < safeLen && line[j + 1] == '*') { inComment = true; } else if (c == '{') { CssBlock parent = block; block = new CssBlock(); block.LineFrom = i; block.ColFrom = j; if (parent != null) { block.Parent = parent; parent.Children.Add(block); } else { blocks.Add(block); } } else if (c == '}') { if (block != null) { block.LineTo = i; block.ColTo = j; block = block.Parent; if (block != null) { block.LineTo = i; block.ColTo = j; } } } } } return(blocks); }