예제 #1
0
Glib::ustring MyComboBox::convertText(Glib::ustring inputText) {
	int pos = inputText.find_last_of('/');
	Glib::ustring text = inputText;
	int max = 0;
	if ((pos >= 0) && (inputText.size() > (unsigned) pos)) {
		max = (inputText.size() - (pos + 1)) > 50 ?
				50 : (inputText.size() - (pos + 1));
		text = Glib::ustring(inputText, ++pos, max);
	}
	return text;
}
예제 #2
0
/* 
 * Returns the file extension of a path/filename
 */
Glib::ustring Inkscape::IO::get_file_extension(Glib::ustring path)
{
    Glib::ustring::size_type period_location = path.find_last_of(".");
    return path.substr(period_location);
}
예제 #3
0
Glib::ustring sCutSuffix(const Glib::ustring & _rsString,
                         const Glib::ustring & _rsSep)
{
  return _rsString.substr(0, _rsString.find_last_of(_rsSep));
}
예제 #4
0
Glib::ustring Document::generateKey ()
{
	// Ideally Chambers06
	// If not then pap104
	// If not then Unnamed-5
	Glib::ustring name;

	Glib::ustring::size_type const maxlen = 14;

	if (!bib_.getAuthors().empty ()) {
		Glib::ustring year = bib_.getYear ();
		if (year.size() == 4)
			year = year.substr (2,3);

		Glib::ustring authors = bib_.getAuthors ();

		Glib::ustring::size_type comma = authors.find (",");
		Glib::ustring::size_type space = authors.find (" ");
		Glib::ustring::size_type snip = Glib::ustring::npos;

		if (comma != Glib::ustring::npos)
			snip = comma;
		if (space != Glib::ustring::npos && space < comma)
			snip = space;

		if (snip != Glib::ustring::npos)
			authors = authors.substr(0, snip);


		if (authors.size() > maxlen - 2) {
			authors = authors.substr(0, maxlen - 2);
		}

		// Should:
		// Truncate it at the first "et al", "and", or ","

		name = authors + year;
	} else if (!filename_.empty ()) {
		Glib::ustring filename = Gio::File::create_for_uri(filename_)->query_info()->get_display_name();

		Glib::ustring::size_type periodpos = filename.find_last_of (".");
		if (periodpos != std::string::npos) {
			filename = filename.substr (0, periodpos);
		}

		name = filename;
		if (name.size() > maxlen) {
			name = name.substr(0, maxlen);
		}

	} else {
		name = defaultKey_;
	}

	// Don't confuse LaTeX
	name = Utility::strip (name, " ");
	name = Utility::strip (name, "&");
	name = Utility::strip (name, "$");
	name = Utility::strip (name, "%");
	name = Utility::strip (name, "#");
	name = Utility::strip (name, "_");
	name = Utility::strip (name, "{");
	name = Utility::strip (name, "}");
	name = Utility::strip (name, ",");
	name = Utility::strip (name, "@");

	return name;
}