Exemple #1
0
unsigned int bibleworks_clipboard_file_line_get_extract_book_id (ustring& line)
// Gets the id of a book from a line of a BibleWorks database copied through the clipboard.
// The amount of text that make up the book is removed from the line.
// Normally a line of text would look like this:
// SCR Matthew 1:1  Βίβλος γενέσεως Ἰησοῦ Χριστοῦ, υἱοῦ Δαβὶδ, υἱοῦ Ἀβραάμ.
// or:
// SCR 1 Corinthians 1:1  Παῦλος κλητὸς ἀπόστολος Ἰησοῦ Χριστοῦ διὰ θελήματος Θεοῦ, καὶ Σωσθένης ὁ ἀδελφός,
{
  // Remove whitespace from the start of the line.
  while (line.substr (0, 1) == " ") 
    line.erase (0, 1);
  // Remove the module abbreviation.
  size_t pos = line.find (" ");
  if (pos == string::npos)
    return 0;
  line.erase (0, ++pos);
  // Get the name of the book.
  vector <unsigned int> ids = books_type_to_ids (btUnknown);
  for (unsigned int i = 0; i < ids.size(); i++) {
    ustring english_name = books_id_to_english (ids[i]);
    if (line.find (english_name) == 0) {
      line.erase (0, english_name.length());
      return ids[i];
    }
  }
  return 0;
}
Exemple #2
0
/*
 * Extracts and processes all messages inside the specified buffer.
 * @throw CDCReading Exception
 */
void CDCImplPrivate::processAllMessages(ustring& msgBuffer) {
	if (msgBuffer.empty()) {
		return;
	}

	ParsedMessage parsedMessage = parseNextMessage(msgBuffer);
	while ( parsedMessage.parseResult.resultType != PARSE_NOT_COMPLETE ) {
		if ( parsedMessage.parseResult.resultType == PARSE_BAD_FORMAT ) {
			// throw all bytes from the buffer up to next 0x0D
			size_t endMsgPos = msgBuffer.find(0x0D, parsedMessage.parseResult.lastPosition);
			if (endMsgPos == string::npos) {
				msgBuffer.clear();
			}  else {
				msgBuffer.erase(0, endMsgPos+1);
			}

			setLastReceptionError("Bad message format");
		} else {
			msgBuffer.erase(0, parsedMessage.parseResult.lastPosition+1);
			processMessage(parsedMessage);
		}

		if (msgBuffer.empty()) {
			return;
		}

		parsedMessage = parseNextMessage(msgBuffer);
	}
}
Exemple #3
0
  ustring trimLeft( ustring &str, const ustring trimChars)
  {
    ustring::size_type pos = str.find_first_not_of( trimChars );
    str.erase( 0, pos );

    return str;
  }
Exemple #4
0
  ustring trimRight( ustring &str, ustring trimChars)
  {
    ustring::size_type pos = str.find_last_not_of( trimChars );
    str.erase( pos + 1 );

    return str;
  }
