Пример #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;
}
Пример #2
0
bool replace_text(ustring & line, const ustring & look_for, const ustring & replace_with)
// Replaces some text. Returns true if any replacement was done.
{
  bool replacements_done = false;
  size_t offposition = line.find (look_for);
  while (offposition != string::npos) {
    line.replace (offposition, look_for.length (), replace_with);
    offposition = line.find (look_for, offposition + replace_with.length ());
    replacements_done = true;
  }
  return replacements_done;
}
Пример #3
0
void notes_handle_vcs_feedback (const ustring& directory, const ustring& feedback)
// This handles the feedback that comes from the version control system.
{
    if (directory == notes_shared_storage_folder ()) {

        unsigned int note_id = 0;

        // The following feedback indicates that somebody created a new note:
        // create mode 100644 27185458
        if (feedback.find ("create mode") != string::npos) {
            ustring s (feedback);
            s.erase (12);
            Parse parse (s);
            if (parse.words.size () == 2) {
                note_id = convert_to_int (parse.words[1]);
            }
        }

        // The following feedback indicates that somebody modified a note:
        // #	modified:   27185458
        if (feedback.find ("modified:") != string::npos) {
            ustring s (feedback);
            s.erase (12);
            note_id = convert_to_int (number_in_string (feedback));
        }

        // The following feedback indicates that somebody deleted a note:
        // #	deleted:    46473236
        if (feedback.find ("deleted:") != string::npos) {
            ustring s (feedback);
            s.erase (11);
            note_id = convert_to_int (number_in_string (feedback));
        }

        // See the following:
        // 95935882 |    9 +++++++++
        // It means that this note was edited.
        if (feedback.find (" |  ") != string::npos) {
            note_id = convert_to_int (number_in_string (feedback));
        }

        if (note_id != 0) {
            gw_message (_("Change detected for note ") + convert_to_string (note_id));
            // Update the index.
            sqlite3 *db;
            sqlite3_open(notes_index_filename ().c_str(), &db);
            sqlite3_busy_timeout(db, 1000);
            notes_store_index_entry (db, note_id);
            sqlite3_close(db);
        }
    }
}
Пример #4
0
void CheckChaptersVerses::store_expanded_verse(const ustring & verse, unsigned int verses_pointer, vector < unsigned int >&expanded_verses, vector < unsigned int >&verses_pointers)
{
  int expanded_verse;
  expanded_verse = 2 * (convert_to_int(verse));
  if (verse.find("b") == string::npos) {
    expanded_verses.push_back(expanded_verse);
    verses_pointers.push_back(verses_pointer);
  }
  if (verse.find("a") == string::npos) {
    expanded_verses.push_back(++expanded_verse);
    verses_pointers.push_back(verses_pointer);
  }
}
Пример #5
0
bool replace_text_between(ustring & line, const ustring & start, const ustring & end, const ustring & replacement)
// Replaces text that starts with "start" and ends with "end" with "replacement".
// Returns true if replacement was done.
{
  bool replacements_done = false;
  size_t beginpos = line.find(start);
  size_t endpos = line.find(end);
  while ((beginpos != string::npos) && (endpos != string::npos) && (endpos > beginpos)) {
    line.replace(beginpos, endpos - beginpos + end.length(), replacement);
    beginpos = line.find(start, beginpos + replacement.length());
    endpos = line.find(end, beginpos + replacement.length());
    replacements_done = true;
  }
  return replacements_done;
}
Пример #6
0
    InputMethodT makeIMFromString (ustring imStr) {
        InputMethodT im;
        _size_t_ eolPos;
        ustring transPortion;
        ustring specialToken = (imStr.find (" -> ") != ustring::npos) ?
            _(" -> ") : _(" ");

        while (imStr.length () > 1) {
            eolPos = imStr.find ("\n");
            transPortion = imStr.substr (0, eolPos);
            imStr = imStr.replace (0, eolPos + 1, "");
            im = addTransformation
                (im, transPortion.replace (1, specialToken.length (), ""));
        }
        return standardizeIM (im);
    }
