public char NextChar(int pos, ref int foundPos) { char ch = char.MinValue; int nextpos = pos; while (true) { if (nextpos >= TextLength) { break; } ch = NativeInterface.GetCharAt(nextpos); if (ch == '\t' || ch == ' ' || ch == '\r' || ch == '\v' || ch == '\n') { nextpos = NativeInterface.PositionAfter(nextpos); continue; } else { foundPos = nextpos; return(ch); } } foundPos = -1; return(ch); }
private char SafeGetChar(int pos) { if (pos < 0 || pos >= TextLength) { return(char.MinValue); } return(NativeInterface.GetCharAt(pos)); }
public char PreviousChar(int pos, ref int foundPos, bool wantWhitespace) { char ch = char.MinValue; int curpos = NativeInterface.PositionBefore(pos); if (curpos == 0) { foundPos = curpos; return(ch); } while (true) { ch = NativeInterface.GetCharAt(curpos); if (ch == '\t' || ch == ' ' || ch == '\r' || ch == '\v' || ch == '\n') { //if the caller is interested in whitespace, //simply return it if (wantWhitespace) { foundPos = curpos; return(ch); } long tmpPos = curpos; curpos = NativeInterface.PositionBefore(curpos); if (curpos == 0 && tmpPos == curpos) { break; } } else { foundPos = curpos; return(ch); } } foundPos = -1; return(ch); }
public string PreviousWord(int pos, ref int foundPos) { // Get the partial word that we have char ch = char.MinValue; int curpos = NativeInterface.PositionBefore(pos); if (curpos == 0) { foundPos = -1; return(""); } while (true) { ch = NativeInterface.GetCharAt(curpos); if (ch == '\t' || ch == ' ' || ch == '\r' || ch == '\v' || ch == '\n') { int tmpPos = curpos; curpos = NativeInterface.PositionBefore(curpos); if (curpos == 0 && tmpPos == curpos) { break; } } else { int start = NativeInterface.WordStartPosition(curpos, true); int end = NativeInterface.WordEndPosition(curpos, true); //return NativeInterface.GetTextRange(start, end); return(new Range(start, end, this).Text); } } foundPos = -1; return(""); }
public bool MatchBraceForward(char chOpenBrace, int pos, ref int matchedPos) { if (pos <= 0) { return(false); } char chCloseBrace; switch (chOpenBrace) { case '{': { chCloseBrace = '}'; break; } case '(': { chCloseBrace = ')'; break; } case '[': { chCloseBrace = ']'; break; } case '<': { chCloseBrace = '>'; break; } default: { return(false); } } int nNextPos = pos; char ch; int depth = 1; while (true) { if (nNextPos >= this.TextLength) { break; } nNextPos = NativeInterface.PositionAfter(nNextPos); // Make sure we are not in a comment if (m_context.IsCommentOrString(nNextPos)) { continue; } ch = NativeInterface.GetCharAt(nNextPos); if (ch == chCloseBrace) { // Dec the depth level depth--; if (depth == 0) { matchedPos = nNextPos; return(true); } } else if (ch == chOpenBrace) { // Inc depth level depth++; } } return(false); }
public bool MatchBraceBack(char chCloseBrace, int pos, ref int matchedPos) { if (pos <= 0) { return(false); } char chOpenBrace; switch (chCloseBrace) { case '}': { chOpenBrace = '{'; break; } case ')': { chOpenBrace = '('; break; } case ']': { chOpenBrace = '['; break; } case '>': { chOpenBrace = '<'; break; } default: { return(false); } } int nPrevPos = pos; char ch; int depth = 1; // We go backward while (true) { if (nPrevPos == 0) { break; } nPrevPos = NativeInterface.PositionBefore(nPrevPos); // Make sure we are not in a comment if (m_context.IsCommentOrString(nPrevPos)) { continue; } ch = NativeInterface.GetCharAt(nPrevPos); if (ch == chOpenBrace) { // Dec the depth level depth--; if (depth == 0) { matchedPos = nPrevPos; return(true); } } else if (ch == chCloseBrace) { // Inc depth level depth++; } } return(false); }