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); } }
QString help::pretty_print (help::data_t data, bool terminal_output) { QString ret = ""; QTextStream out (&ret); out << data.first.join ("\n") << "\n"; std::size_t max_len = 0; /* Iterate over all parameter options and get max width. */ for (help::params_t::const_iterator it = data.second.constBegin (); it != data.second.constEnd (); ++it) { max_len = std::max (max_len, static_cast<std::size_t> ((*it).first.size ())); } std::size_t terminal_cols = 0; if (terminal_output) { #ifdef Q_OS_WIN CONSOLE_SCREEN_BUFFER_INFO terminal_internal; HANDLE stderr_handle = GetStdHandle (STD_ERROR_HANDLE); if (stderr_handle && (stderr_handle != INVALID_HANDLE_VALUE)) { if (GetConsoleScreenBufferInfo (stderr_handle, &terminal_internal)) { terminal_cols = (terminal_internal.srWindow.Right - terminal_internal.srWindow.Left) + 1; } } #elif defined (Q_OS_UNIX) struct winsize terminal_internal; ioctl (0, TIOCGWINSZ, &terminal_internal); terminal_cols = terminal_internal.ws_col; #endif } x2goDebug << "Terminal cols: " << terminal_cols << endl; for (help::params_t::const_iterator it = data.second.constBegin (); it != data.second.constEnd (); ++it) { std::size_t indent = (max_len - (*it).first.size ()) + 4; x2goDebug << "Indent: " << indent << "; max_len: " << max_len << "; param size: " << (*it).first.size () << endl; out << " "; out << (*it).first; out << QString (" ").repeated (indent); /* Append first two spaces to the general indent level for upcoming lines. */ indent += 2; std::ptrdiff_t remaining = 0; /* Split up description on newlines. */ QStringList desc_split = (*it).second.split ("\n"); for (QStringList::const_iterator desc_split_it = desc_split.constBegin (); desc_split_it != desc_split.constEnd (); ++desc_split_it) { std::size_t cur_len = (*desc_split_it).size (); x2goDebug << "Going to output a description " << (*desc_split_it).size () << " chars wide." << endl; if (0 != terminal_cols) { /* * Only set this the first time right after having written the parameter and indent spaces. * Don't change it after that. */ if (desc_split_it == desc_split.constBegin ()) { remaining = terminal_cols - (indent + (*it).first.size ()); } x2goDebug << "Still have " << remaining << " characters left on this line." << endl; /* Ran out of space? That's bad... print a newline and don't use any indentation level. */ if (0 > remaining) { x2goDebug << "Ran out of space! Will break line and start the description on a new one." << endl; out << "\n"; remaining = terminal_cols; indent = 0; } } QString working_copy (*desc_split_it); while (!working_copy.isEmpty ()) { cur_len = working_copy.size (); x2goDebug << "Trying to fit a (remaining) description " << cur_len << " characters wide." << endl; string_split_t string_split; if (0 != terminal_cols) { string_split = split_long_line (working_copy, remaining); } else { /* For non-terminal printing (or if the width is unknown), use the default splitting length. */ string_split = split_long_line (working_copy); } /* Print potentially splitted line. */ working_copy = string_split.first; out << working_copy; /* Continue with next chunk. */ working_copy = string_split.second;; out << "\n"; /* * Print whitespace if the remainder string is non-empty * or printing shall continue on next line. */ if ((!working_copy.isEmpty ()) || ((desc_split_it + 1) != desc_split.constEnd ())) { indent = 2 + max_len + 4; out << QString (" ").repeated (indent); } } } } if (terminal_output) { qCritical ().nospace () << qPrintable (ret); } return (ret); }