Пример #7
0
void DataValue::parseArray(const ustring &text, void *value) {
	ArrayValue *arr = (ArrayValue*)value;
	int i = 1;	// skip [
	while (text[i] != ']') {
		i++;	// skip '
		int p = text.find('\'', i);
		void *v = arr->add(ustring(text, i, p - i));
		i = p + 2;	// skip =
		p = text.find(',', i);
		if(p == -1)
			p = text.length() - 1;
		parse(ustring(text, i, p - i), arr->type, v);
		i = p;
		if(text[i] == ',') i++;
	}
}
Пример #8
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);
	}
}
Пример #9
0
void Wordlist::process_line(ustring & line, set <ustring> &section_entries)
// Processes one line of text:
// - deals with entries.
// - deals with asterisks.
// section_entries - has the entries already made in this section.
{
  // Handle section restart.
  {
    ustring s (line);
    ustring marker = usfm_extract_marker (s);
    if (section_markers.find (marker) != section_markers.end()) {
      section_entries.clear();
    }
  }
  // Remove the asterisk before and the asterisk after the closer, e.g.:
  // \w entry*\w* -> \w entry\w*
  // \w entry\w** -> \w entry\w*
  replace_text(line, "*" + entry_closer, entry_closer);
  replace_text(line, entry_closer + "*", entry_closer);
  // Go through the line looking for the opener.
  size_t startpos = line.find(entry_opener);
  while (startpos != string::npos) {
    // Look for the closer too, after the opener, not before.
    size_t endpos = line.find(entry_closer, startpos);
    if (endpos == string::npos)
      break;
    // Get the word.
    ustring word = line.substr(startpos + entry_opener.length(), endpos - startpos - entry_closer.length());
    if (!word.empty()) {
      // Store the word.      
      words.insert(word);
      wordcount++;
      // Handle asterisks.
      if (use_asterisk) {
        bool insert_asterisk = true;
        if (first_in_chapter)
          if (section_entries.find(word) != section_entries.end())
            insert_asterisk = false;
        if (insert_asterisk) {
          line.insert(endpos + entry_closer.length(), "*");
        }
        section_entries.insert(word);
      }
    }
    startpos = line.find(entry_opener, endpos);
  }
}
Пример #10
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);
  }
}
Пример #11
0
PaletteItemGroup::PaletteItemGroup(Palette *parent, const ustring &name):PaletteItem(parent, name, "") {
	int p = name.find('_');
	if(p != -1)
		caption = name.substr(p+1, -1);
	minHeight = 14;
	height = minHeight;
	fullWidth = true;
}
Пример #12
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);
  }
}
Пример #13
0
  ustring replace(ustring source, ustring fromStr, ustring toStr, int offset, int times)
  {
    int total = 0;
    ustring::size_type pos=offset;
    while ( ( (pos = source.find(fromStr, pos)) < Glib::ustring::npos) && ( (times==0) || (total++<times) ) )
      {
	source.replace(pos, fromStr.length(), toStr);
	pos+=toStr.size();
      }
    return source;
  }
