예제 #1
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;
    });
}
예제 #2
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;
}
예제 #3
0
ustring string_reverse(const ustring & s)
{
  ustring returnvalue;
  for (int i = s.length() - 1; i >= 0; i--)
    returnvalue.append(s.substr(i, 1));
  return returnvalue;
}
예제 #4
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);
  }
}
예제 #5
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;
}
예제 #6
0
void gw_mkdir_with_parents(const ustring & directory)
// Creates directory, with the parents, if need be.
// Function mkdir could be used (see man 2 mkdir), but this does not allow for 
// the creation of the parent directories. The core utility mkdir provides
// this functionality, so is preferred, and used here.
// Later one g_mkdir_with_parents () was used, but this did not create 
// directories properly. Hence we are stuck with mkdir.
{
#if 0
  ustring s;
  GwSpawn spawn (Directories->get_mkdir());
  spawn.arg (Directories->get_mkdir_args());
  spawn.arg (directory);
/*   GwSpawn spawn("mkdir");
#ifndef WIN32
  spawn.arg("-p");
#endif
  spawn.arg(directory);
#ifdef WIN32
  spawn.devnull();
#endif
 */  spawn.run();
 #endif
 
#ifdef WIN32
	// Use Windows system call to do this "right"
	bool retval = CreateDirectory(directory.c_str(), NULL);
	// Returns 0 if OK
	// Returns non-zero if error, and GetLastError will tell us:
	// ERROR_ALREADY_EXISTS The specified directory already exists.
	// ERROR_PATH_NOT_FOUND One or more intermediate directories do not exist; this function will only create the final directory in the path.
	if (retval == 0) {
		int lasterr = GetLastError();
		if (lasterr == ERROR_ALREADY_EXISTS) { 
			// Not really an error, just informative
			mkdir_info("Already exists " + directory);
		}
		else if (lasterr == ERROR_PATH_NOT_FOUND) {
			mkdir_info("Cannot create " + directory + " because intermediate directories don't exist.");
			// Strip off last part of directory and try again recursively
			Glib::ustring::size_type idx = directory.find_last_of("\\");
			ustring newdir = directory.substr(0, idx);
			gw_mkdir_with_parents(newdir);
			// Now try the full path again
			gw_mkdir_with_parents(directory);
		}
	}
	else {
		// Not really an error, just informative
		mkdir_info("Created " + directory);
	}
#else
  GwSpawn spawn (Directories->get_mkdir());
  spawn.arg (Directories->get_mkdir_args());
  spawn.arg (directory);
  spawn.run();
#endif
}
예제 #7
0
void Query(ServerConnection *conn, const ustring& params)
{
    ustring::size_type pos1 = params.find_first_of(" ");
    ustring nick = params.substr(0, pos1);
    if (nick.empty()) {
        throw CommandException(_("/QUERY <nick>, start a query(tab) with a user"));
    } else {
        AppWin->getNotebook().addTab(Tab::QUERY, nick, conn);
    }
}
예제 #8
0
void CheckMatchingPairs::check_matched_pairs(ustring & text)
// Checks on matched pairs. Output any problems found.
{
  for (unsigned int i = 0; i < text.length(); i++) {
    // Get the unicode character;
    gunichar unichar;
    unichar = g_utf8_get_char(text.substr(i, 1).c_str());
    // If we found a mirror character, investigate further.
    gunichar mirror;
    if (g_unichar_get_mirror_char(unichar, &mirror)) {
      // Do we ignore this one?
      if (ignores.find(unichar) != ignores.end())
        continue;
      // See whether this one opens or closes a pair.
      if (gopeners.find(unichar) != gopeners.end()) {
        // It opens: Add data.
        MatchingPairOpener opener(text.substr(i, 1), unichar, book, chapter, verse, get_context(text, i));
        openers.push_back(opener);
        continue;
      } else {
        // It closes: check for previously seen opener.
        bool give_message = false;
        if (openers.empty()) {
          give_message = true;
        }
        if (!give_message) {
          if (openers[openers.size() - 1].unichar == mirror) {
            // Remove last one.
            openers.pop_back();
          } else {
            // Flag message.
            give_message = true;
          }
        }
        if (give_message) {
          // Give message;
          message(book, chapter, verse, _("Pair not opened: ") + get_context(text, i));
        }
      }
    }
  }
}
예제 #9
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;
}
예제 #10
0
float CFont::GetLineWidth(const ustring& text, size_t start /*= 0*/)
{
    size_t count = text.length()-start;
    for (int i = 0; i+start < text.size(); ++i)
    {
        if (text[i+start] == '\n')
        {
            count = i;
            break;
        }
    }
    return GetStringWidth(text.substr(start, count));
}
예제 #11
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;  
}
예제 #12
0
void xml_html_insert_emphasis(ustring & line, vector < size_t > &positions, vector < size_t > &lengths)
// This inserts the <b> tag to get the text bold.
{
  for (unsigned int i = 0; i < positions.size(); i++) {
    // Text to insert to highlight it.
    ustring taggedtext = "<b>" + line.substr(positions[i], lengths[i]) + "</b>";
    // Insert tag.
    line.replace(positions[i], lengths[i], taggedtext);
    // Push any following positions up.
    for (unsigned int i2 = i + 1; i2 < positions.size(); i2++) {
      positions[i2] = positions[i2] + 7;
    }
  }
}
예제 #13
0
static void split(std::vector<ustring>& strvec, const ustring& str) {
    size_t start = 0, np = ustring::npos;
    while (true) {
        size_t end = str.find_first_of(' ', start);
	size_t len = (end == np) ? np : end - start;
	if (len > 0) {
	    strvec.push_back(str.substr(start, len).lowercase());
	}
	if (end == np) {
	    return;
	}
        start = end + 1;
    }
}
예제 #14
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");
  }
}
예제 #15
0
filetype_t File::getFileType(ustring filename)
{
    // Extract file extension (i.e. "stl")
  ustring extension = filename.substr(filename.find_last_of(".")+1);


    if(extension == "wrl" || extension == "WRL") {
        return VRML;
    }

    if(extension == "amf" || extension == "AMF") {
        return AMF;
    }

    if(extension != "stl" && extension != "STL") {
        return NONE_STL;
    }

    ifstream file;
    file.open(filename.c_str());

    if(file.fail()) {
      cerr << _("Error: Unable to open file - ") << filename << endl;
      return NONE_STL;
    }

    // ASCII files start with "solid [Name_of_file]"
    ustring first_word;
    try {
      file >> first_word;

      // Find bad Solid Works STL header
      // 'solid binary STL from Solid Edge, Unigraphics Solutions Inc.'
      ustring second_word;
      if(first_word == "solid")
	file >> second_word;

      file.close();
      if(first_word == "solid" && second_word != "binary") { // ASCII
	return ASCII_STL;
      } else {
	return BINARY_STL;
      }
    } catch (Glib::ConvertError& e) {
      return BINARY_STL; // no keyword -> binary
    }

}
예제 #16
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);
  }
}
예제 #17
0
파일: Entry.cpp 프로젝트: WizardGed/lostirc
void findCommon(vector<ustring>& vec, const ustring& search, unsigned int& atchar)
{
    if (atchar > search.length())
          return;

    for (vector<ustring>::const_iterator i = vec.begin(); i != vec.end(); ++i)
    {
        if (atchar > i->length() ||
                search.substr(0, atchar).lowercase() != i->substr(0, atchar).lowercase()) {
            atchar--;
            return;
        }
    }
    findCommon(vec, search, ++atchar);

}
예제 #18
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);
    }
예제 #19
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);
  }
}
예제 #20
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");
}
예제 #21
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");
}
예제 #22
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);
  }
}
예제 #23
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");
  }
}
예제 #24
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);
}
예제 #25
0
/*
 * Extracts message string from specified buffer and returns
 * it in the form of string. If the buffer does not contain
 * full message, empty string is returned.
 */
CDCImplPrivate::ParsedMessage CDCImplPrivate::parseNextMessage(ustring& msgBuffer) {
	ParsedMessage parsedMessage;
	ustring parsedMsg;

	ParseResult parseResult = msgParser->parseData(msgBuffer);
	switch (parseResult.resultType) {
		case PARSE_OK:
			parsedMsg = msgBuffer.substr(0, parseResult.lastPosition+1);
			parsedMessage.message = parsedMsg;
			break;

		case PARSE_NOT_COMPLETE:
			parsedMessage.message = ustring(uchar_str(""));
			break;

		case PARSE_BAD_FORMAT:
            parsedMessage.message = ustring(uchar_str(""));
			break;
	}

    parsedMessage.parseResult = parseResult;
	return parsedMessage;
}
예제 #26
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");
  }
}
예제 #27
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");
}
예제 #28
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);
}
예제 #29
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;
    
}
예제 #30
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;
}