Searching for valid code block begin

@param cursor text cursor
@return code block start, -1 if not found
330271
private int findCodeBlockStart(TextCursor cursor) {
        int offset = cursor.currentOffset;
        int index;
        while ((index = cursor.text.indexOf(CODE_BLOCK, offset)) >= 0) {
            if (isGoodAnchor(cursor.text, index - 1)) {
                return index;
            }
            offset = index + 3;
        }
        return -1;
    }
643775
function(){
    var tok = this.accept(':');
    if (tok) {
      var expr = this.parseExpr();
      return expr.type === 'Block' ? expr : this.initBlock(tok.loc.start.line, [expr]);
    } else {
      return this.block();
    }
  }
580
boolean remove(RowCursor cursor)
  {
    int rowHead = _rowHead;
    int blobTail = _blobTail;
    
    rowHead -= cursor.removeLength();

    if (rowHead < blobTail) {
      return false;
    }
    
    byte []buffer = _buffer;
    
    // buffer[rowHead] = REMOVE;
    
    cursor.getRemove(buffer, rowHead);
    // cursor.getKey(buffer, rowHead + ColumnState.LENGTH);
    
    rowHead(rowHead);
    
    validateBlock(cursor.row());    
    
    return true;
  }
1168029
@Override
   public CursorPosition getCursor()
   {
      if (settings.isAnsiConsole() && Config.isOSPOSIXCompatible())
      {
         try
         {
            StringBuilder col = new StringBuilder(4);
            StringBuilder row = new StringBuilder(4);
            out().print(ANSI.CURSOR_ROW);
            out().flush();
            boolean gotSep = false;
            // read the position
            int[] input = read();

            for (int i = 2; i < input.length - 1; i++)
            {
               if (input[i] == 59) // we got a ';' which is the separator
                  gotSep = true;
               else
               {
                  if (gotSep)
                     col.append((char) input[i]);
                  else
                     row.append((char) input[i]);
               }
            }
            return new CursorPosition(Integer.parseInt(row.toString()),
                     Integer.parseInt(col.toString()));
         }
         catch (Exception e)
         {
            if (settings.isLogging())
               logger.log(Level.SEVERE,
                        "Failed to find current row with ansi code: ", e);
            return new CursorPosition(-1, -1);
         }
      }
      return new CursorPosition(-1, -1);
   }
1104278
public int start() {
    Preconditions.checkState(match != null, "Have not called find()");
    if (start >= 0) {
      return tokens.get(start).start();
    }
    return -1;
  }
1316942
private int findHighStart(int highValue) {

        int value;
        int c, prev;
        int i1, i2, j, i2Block, prevI2Block, block, prevBlock;


        /* set variables for previous range */
        if(highValue==initialValue) {
            prevI2Block=index2NullOffset;
            prevBlock=dataNullOffset;
        } else {
            prevI2Block=-1;
            prevBlock=-1;
        }
        prev=0x110000;

        /* enumerate index-2 blocks */
        i1=UNEWTRIE2_INDEX_1_LENGTH;
        c=prev;
        while(c>0) {
            i2Block=index1[--i1];
            if(i2Block==prevI2Block) {
                /* the index-2 block is the same as the previous one, and filled with highValue */
                c-=UTRIE2_CP_PER_INDEX_1_ENTRY;
                continue;
            }
            prevI2Block=i2Block;
            if(i2Block==index2NullOffset) {
                /* this is the null index-2 block */
                if(highValue!=initialValue) {
                    return c;
                }
                c-=UTRIE2_CP_PER_INDEX_1_ENTRY;
            } else {
                /* enumerate data blocks for one index-2 block */
                for(i2=UTRIE2_INDEX_2_BLOCK_LENGTH; i2>0;) {
                    block=index2[i2Block+ --i2];
                    if(block==prevBlock) {
                        /* the block is the same as the previous one, and filled with highValue */
                        c-=UTRIE2_DATA_BLOCK_LENGTH;
                        continue;
                    }
                    prevBlock=block;
                    if(block==dataNullOffset) {
                        /* this is the null data block */
                        if(highValue!=initialValue) {
                            return c;
                        }
                        c-=UTRIE2_DATA_BLOCK_LENGTH;
                    } else {
                        for(j=UTRIE2_DATA_BLOCK_LENGTH; j>0;) {
                            value=data[block+ --j];
                            if(value!=highValue) {
                                return c;
                            }
                            --c;
                        }
                    }
                }
            }
        }

        /* deliver last range */
        return 0;
    }
343169
public boolean startsWith(final String str) {
        if (str == null) {
            return false;
        }
        final int len = str.length();
        if (len == 0) {
            return true;
        }
        if (len > size) {
            return false;
        }
        for (int i = 0; i < len; i++) {
            if (buffer[i] != str.charAt(i)) {
                return false;
            }
        }
        return true;
    }
156474
@Override
    public void beginQuotationLine()
    {
        if (getBlockState().getQuotationLineIndex() > 0) {
            getPrinter().print("\n");
        }

        print(StringUtils.repeat('>', getBlockState().getQuotationDepth()));
    }
