コード例 #1
0
ファイル: string.cpp プロジェクト: stephengold/gold-tiles
// Capitalize the first letter of each word.
// Trim leading and trailing non-graphic characters.
// Convert adjacent non-graphic characters a single space.
// Equal-signs (=) are treated as non-graphic characters.
void String::Capitalize(void) {
    bool after_graphic = false;
    String result;
    char const space = ' ';

    for (SizeType i_char = 0; i_char < Length(); i_char++) {
        char ch = at(i_char);
        bool const is_graphic = (::isgraph(ch) != 0 && ch != '=');

        if (!is_graphic) {
            ch = space;
        } else if (!after_graphic) {  // first letter of a word
            ch = char(::toupper(ch));
        }

        if (is_graphic || after_graphic) {
            result += ch;
        }

        after_graphic = is_graphic;
    }

    *this = result;

    if (!IsEmpty() && Last() == space) {
        // remove trailing space, which was originally some non-graphic character
        Shorten(1);
    }
}
コード例 #2
0
wxString FbViewThread::GetFiles(FbDatabase & database)
{
	int maxLength = FbParams(FB_FILE_LENGTH);
	int id = m_view.GetCode();
	wxString html;
	wxString sql = wxT("SELECT DISTINCT id_archive,file_name,1,id_archive*id_archive,file_type,md5sum FROM books WHERE id=?1 UNION ");
	sql << wxT("SELECT DISTINCT id_archive,file_name,2,id_archive*id_archive,NULL,NULL FROM files WHERE id_book=?1 ORDER BY 3,4");
	FbSQLite3Statement stmt = database.PrepareStatement(sql);
	stmt.Bind(1, id);
	FbSQLite3ResultSet result = stmt.ExecuteQuery();
	while (result.NextRow()) {
		html << wxT("<p>");
		if (id > 0 && result.GetInt(2) == 1) {
			wxString lib = FbParams(FB_CONFIG_TYPE);
			wxString md5 = result.GetAsString(wxT("md5sum"));
			wxString ext = result.GetAsString(wxT("file_type"));
			wxString str = wxString::Format(wxT("$(%s)/%d.%s"), lib.c_str(), id, ext.c_str());
			wxString url = FbInternetBook::GetURL(id, md5);
			html << wxString::Format(wxT("<a href=\"%s\">%s</a>"), url.c_str(), str.c_str());
		} else {
			html << wxT("<p>");
			if (int arch = result.GetInt(0)) {
				wxString url;
				wxString trg = result.GetString(1);
				wxString str = Shorten(result.GetString(1), maxLength);
				wxString sql = wxT("SELECT file_name FROM archives WHERE id="); sql << arch;
				FbSQLite3ResultSet result = database.ExecuteQuery(sql);
				if (result.NextRow()) {
					url = wxT("book:") + result.GetString(0);
					wxString str = Shorten(result.GetString(0), maxLength);
					html << wxString::Format(wxT("<a href=\"%s\">%s</a>"), url.c_str(), str.c_str());
					html << wxT(": ");
				}
				html << wxString::Format(wxT("<a href=\"%s\" target=\"%s\">%s</a>"), url.c_str(), trg.c_str(), str.c_str());
			} else {
				wxString url = wxT("book:") + result.GetString(1);
				wxString str = Shorten(result.GetString(1), maxLength);
				html << wxString::Format(wxT("<a href=\"%s\">%s</a>"), url.c_str(), str.c_str());
			}
		}
		html << wxT("</p>");
	}
	return html;
}