int get_nof_tabs_between(sptr_t edit, int start, int end) { int current_pos = get_line_start(edit,start); int max_tabs = 0; do { unsigned char current_char = (unsigned char)call_edit(edit,SCI_GETCHARAT,current_pos); bool current_char_ends_line = is_line_end(edit,current_pos); int tabs_on_line = 0; while (current_char != '\0' && !current_char_ends_line) { if (current_char == '\t') { tabs_on_line++; if (tabs_on_line > max_tabs) { max_tabs = tabs_on_line; } } current_pos = call_edit(edit,SCI_POSITIONAFTER,current_pos); current_char = (unsigned char)call_edit(edit,SCI_GETCHARAT,current_pos); current_char_ends_line = is_line_end(edit,current_pos); } } while (change_line(edit,current_pos,FORWARDS) && current_pos < end); return max_tabs; }
bool lex_stream_t::implementation_t::is_comment(char c, stream_lex_token_t& result) { if (c != '/') return false; std::istream::int_type peek_c (_super::peek_char()); if (peek_c == EOF || (peek_c != '/' && peek_c != '*')) return false; (void)_super::get_char(c); identifier_buffer_m.clear(); if (c == '/') { while (_super::get_char(c) && !is_line_end(c)) { identifier_buffer_m.push_back(c); } identifier_buffer_m.push_back(0); result = stream_lex_token_t(trail_comment_k, any_regular_t(std::string(&identifier_buffer_m[0]))); } else // if (c == '*') { while (true) { if (!_super::get_char(c)) throw_parser_exception("Unexpected EOF in comment."); if (c == '*') { peek_c = _super::peek_char(); if (peek_c != EOF && peek_c == '/') { _super::ignore_char(); break; } } else if (is_line_end(c)) { c = '\n'; } identifier_buffer_m.push_back(c); } identifier_buffer_m.push_back(0); result = stream_lex_token_t(lead_comment_k, any_regular_t(std::string(&identifier_buffer_m[0]))); } return true; }
std::string stream_sucker( InputStream& stream ) { #if ADOBE_PLATFORM_MAC const char platform_lf('\r'); #else const char platform_lf('\n'); // Windows seems to handle this fine #endif std::string result; if ( stream.is_open() ) { stream.unsetf(std::ios_base::skipws); std::istream_iterator<char> first(stream); std::istream_iterator<char> last; while (first != last) { if (is_line_end(first, last)) { result.append(1, platform_lf); continue; } result.append(1, *first); ++first; } } return result; }
int string_fill_slice(struct string *dst, const char *buf, char end) { const char *p; int len; for (p = buf; is_space(*p) && !is_line_end(*p); p++); dst->str = (char *)p; for (len = 0; !is_line_end(*p); p++) { if (*p == end) break; if (is_space(*p)) { if (len == 0) len = p-dst->str; } else { len = 0; } } if (len == 0) len = p-dst->str; dst->len = len; return p-buf; }
std::pair<I, std::string> get_line(I first, I last) { std::string result; while (first != last && !is_line_end(first, last)) { result.append(1, *first); ++ first; } return std::make_pair(first, result); }
int get_block_boundary(sptr_t edit, int& location, direction which_dir) { int current_pos; int max_tabs = 0; bool orig_line = true; location = get_line_start(edit,location); do { int tabs_on_line = 0; current_pos = location; unsigned char current_char = (unsigned char)call_edit(edit,SCI_GETCHARAT,current_pos); bool current_char_ends_line = is_line_end(edit,current_pos); while (current_char != '\0' && !current_char_ends_line) { if (current_char == '\t') { tabs_on_line++; if (tabs_on_line > max_tabs) { max_tabs = tabs_on_line; } } current_pos = call_edit(edit,SCI_POSITIONAFTER,current_pos); current_char = (unsigned char)call_edit(edit,SCI_GETCHARAT,current_pos); current_char_ends_line = is_line_end(edit,current_pos); } if (tabs_on_line == 0 && !orig_line) { return max_tabs; } orig_line = false; } while (change_line(edit,location,which_dir)); return max_tabs; }
void pp_define(char *p, bool ww) { int i, si; p = parse_id(p, m_id_buf); si = get_symbol_index(m_id_buf); if (si < 0) { si = m_symbol_len; // not defined so add it strcpy(m_symbol[si].id, m_id_buf); m_symbol[si].val[0] = 0; // default val is empty str ++m_symbol_len; } // else if defined change its value if (!is_line_end(*p)) { skip_white_space(&p); i = 0; while (!is_line_end(*p)) { // get pp value, to end of line m_symbol[si].val[i++] = *p++; } m_symbol[si].val[i] = 0; // terminate string } m_symbol[si].ww = ww; // to use whole-word search or not }
void stretch_tabstops(sptr_t edit, int block_start_linenum, int block_nof_lines, int max_tabs) { int l, t; et_line* lines = (et_line*)_alloca(sizeof (et_line) * block_nof_lines); memset(lines,0,sizeof (et_line) * block_nof_lines); int new_buffer_size = sizeof (et_tabstop) * __max(1,block_nof_lines * max_tabs); if (new_buffer_size > grid_buffer_size) { et_tabstop* new_buffer = (et_tabstop*)realloc(grid_buffer,new_buffer_size); if (new_buffer == NULL) { return; } grid_buffer = new_buffer; grid_buffer_size = new_buffer_size; } memset(grid_buffer,0,new_buffer_size); et_tabstop** grid = (et_tabstop**)_alloca(sizeof (et_tabstop*) * block_nof_lines); for (l = 0; l < block_nof_lines; l++) { grid[l] = grid_buffer + (l * max_tabs); } // get width of text in cells for (l = 0; l < block_nof_lines; l++) // for each line { int text_width_in_tab = 0; int current_line_num = block_start_linenum + l; int current_tab_num = 0; bool cell_empty = true; int current_pos = call_edit(edit,SCI_POSITIONFROMLINE,current_line_num); int cell_start = current_pos; unsigned char current_char = (unsigned char)call_edit(edit,SCI_GETCHARAT,current_pos); bool current_char_ends_line = is_line_end(edit,current_pos); // maybe change this to search forwards for tabs/newlines while (current_char != '\0') { if (current_char_ends_line) { grid[l][current_tab_num].ends_in_tab = false; text_width_in_tab = 0; break; } else if (current_char == '\t') { if (!cell_empty) { text_width_in_tab = get_text_width(edit,cell_start,current_pos); } grid[l][current_tab_num].ends_in_tab = true; grid[l][current_tab_num].text_width_pix = calc_tab_width(text_width_in_tab); current_tab_num++; lines[l].num_tabs++; text_width_in_tab = 0; cell_empty = true; } else { if (cell_empty) { cell_start = current_pos; cell_empty = false; } } current_pos = call_edit(edit,SCI_POSITIONAFTER,current_pos); current_char = (unsigned char)call_edit(edit,SCI_GETCHARAT,current_pos); current_char_ends_line = is_line_end(edit,current_pos); } } // find columns blocks and stretch to fit the widest cell for (t = 0; t < max_tabs; t++) // for each column { bool starting_new_block = true; int first_line_in_block = 0; int max_width = 0; for (l = 0; l < block_nof_lines; l++) // for each line { if (starting_new_block) { starting_new_block = false; first_line_in_block = l; max_width = 0; } if (grid[l][t].ends_in_tab) { grid[l][t].widest_width_pix = &(grid[first_line_in_block][t].text_width_pix); // point widestWidthPix at first if (grid[l][t].text_width_pix > max_width) { max_width = grid[l][t].text_width_pix; grid[first_line_in_block][t].text_width_pix = max_width; } } else // end column block { starting_new_block = true; } } } std::vector<int> tab_array; // set tabstops for (l = 0; l < block_nof_lines; l++) // for each line { int current_line_num = block_start_linenum + l; int acc_tabstop = 0; tab_array.resize(lines[l].num_tabs + 1); tab_array[lines[l].num_tabs] = 0; for (t = 0; t < lines[l].num_tabs; t++) { if (grid[l][t].widest_width_pix != NULL) { acc_tabstop += *(grid[l][t].widest_width_pix); tab_array[t] = acc_tabstop; } else { tab_array[t] = 0; } } call_edit(edit,SCI_SETTABSTOPS,current_line_num,(LONG_PTR)&(tab_array.at(0))); } }