int center(buffer * const b) { line_desc * const ld = b->cur_line_desc; const int right_margin = b->opt.right_margin ? b->opt.right_margin : ne_columns; int64_t len, start_pos = 0, end_pos = ld->line_len; while(start_pos < ld->line_len && isasciispace(ld->line[start_pos])) start_pos = next_pos(ld->line, start_pos, b->encoding); if (start_pos == ld->line_len) return OK; while(isasciispace(ld->line[prev_pos(ld->line, end_pos, b->encoding)])) end_pos = prev_pos(ld->line, end_pos, b->encoding); len = b->encoding == ENC_UTF8 ? utf8strlen(&ld->line[start_pos], end_pos - start_pos) : end_pos - start_pos; if (len >= right_margin) return OK; b->cur_pos = -1; start_undo_chain(b); delete_stream(b, ld, b->cur_line, end_pos, ld->line_len - end_pos); delete_stream(b, ld, b->cur_line, 0, start_pos); insert_spaces(b, ld, b->cur_line, 0, (right_margin - len) / 2); end_undo_chain(b); return OK; }
int undelete_line(buffer * const b) { line_desc * const ld = b->cur_line_desc; if (!b->last_deleted) return ERROR; start_undo_chain(b); if (b->cur_pos > ld->line_len) insert_spaces(b, ld, b->cur_line, ld->line_len, b->win_x + b->cur_x - calc_width(ld, ld->line_len, b->opt.tab_size, b->encoding)); insert_one_line(b, ld, b->cur_line, b->cur_pos); insert_stream(b, ld, b->cur_line, b->cur_pos, b->last_deleted->stream, b->last_deleted->len); end_undo_chain(b); return OK; }
/** * Read and init the current title and insert all the keywords found into the keywords vector * @param line line where extract the title * @param title vector where to store the words * @param words_ignore the vector containing the words to ignore * @param keywords the vector of keywords */ void read_title( const std::string& line, std::vector<std::string>& title, const std::vector<std::string>& words_ignore, std::vector<RefTitleWord>& keywords ){ std::istringstream iss(line); // Insert the words in the line into the current entry vector std::string word; insert_spaces( iss, word, title ); while ( getline( iss, word, ' ' ) ){ // Move the string read into the current title title.push_back( std::move(word) ); // If the word is not to ignore if ( !std::binary_search(words_ignore.begin(), words_ignore.end(), title.back()) ){ // Add a reference to this word and its title into the keywords vector keywords.push_back( RefTitleWord(title, title.back()) ); } // Insert spaces after the word read, except for the last word read if ( iss.peek() != EOF ){ word = " "; insert_spaces( iss, word, title ); } } }