コード例 #1
0
ファイル: find_all_shift_and.c プロジェクト: enzeart/libmagus
int main(int argc, char **argv) {
	both_null();
	pattern_null();
	text_null();
	pattern_larger_than_text();
	both_empty();
	empty_pattern();
	empty_text();
	all_match();
	no_match();
	non_overlapping_match();
	overlapping_match();
}
コード例 #2
0
ファイル: dialogmerge.cpp プロジェクト: postiffm/bibledit-gtk
void MergeDialog::on_mergebutton(GtkButton * button)
// If a merge button is clicked, it inserts the right text, and deletes
// the pair of buttons.
{
  GtkWidget *mybutton = GTK_WIDGET(button);
  for (unsigned int i = 0; i < buttonpairs.size(); i++) {
    bool match = false;
    if (mybutton == buttonpairs[i].button1.button)
      match = true;
    if (mybutton == buttonpairs[i].button2.button)
      match = true;
    if (match) {
      ustring text;
      if (mybutton == buttonpairs[i].button1.button) {
        text = buttonpairs[i].button1.text;
      }
      if (mybutton == buttonpairs[i].button2.button) {
        text = buttonpairs[i].button2.text;
      }
      if (text == empty_text())
        text.clear();
      GtkTextIter iter, iter2;
      gtk_text_buffer_get_iter_at_child_anchor(textbuffer, &iter, buttonpairs[i].button1.childanchor);
      gtk_text_buffer_place_cursor(textbuffer, &iter);
      iter2 = iter;
      gtk_text_iter_forward_char(&iter2);
      gtk_text_buffer_delete(textbuffer, &iter, &iter2);
      gtk_text_buffer_get_iter_at_child_anchor(textbuffer, &iter, buttonpairs[i].button2.childanchor);
      iter2 = iter;
      gtk_text_iter_forward_char(&iter2);
      gtk_text_buffer_delete(textbuffer, &iter, &iter2);
      if (!text.empty())
        gtk_text_buffer_insert_at_cursor(textbuffer, text.c_str(), -1);
    }
  }
}
コード例 #3
0
ファイル: dialogmerge.cpp プロジェクト: postiffm/bibledit-gtk
void MergeDialog::load_text(ustring text)
{
  // Variables for loading text in the textview.
  size_t pos;
  GtkTextIter iter;

  // Preprocess empty replacements.
  preprocess_empty_replacements(text);

  // Goo through the text looking for markers and processing them.
  pos = text.find(merge_conflict_markup(1));
  while (pos != string::npos) {

    // Insert the bit of text before the first conflict marker.
    gtk_text_buffer_get_end_iter(textbuffer, &iter);
    gtk_text_buffer_insert(textbuffer, &iter, text.substr(0, pos).c_str(), -1);
    text.erase(0, pos + merge_conflict_markup(1).length());

    // Retrieve the first alternative.
    ustring alternative1;
    pos = text.find(merge_conflict_markup(2));
    if (pos != string::npos) {
      alternative1 = text.substr(1, pos - 2);
      text.erase(0, pos + merge_conflict_markup(2).length());
      if (alternative1.empty())
        alternative1 = empty_text();
    }
    // Insert a button with the first alternative as a label.
    gtk_text_buffer_get_end_iter(textbuffer, &iter);
    GtkTextChildAnchor *childanchor1 = gtk_text_buffer_create_child_anchor(textbuffer, &iter);
    GtkWidget *button1 = gtk_button_new_with_label(alternative1.c_str());
    gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), button1, childanchor1);
    gtk_widget_show_all(button1);
    g_signal_connect((gpointer) button1, "clicked", G_CALLBACK(on_mergebutton_clicked), gpointer(this));

    // Store data about first alternative.
    MergeButton mergebutton1;
    mergebutton1.childanchor = childanchor1;
    mergebutton1.button = button1;
    mergebutton1.text = alternative1;

    // Retrieve the second alternative.
    ustring alternative2;
    pos = text.find(merge_conflict_markup(3));
    if (pos != string::npos) {
      alternative2 = text.substr(1, pos - 2);
      text.erase(0, pos + merge_conflict_markup(3).length());
      if (alternative2.empty())
        alternative2 = empty_text();
    }
    // Insert a button with the second alternative as a label.
    gtk_text_buffer_get_end_iter(textbuffer, &iter);
    GtkTextChildAnchor *childanchor2 = gtk_text_buffer_create_child_anchor(textbuffer, &iter);
    GtkWidget *button2 = gtk_button_new_with_label(alternative2.c_str());
    gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(textview), button2, childanchor2);
    gtk_widget_show_all(button2);
    g_signal_connect((gpointer) button2, "clicked", G_CALLBACK(on_mergebutton_clicked), gpointer(this));

    // Store data about second alternative.
    MergeButton mergebutton2;
    mergebutton2.childanchor = childanchor2;
    mergebutton2.button = button2;
    mergebutton2.text = alternative2;

    // Store the button pair.
    MergeButtonPair mergebuttonpair;
    mergebuttonpair.button1 = mergebutton1;
    mergebuttonpair.button2 = mergebutton2;
    buttonpairs.push_back(mergebuttonpair);

    // Next iteration.
    pos = text.find(merge_conflict_markup(1));
  }

  // Load remaining text in textview.
  gtk_text_buffer_get_end_iter(textbuffer, &iter);
  gtk_text_buffer_insert(textbuffer, &iter, text.substr(0, pos).c_str(), -1);

  // Scroll to beginning of buffer.
  gtk_text_buffer_get_start_iter(textbuffer, &iter);
  gtk_text_buffer_place_cursor(textbuffer, &iter);
  screen_scroll_to_iterator(GTK_TEXT_VIEW(textview), &iter);
}