1282668
private JNoteElementAbstract getHighestNoteGlyphBetween(NoteAbstract start, NoteAbstract end, boolean excludeStartAndEnd) {
		Collection jnotes = getNoteGlyphesBetween(start, end);
		JNoteElementAbstract ret = null;
		boolean first = true;
		for (Iterator it = jnotes.iterator(); it.hasNext();) {
			JNoteElementAbstract n = (JNoteElementAbstract) it.next();
			if (first && excludeStartAndEnd) {
				//ignore start ?
				first = false;
				continue;
			}
			if (!it.hasNext() && excludeStartAndEnd) {
				//ignore end ?
				break;
			}
			if (ret == null)
				ret = n;
			else {
				if (n.getBoundingBox().getMinY()
					< ret.getBoundingBox().getMinY())
					ret = n;
			}
		}
		return ret;
	}
1070490
private int findSpanEnd(TextCursor cursor, int spanStart, int limit, char span) {
        for (int i = spanStart + 1; i < limit; i++) {
            char c = cursor.text.charAt(i);
            if (c == span) {
                // Check prev and next symbols
                if (isGoodAnchor(cursor.text, i + 1) && isNotSymbol(cursor.text, i - 1, span)) {
                    return i + 1;
                }
            }
        }
        return -1;
    }
29668
void startBlockImpl( String[] selectors ) {
        for( int i=0; i<selectors.length; i++ ) {
            if( i > 0 ) {
                output.append( ',' );
                newline();
            }
            insets();
            append( selectors[i] );
        }
        space();
        output.append( '{' );
        newline();
        incInsets();
    }
616055
public static <T> T getPrevInstruction(InstructionHandle startHandle, Class<T> clazz) {
        InstructionHandle curHandle = startHandle;
        while (curHandle != null) {
            curHandle = curHandle.getPrev();

            if (curHandle != null && clazz.isInstance(curHandle.getInstruction())) {
                return clazz.cast(curHandle.getInstruction());
            }
        }
        return null;
    }
810448
def beginning_of_code_block(node, line_number, full_contents, is_code_node):
    """"""
    if SPHINX_INSTALLED and not is_code_node:
        delta = len(node.non_default_attributes())
        current_line_contents = full_contents.splitlines()[line_number:]
        blank_lines = next(
            (i for (i, x) in enumerate(current_line_contents) if x),
            0)
        return (
            line_number +
            delta - 1 +
            blank_lines - 1 +
            SPHINX_CODE_BLOCK_DELTA)
    else:
        lines = full_contents.splitlines()
        code_block_length = len(node.rawsource.splitlines())

        try:
            # Case where there are no extra spaces.
            if lines[line_number - 1].strip():
                return line_number - code_block_length + 1
        except IndexError:
            pass

        # The offsets are wrong if the RST text has multiple blank lines after
        # the code block. This is a workaround.
        for line_number in range(line_number, 1, -1):
            if lines[line_number - 2].strip():
                break

        return line_number - code_block_length
1308489
def __select_text_under_cursor_blocks(self, cursor):
        

        start_block = self.document().findBlock(cursor.selectionStart()).firstLineNumber()
        end_block = self.document().findBlock(cursor.selectionEnd()).firstLineNumber()
        cursor.setPosition(self.document().findBlockByLineNumber(start_block).position())
        cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.MoveAnchor)
        cursor.movePosition(QTextCursor.Down, QTextCursor.KeepAnchor, end_block - start_block)
        cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)
397944
private StateUpdater createStart(Cursor cursor, SelectorModel model, StateUpdater check, StateUpdater select)
    {
        return (extrp, current) ->
        {
            StateUpdater next = current;
            if (!model.isEnabled())
            {
                next = check;
            }
            else if (model.getSelectionClick() == cursor.getClick())
            {
                checkBeginSelection(cursor, model);
                if (model.isSelecting())
                {
                    next = select;
                }
            }
            return next;
        };
    }
708473
JCBlock block(int pos, long flags) {
        accept(LBRACE);
        List<JCStatement> stats = blockStatements();
        JCBlock t = F.at(pos).Block(flags, stats);
        while (token.kind == CASE || token.kind == DEFAULT) {
            syntaxError("orphaned", token.kind);
            switchBlockStatementGroups();
        }
        // the Block node has a field "endpos" for first char of last token, which is
        // usually but not necessarily the last char of the last token.
        t.endpos = token.pos;
        accept(RBRACE);
        return toP(t);
    }
1068713
function getCheckStartEndBlockEvalFunction() {
		var skipBogus = false,
			whitespaces = CKEDITOR.dom.walker.whitespaces(),
			bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true ),
			isBogus = CKEDITOR.dom.walker.bogus();

		return function( node ) {
			// First skip empty nodes
			if ( bookmarkEvaluator( node ) || whitespaces( node ) )
				return true;

			// Skip the bogus node at the end of block.
			if ( isBogus( node ) && !skipBogus ) {
				skipBogus = true;
				return true;
			}

			// If there's any visible text, then we're not at the start.
			if ( node.type == CKEDITOR.NODE_TEXT &&
				( node.hasAscendant( 'pre' ) ||
					CKEDITOR.tools.trim( node.getText() ).length ) ) {
				return false;
			}

			// If there are non-empty inline elements (e.g. <img />), then we're not
			// at the start.
			if ( node.type == CKEDITOR.NODE_ELEMENT && !node.is( inlineChildReqElements ) )
				return false;

			return true;
		};
	}