Пример #14
0
void xml_handle_entities(ustring & line, vector < size_t > *positions)
/*
  Changes the < and the > in the text to the xml entities &lt; and &gt
  Changes the ampersand (&) to &amp;
  Any positions affected by this will be adjusted.
*/
{
  size_t offposition;
  // Deal with &. This one is done first, 
  // else the ampersands inserted later will get changed too.
  offposition = line.find("&");
  while (offposition != string::npos) {
    line.replace(offposition, 1, "&amp;");
    if (positions)
      xml_positions_push_up(offposition, 4, *positions);
    // Do not repeat on the & just removed and inserted, but start searching after it.
    offposition = line.find("&", offposition + 3);
  }
  // Deal with <
  offposition = line.find("<");
  while (offposition != string::npos) {
    line.replace(offposition, 1, "&lt;");
    if (positions)
      xml_positions_push_up(offposition, 3, *positions);
    offposition = line.find("<", offposition);
  }
  // Deal with >
  offposition = line.find(">");
  while (offposition != string::npos) {
    line.replace(offposition, 1, "&gt;");
    if (positions)
      xml_positions_push_up(offposition, 3, *positions);
    offposition = line.find(">", offposition);
  }
}
Пример #15
0
void set_lyrics(DB_playItem_t *track, ustring lyrics) {
    signal_idle().connect_once([track, lyrics = move(lyrics)]() -> void {
        const char *artist, *title;
        {
            pl_lock_guard guard;

            if (!is_playing(track))
                return;
            artist = deadbeef->pl_find_meta(track, "artist");
            title  = deadbeef->pl_find_meta(track, "title");
        }
	if (!artist)
	    artist = _("Unknown Artist");
	if (!title)
	    title = _("Unknown Title");
        refBuffer->erase(refBuffer->begin(), refBuffer->end());
        refBuffer->insert_with_tags(refBuffer->begin(), title, tagsTitle);
        refBuffer->insert_with_tags(refBuffer->end(), ustring("\n") + artist + "\n\n", tagsArtist);

        bool italic = false;
        bool bold = false;
        size_t prev_mark = 0;
        vector<RefPtr<TextTag>> tags;
        while (prev_mark != ustring::npos) {
            size_t italic_mark = lyrics.find("''", prev_mark);
            if (italic_mark == ustring::npos)
                break;
            size_t bold_mark = ustring::npos;
            if (italic_mark < lyrics.size() - 2 && lyrics[italic_mark + 2] == '\'')
                bold_mark = italic_mark;

            tags.clear();
            if (italic) tags.push_back(tagItalic);
            if (bold)   tags.push_back(tagBold);
            refBuffer->insert_with_tags(refBuffer->end(),
                    lyrics.substr(prev_mark, min(bold_mark, italic_mark) - prev_mark), tags);

            if (bold_mark == ustring::npos) {
                prev_mark = italic_mark + 2;
                italic = !italic;
            } else {
                prev_mark = bold_mark + 3;
                bold = !bold;
            }
        }
        refBuffer->insert(refBuffer->end(), lyrics.substr(prev_mark)); // in case if no formatting found
        last = track;
    });
}
Пример #16
0
ustring resource_url_get(const ustring& url, const ustring& templatefile)
/*
 Some urls are given as full ones, e.g. http://bibledit.org.
 These don't need any modification.
 Other urls are given as plain filenames only. It is assumed for these that 
 they are given relative to the resource directory where these reside. 
 These need to be modified so as to include the full path and the file:// prefix.
 */
{
  ustring modified_url(url);
  if (url.find ("http") != 0) {
    ustring path = gw_path_get_dirname(templatefile);
    modified_url = resource_file_prefix();
    modified_url.append(gw_build_filename(path, url));
  }
  return modified_url;
}
Пример #17
0
  ustring replace(ustring source, std::map<ustring,ustring>strMap, int offset, int times)
  {
    int total = 0;
    ustring::size_type pos;

    for (std::map<ustring, ustring>::iterator i=strMap.begin(); i!=strMap.end(); ++i)
      {
	ustring fromStr = i->first;
	ustring toStr = i->second;
	pos=offset;
	while ( (pos = source.find(fromStr, pos)) < Glib::ustring::npos)
	  {
	    if ( (times!=0) && (total++>=times) )
	      return source;	// Don't work anymore

	    source.replace(pos, fromStr.length(), toStr);
	    pos+=toStr.size();
	  }
      }
    return source;
  }
Пример #18
0
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"));
    }
  }
}
Пример #19
0
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);
}
Пример #20
0
ustring shell_quote_space(const ustring & filename)
// Puts quotes and spaces around a filename, making it fit for the shell.
// Example: /home/user/John Johnson/.bibledit/projects/test/Genesis
// becomes: '/home/user/John Johnson/.bibledit/projects/test/Genesis'
// with an extra space prefixed and suffixed.
// Unix does not allow spaces in the user names, at the time of writing,
// but Windows does.
// This function was introduced to address this situation, but has a wider
// use too.
// In Windows, do not quote the name if it contains no space.
// Quoting the /s of the rmdir command, for example, confused the command.
{
  ustring quotedname;
#ifdef WIN32
  if (filename.find(" ") != string::npos)
    quotedname = " \"" + filename + "\" ";
  else
    quotedname = " " + filename + " ";
#else
  quotedname = " '" + filename + "' ";
#endif
  return quotedname;
}
Пример #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;
    
}
Пример #22
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);
}