Exemple #5
0
void de_byte_order_mark (ustring& line)
// Some textfiles start with a byte order mark.
// This function remove it.
{
  if (line.find ("") == 0) { // Note that there's text between the quotation marks.
    line.erase (0, 1);
  }
}
Exemple #6
0
bool bitpattern_take(ustring & pattern)
// Return the next bit from "pattern" and removes it from that string.
// This implies that settngs from the pattern must be taken in the same order
// that they were added.
{
  bool setting = false;
  if (!pattern.empty()) {
    setting = convert_to_bool(pattern.substr(0, 1));
    pattern.erase(0, 1);
  }
  return setting;
}
Exemple #7
0
ustring convert_bibleworks_greek (ustring line)
{
  ustring outputline;
  while (!line.empty()) {
    ustring character;
    bool converted = false;
    // Convert the combined characters.
    character = line.substr (0, 2);
    for (unsigned int i = 0; i < sizeof(bibleworks_greek_table_2) / sizeof(*bibleworks_greek_table_2); i++) {
      if (!converted) {
        if (character == bibleworks_greek_table_2[i].input) {
          outputline.append (bibleworks_greek_table_2[i].output);
          line.erase (0, 2);
          converted = true;
        }
      }
    }
    // Convert the single character.
    if (!converted) {
      character = line.substr (0, 1);
      for (unsigned int i = 0; i < sizeof(bibleworks_greek_table_1) / sizeof(*bibleworks_greek_table_1); i++) {
        if (!converted) {
          if (character == bibleworks_greek_table_1[i].input) {
            outputline.append (bibleworks_greek_table_1[i].output);
            line.erase (0, 1);
            converted = true;
          }
        }
      }
    }
    // Message if the conversion didn't work out.
    if (!converted) {
      gw_critical ("Output so far: " + outputline + " - unhandled character: " + character + " - input stream: " + line);
      outputline.append (character);
      line.erase (0, 1);
    }
  }
  return outputline;  
}
void NotesTransferDialog::clean_note(ustring & note)
// "Cleans" the note: removes unnecessary stuff.
{
  ustring working_copy(note);
  ustring marker = usfm_extract_marker(working_copy);
  if (marker == "v") {
    usfm_extract_marker(note);
    note = trim(note);
    ustring verse = number_in_string(note);
    note.erase(0, verse.length());
    note = trim(note);
  }
}
ustring CheckValidateUsfm::usfm_extract_marker_with_forwardslash(ustring & line)
// Returns the usfm marker from the line, but only if it starts with a forward slash
{
  ustring returnvalue;
  line = trim(line);
  size_t offposition;
  offposition = line.find("/");
  if (offposition != string::npos) {
    line.erase(0, offposition);
    size_t endposition;
    endposition = line.find_first_of(" *", 1);
    if (endposition != string::npos) {
      returnvalue = line.substr(0, ++endposition);
      line.erase(0, endposition);
    } else {
      returnvalue = line;
      line.clear();
    }
  }
  if (returnvalue.length() > 0)
    returnvalue.erase(0, 1);    // Remove slash.
  return trim(returnvalue);
}
Exemple #10
0
void bibleworks_define_parsing_gender (ustring& parsing, ustring& definition)
// Parse the gender.
{
  ustring gender_code = parsing.substr (0, 1);
  parsing.erase (0, 1);
  if (gender_code == "m") {
    definition.append (" masculine");
  } 
  if (gender_code == "f") {
    definition.append (" feminine");
  }
  if (gender_code == "n") {
    definition.append (" neuter");
  }
}
Exemple #11
0
void bibleworks_define_parsing_number (ustring& parsing, ustring& definition)
// Parse the number.
{
  ustring number = parsing.substr (0, 1);
  bool remove_code = true;
  if (number == "s") {
    definition.append (" singular");
  } else if (number == "p") {
    definition.append (" plural");
  } else {
    remove_code = false;
  }
  if (remove_code) {
    parsing.erase (0, 1);
  }
}
Exemple #12
0
void CategorizeLine::clear_out_any_marker(ustring & line)
{
  size_t startpos = 0;
  startpos = line.find("\\", startpos);
  while (startpos != string::npos) {
    ustring marker;
    size_t endpos = line.find_first_of(" *", startpos);
    if (endpos == string::npos) {
      marker = line.substr(startpos + 1, line.length() - startpos);
    } else {
      marker = line.substr(startpos + 1, endpos - startpos - 1);
    }
    line.erase(startpos, marker.length() + 2);
    startpos++;
    startpos = line.find("\\", startpos);
  }
}
Exemple #13
0
void bibleworks_define_parsing_tense (ustring& parsing, ustring& definition)
// Parse the tense of verbs.
{
  ustring tense = parsing.substr (0, 1);  
  parsing.erase (0, 1);
  if (tense == "p")
    definition.append (" present");
  if (tense == "i")
    definition.append (" imperfect");
  if (tense == "f")
    definition.append (" future");
  if (tense == "a")
    definition.append (" aorist");
  if (tense == "x")
    definition.append (" perfect");
  if (tense == "y")
    definition.append (" pluperfect");
}
Exemple #14
0
void bibleworks_define_parsing_mood (ustring& parsing, ustring& definition)
// Parse the mood of verbs.
{
  ustring mood = parsing.substr (0, 1);  
  parsing.erase (0, 1);
  if (mood == "i")
    definition.append (" indicative");
  if (mood == "s")
    definition.append (" subjunctive");
  if (mood == "o")
    definition.append (" optative");
  if (mood == "d")
    definition.append (" imperative");
  if (mood == "n")
    definition.append (" infinitive");
  if (mood == "p")
    definition.append (" participle");
}
Exemple #15
0
void bibleworks_define_parsing_person (ustring& parsing, ustring& definition)
// This looks in the "parsing" whether the person is given. 
// If so, it adds the description to the "definition" and removes the relevant code from the "parsing".
{
  ustring person = parsing.substr (0, 1);
  bool person_found = true;
  if (person == "1") {
    definition.append (" first person");
  } else if (person == "2") {
    definition.append (" second person");
  } else if (person == "3") {
    definition.append (" third person");
  } else {
    person_found = false;
  }
  if (person_found) {
    parsing.erase (0, 1);
  }
}
Exemple #16
0
void bibleworks_define_parsing_case (ustring& parsing, ustring& definition)
// Parse the case.
{
  ustring case_code = parsing.substr (0, 1);
  parsing.erase (0, 1);
  if (case_code == "n") {
    definition.append (" nominative");
  } 
  if (case_code == "g") {
    definition.append (" genitive");
  }
  if (case_code == "d") {
    definition.append (" dative");
  }
  if (case_code == "a") {
    definition.append (" accusative");
  }
  if (case_code == "v") {
    definition.append (" vocative");
  }
}
void CheckValidateUsfm::check_on_endmarker(ustring & line, const ustring & marker, bool optional)
// This test is ran by any marker that needs an endmarker.
// It checks on that, and if found, removes it from the line,
// and if not found, gives a message.
// If the endmarker is "optional" no message will be given.
{
  // Look for the endmarker.
  ustring endmarker;
  endmarker = "\\" + marker + "*";
  size_t endmarkerposition;
  endmarkerposition = line.find(endmarker);
  if (endmarkerposition != string::npos) {
    // Found: remove it from the line.
    line.erase(endmarkerposition, endmarker.length());
  } else {
    // Not found: Error message.
    // No error message if the endmarker is optional.
    if (!optional) {
      message(_("Endmarker ") + endmarker + _(" not found"));
    }
  }
}
Exemple #18
0
void bibleworks_define_parsing_voice (ustring& parsing, ustring& definition)
// Parse the voice of verbs.
{
  ustring voice = parsing.substr (0, 1);  
  parsing.erase (0, 1);
  if (voice == "a")
    definition.append (" active");
  if (voice == "m")
    definition.append (" middle");
  if (voice == "p")
    definition.append (" passive");
  if (voice == "e")
    definition.append (" middle or passive");
  if (voice == "d")
    definition.append (" middle deponent");
  if (voice == "o")
    definition.append (" passive deponent");
  if (voice == "n")
    definition.append (" middle or passive deponent");
  if (voice == "q")
    definition.append (" impersonal active");
  if (voice == "x")
    definition.append (" no voice stated");
}
Exemple #19
0
void bibleworks_define_parsing_pronoun (ustring& parsing, ustring& definition)
// Parse the extra bits of the pronoun.
{
  ustring code = parsing.substr (0, 1);
  parsing.erase (0, 1);
  if (code == "r") {
    definition.append (" relative");
  }
  if (code == "e") {
    definition.append (" reciprocal");
  }
  if (code == "d") {
    definition.append (" demonstrative");
  }
  if (code == "c") {
    definition.append (" correlative");
  } 
  if (code == "q") {
    definition.append (" interrogative");
  }
  if (code == "i") {
    definition.append (" indefinite");
  }
  if (code == "o") {
    definition.append (" correlative/interrogative");
  }
  if (code == "x") {
    definition.append (" reflexive");
  }
  if (code == "s") {
    definition.append (" possessive");
  }
  if (code == "p") {
    definition.append (" personal");
  }
}
Exemple #20
0
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);
}
Exemple #21
0
void CategorizeLine::CategorizeOneLine(ustring &line)
{
    // Extract the marker for this line.
    ustring marker = usfm_extract_marker(line);
    
    // Marker to work with for this line.
    ustring actual_marker;
    if (marker.empty())
        actual_marker = previous_marker;
    else
        actual_marker = marker;
    
    // Re-insert bible note markers.
    if (marker == footnote_opener(false)) {
        line.insert(0, footnote_opener(true));
    }
    if (marker == endnote_opener(false)) {
        line.insert(0, endnote_opener(true));
    }
    if (marker == xref_opener(false)) {
        line.insert(0, xref_opener(true));
    }
    // Subdivide the line into categories.
    // Each category removes something from this content, until it is empty.
    
    // Footnotes, endnotes.
    if (!line.empty()) {
        size_t beginposition, endposition;
        ustring opening_marker = footnote_opener(true);
        ustring closing_marker = footnote_closer();
        beginposition = line.find(opening_marker);
        endposition = line.find(closing_marker);
        if (endposition == string::npos) {
            // BUG: In main editor, the chapter lines are all combined into a single long ustring.
            // This means that footnotes that are split across lines are "fixed." But that is not
            // the case when just looking at a single verse \\v line that has a footnote started
            // but not finished. Fixed 2/15/2018
            endposition = line.length() - 1;
        }
        while (beginposition != string::npos) {
            assert(beginposition <= endposition); // this cannot be above the while stmt...beginposition == string::npos if no marker is found
            ustring notetext;
            notetext = line.substr(beginposition + opening_marker.length(), endposition - beginposition - closing_marker.length());
            line.erase(beginposition, endposition - beginposition + closing_marker.length());
            clear_out_any_marker(notetext);
            append_text(note, notetext);
            beginposition = line.find(opening_marker);
            endposition = line.find(closing_marker);
        }
        opening_marker = endnote_opener(true);
        closing_marker = endnote_closer();
        beginposition = line.find(opening_marker);
        endposition = line.find(closing_marker);
        while ((beginposition != string::npos) && (endposition != string::npos)) {
            ustring notetext;
            notetext = line.substr(beginposition + opening_marker.length(), endposition - beginposition - closing_marker.length());
            line.erase(beginposition, endposition - beginposition + closing_marker.length());
            clear_out_any_marker(notetext);
            append_text(note, notetext);
            beginposition = line.find(opening_marker);
            endposition = line.find(closing_marker);
        }
    }
    // Crossreferences.
    if (!line.empty()) {
        size_t beginposition, endposition;
        ustring opening_marker = xref_opener(true);
        ustring closing_marker = xref_closer();
        beginposition = line.find(opening_marker);
        endposition = line.find(closing_marker);
        while ((beginposition != string::npos) && (endposition != string::npos)) {
            ustring referencetext;
            referencetext = line.substr(beginposition + opening_marker.length(), endposition - beginposition - closing_marker.length());
            line.erase(beginposition, endposition - beginposition + closing_marker.length());
            clear_out_any_marker(referencetext);
            append_text(ref, referencetext);
            beginposition = line.find(opening_marker);
            endposition = line.find(closing_marker);
        }
    }
    // Identifiers.
    if (!line.empty()) {
        if (is_id_marker(actual_marker)) {
            clear_out_any_marker(line);
            append_text(id, line);
            line.clear();
        }
    }
    // Introduction elements.
    if (!line.empty()) {
        if (is_intro_marker(actual_marker)) {
            clear_out_any_marker(line);
            append_text(intro, line);
            line.clear();
        }
    }
    // Headings, titles, labels.
    if (!line.empty()) {
        if (is_head_marker(actual_marker)) {
            clear_out_any_marker(line);
            append_text(head, line);
            line.clear();
        }
    }
    // Chapter text.
    if (!line.empty()) {
        if (is_chap_marker(actual_marker)) {
            clear_out_any_marker(line);
            append_text(chap, line);
            line.clear();
        }
    }
    // Extended study notes. As these use the existing footnote markers, 
    // deal with the study notes first.
    if (!line.empty()) {
        if (is_study_marker(actual_marker)) {
            clear_out_any_marker(line);
            append_text(study, line);
            line.clear();
        }
    }
    // After everything else has been removed, output the rest as main text.
    // This includes the "Verses" group, the "Paragraph Elements", and the
    // "Poetry Elements", the "Table Elements", and the "Special Text and
    // Character Styles", which have been filtered out already above.
    if (!line.empty()) {
        clear_out_any_marker(line);
        append_text(verse, line);
        line.clear();
    }
    // Store previous marker.
    previous_marker = marker;
    
}
Exemple #22
0
bool bibleworks_define_parsing (ustring parsing, ustring& definition)
// Tries to define the parsing as coming from BibleWorks.
// Returns true if it managed.
// The definitions were assembled by trial and error, by searching for a parsing, then looking what BibleWorks gave for it.
{
  // A parsing as imported from BibleWorks should start with the @ character.
  if (parsing.substr (0, 1) != "@") {
    return false;
  }
  parsing.erase (0, 1);
  ustring prefix = parsing.substr (0, 1);
  parsing.erase (0, 1);

  if (prefix == "n") {
    definition = "noun";
    bibleworks_define_parsing_case (parsing, definition);
    bibleworks_define_parsing_gender (parsing, definition);
    bibleworks_define_parsing_number (parsing, definition);
    return true;
  }

  if (prefix == "v") {
    definition = "verb";
    // Parsing of the verb may follow different routes depending on the length of the parsing.
    size_t length_after_v = parsing.length();
    if (length_after_v == 3) {
      bibleworks_define_parsing_mood (parsing, definition);
      bibleworks_define_parsing_tense (parsing, definition);
      bibleworks_define_parsing_voice (parsing, definition);
    }
    if (length_after_v == 4) {
      bibleworks_define_parsing_mood (parsing, definition);
      bibleworks_define_parsing_tense (parsing, definition);
      bibleworks_define_parsing_voice (parsing, definition);
    }
    if (length_after_v == 5) {
      bibleworks_define_parsing_mood (parsing, definition);
      bibleworks_define_parsing_tense (parsing, definition);
      bibleworks_define_parsing_voice (parsing, definition);
      bibleworks_define_parsing_person (parsing, definition);
      bibleworks_define_parsing_number (parsing, definition);
    }
    if (length_after_v == 6) {
      // These are the participles.
      bibleworks_define_parsing_mood (parsing, definition);
      bibleworks_define_parsing_tense (parsing, definition);
      bibleworks_define_parsing_voice (parsing, definition);
      bibleworks_define_parsing_case (parsing, definition);
      bibleworks_define_parsing_gender (parsing, definition);
      bibleworks_define_parsing_number (parsing, definition);
    }
    return true;
  }

  if (prefix == "a") {
    definition = "adjective";
    bibleworks_define_parsing_case (parsing, definition);
    bibleworks_define_parsing_gender (parsing, definition);
    bibleworks_define_parsing_number (parsing, definition);
    bibleworks_define_parsing_adjective_suffix (parsing, definition);
    return true;
  }

  if (prefix == "d") {
    definition = "definite article";
    bibleworks_define_parsing_case (parsing, definition);
    bibleworks_define_parsing_gender (parsing, definition);
    bibleworks_define_parsing_number (parsing, definition);
    return true;
  }

  if (prefix == "p") {
    definition = "preposition";
    return true;
  }

  if (prefix == "c") {
    definition = "conjunction";
    return true;
  }

  if (prefix == "x") {
    definition = "particle or disjunctive particle";
    bibleworks_define_parsing_particle_suffix (parsing, definition);
    return true;
  }

  if (prefix == "i") {
    definition = "interjection";
    return true;
  }

  if (prefix == "b") {
    definition = "adverb";
    bibleworks_define_parsing_adverb_suffix (parsing, definition);
    return true;
  }

  if (prefix == "r") {
    definition = "pronoun";
    bibleworks_define_parsing_pronoun (parsing, definition);
    bibleworks_define_parsing_case (parsing, definition);
    bibleworks_define_parsing_gender (parsing, definition);
    bibleworks_define_parsing_number (parsing, definition);
    return true;
  }

  if (prefix == "t") {
    definition = "indeclinable form";
    bibleworks_define_parsing_indeclinable_form_suffix (parsing, definition);
    return true;
  }

  if (prefix == "q") {
    definition = "conjunction or conjunctive part";
    bibleworks_define_parsing_conjunction_suffix (parsing, definition);
    return true;
  }

  return false;
}