void ColumnUDA::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { if (task.has (_name)) { if (_style == "default") { std::string value = task.get (_name); if (_type == "date") { // Determine the output date format, which uses a hierarchy of definitions. // rc.report.<report>.dateformat // rc.dateformat.report // rc.dateformat. std::string format = context.config.get ("report." + _report + ".dateformat"); if (format == "") format = context.config.get ("dateformat.report"); if (format == "") format = context.config.get ("dateformat"); lines.push_back ( color.colorize ( leftJustify ( Date ((time_t) strtol (value.c_str (), NULL, 10)) .toString (format), width))); } else if (_type == "duration") { lines.push_back ( color.colorize ( rightJustify ( Duration (value).formatISO (), width))); } else if (_type == "string") { std::vector <std::string> raw; wrapText (raw, value, width, _hyphenate); std::vector <std::string>::iterator i; for (i = raw.begin (); i != raw.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); } else if (_type == "numeric") { lines.push_back (color.colorize (rightJustify (value, width))); } } else if (_style == "indicator") { if (task.has (_name)) lines.push_back ( color.colorize ( rightJustify (context.config.get ("uda." + _name + ".indicator"), width))); } } }
void Column::renderHeader ( std::vector <std::string>& lines, int width, Color& color) { if (context.verbose ("label") && nontrivial (_label)) { // Create a basic label. std::string header; header.reserve (width); header = _label; // Create a fungible copy. Color c = color; // Now underline the header, or add a dashed line. if (context.color () && context.config.getBoolean ("fontunderline")) { c.blend (Color (Color::nocolor, Color::nocolor, true, false, false)); lines.push_back (c.colorize (leftJustify (header, width))); } else { lines.push_back (c.colorize (leftJustify (header, width))); lines.push_back (c.colorize (std::string (width, '-'))); } } }
void ColumnString::render ( std::vector <std::string>& lines, const std::string& value, int width, Color& color) { if (_style == "default" || _style == "left") { std::vector <std::string> raw; wrapText (raw, value, width, _hyphenate); for (auto& i : raw) lines.push_back (color.colorize (leftJustify (i, width))); } else if (_style == "right") { std::vector <std::string> raw; wrapText (raw, value, width, _hyphenate); for (auto& i : raw) lines.push_back (color.colorize (rightJustify (i, width))); } else if (_style == "left_fixed") { lines.push_back (leftJustify (value, width)); } else if (_style == "right_fixed") { lines.push_back (rightJustify (value, width)); } }
void ColumnParent::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { if (task.has (_name)) { // f30cb9c3-3fc0-483f-bfb2-3bf134f00694 default // 34f00694 short if (_style == "default" || _style == "long") { lines.push_back (color.colorize (leftJustify (task.get (_name), width))); } else if (_style == "short") { if (task.has (_name)) lines.push_back (color.colorize (leftJustify (task.get (_name).substr (28), width))); else lines.push_back (color.colorize (leftJustify ("", width))); } } }
void ColumnBg::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { std::string bg = task.get (_name); std::vector <std::string> raw; wrapText (raw, bg, width, _hyphenate); std::vector <std::string>::iterator i; for (i = raw.begin (); i != raw.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); }
void ColumnTags::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { if (task.has (_name)) { std::string tags = task.get (_name); if (_style == "default" || _style == "list") { std::vector <std::string> allTags; split (allTags, tags, ','); if (allTags.size () > 1) { std::sort (allTags.begin (), allTags.end ()); join (tags, " ", allTags); } std::vector <std::string> all; wrapText (all, tags, width, _hyphenate); for (auto& i : all) lines.push_back (color.colorize (leftJustify (i, width))); } else if (_style == "indicator") { lines.push_back ( color.colorize ( rightJustify (context.config.get ("tag.indicator"), width))); } else if (_style == "count") { std::vector <std::string> all; split (all, tags, ','); lines.push_back ( color.colorize ( rightJustify ("[" + format ((int)all.size ()) + "]", width))); } } }
void SEMHeader::reallyPutRecord(FFStream& ffs) const throw(std::exception, FFStreamError, gpstk::StringUtils::StringException) { string line; SEMStream& strm = dynamic_cast<SEMStream&>(ffs); line = leftJustify(asString<short>(numRecords),2); line += " "; line += Title; strm << line << endl; line.erase(); line = rightJustify(asString<short>(week),4); line += " "; line += asString<long>(Toa); strm << line << endl; line.erase(); } // end SEMAHeader::reallyPutRecord
void ColumnTags::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { std::string tags = task.get (_name); if (tags != "") { if (_style == "indicator") { lines.push_back ( color.colorize ( rightJustify (context.config.get ("tag.indicator"), width))); } else if (_style == "count") { std::vector <std::string> all; split (all, tags, ','); lines.push_back ( color.colorize ( rightJustify ("[" + format ((int)all.size ()) + "]", width))); } else if (_style == "default" || _style == "list") { std::replace (tags.begin (), tags.end (), ',', ' '); std::vector <std::string> all; wrapText (all, tags, width, _hyphenate); std::vector <std::string>::iterator i; for (i = all.begin (); i != all.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); } } }
void ColumnDate::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { if (task.has (_name)) { Date date (task.get_date (_name)); if (_style == "default" || _style == "formatted") { // Determine the output date format, which uses a hierarchy of definitions. // rc.report.<report>.dateformat // rc.dateformat.report // rc.dateformat std::string format = context.config.get ("report." + _report + ".dateformat"); if (format == "") format = context.config.get ("dateformat.report"); if (format == "") format = context.config.get ("dateformat"); lines.push_back ( color.colorize ( leftJustify ( date.toString (format), width))); } else if (_style == "countdown") { Date now; lines.push_back ( color.colorize ( rightJustify ( Duration (now - date).format (), width))); } else if (_style == "julian") { lines.push_back ( color.colorize ( rightJustify ( format (date.toJulian (), 13, 12), width))); } else if (_style == "epoch") { lines.push_back ( color.colorize ( rightJustify ( date.toEpochString (), width))); } else if (_style == "iso") { lines.push_back ( color.colorize ( leftJustify ( date.toISO (), width))); } else if (_style == "age") { Date now; lines.push_back ( color.colorize ( leftJustify ( Duration (now - date).formatCompact (), width))); } else if (_style == "remaining") { Date now; if (date > now) lines.push_back ( color.colorize ( rightJustify ( Duration (date - now).format (), width))); else lines.push_back (""); } } }
// prints the required arguments first (if any) then the optional // ones (if any) ostream& CommandOptionParser::displayUsage(ostream& out, bool doPretty) { CommandOptionVec::size_type index; CommandOption *trailing = NULL; char *colch = getenv("COLUMNS"); int columns = 80; unsigned maxlen = 0; if (colch) { string colStr(colch); columns = asInt(colStr); } // find the trailing argument if any, and max option string length for (index = 0; index < optionVec.size(); index++) { if (optionVec[index]->optType == CommandOption::trailingType) trailing = optionVec[index]; else if (optionVec[index]->optType == CommandOption::stdType) maxlen = std::max(maxlen, unsigned(optionVec[index]->getFullOptionString().length())); } out << "Usage: " << progName; if (hasRequiredArguments || hasOptionalArguments) out << " [OPTION] ..."; if (trailing) out << " " << trailing->description; out << endl << (doPretty ? prettyPrint(text,"\n","","",columns) : text); // << endl // << endl // << "Command options:" << endl; for(int required = 1; required >= 0; required--) { if (required==1 && hasRequiredArguments) out << endl << "Required arguments:" << endl; else if (required==0 && hasOptionalArguments) out << endl << "Optional arguments:" << endl; for(index = 0; index < optionVec.size(); index++) { if ((optionVec[index]->required == (required==1)) && (optionVec[index]->optType == CommandOption::stdType)) { string optstr(optionVec[index]->getFullOptionString()); string desc(optionVec[index]->description); string indent(maxlen, ' '); if(doPretty) { leftJustify(optstr, maxlen); prettyPrint(desc, "\n", indent, optstr, columns); } out << desc; if(!doPretty) out << endl; } } } return out; }
//////////////////////////////////////////////////////////////////////////////// // Graph should render like this: // +---------------------------------------------------------------------+ // | | // | 20 | | // | | DD DD DD DD DD DD DD DD | // | | DD DD DD DD DD DD DD DD DD DD DD DD DD DD | // | | PP PP SS SS SS SS SS SS SS SS SS DD DD DD DD DD DD DD Done | // | 10 | PP PP PP PP PP PP SS SS SS SS SS SS DD DD DD DD DD SS Started| // | | PP PP PP PP PP PP PP PP PP PP PP SS SS SS SS DD DD PP Pending| // | | PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP SS DD | // | | PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP PP | // | 0 +---------------------------------------------------- | // | 21 22 23 24 25 26 27 28 29 30 31 01 02 03 04 05 06 | // | July August | // | | // | ADD rate 1.7/d Estimated completion 8/12/2010 | // | Don/Delete rate 1.3/d | // +---------------------------------------------------------------------+ std::string Chart::render () { if (graph_height < 5 || // a 4-line graph is essentially unreadable. graph_width < 2) // A single-bar graph is useless. { return std::string (STRING_CMD_BURN_TOO_SMALL) + "\n"; } if (max_value == 0) context.footnote (STRING_FEEDBACK_NO_MATCH); // Create a grid, folded into a string. grid = ""; for (int i = 0; i < height; ++i) grid += std::string (width, ' ') + "\n"; // Title. std::string full_title; switch (period) { case 'D': full_title = STRING_CMD_BURN_DAILY; break; case 'W': full_title = STRING_CMD_BURN_WEEKLY; break; case 'M': full_title = STRING_CMD_BURN_MONTHLY; break; } full_title += std::string (" ") + STRING_CMD_BURN_TITLE; if (title.length ()) { if (full_title.length () + 1 + title.length () < (unsigned) width) { full_title += " " + title; grid.replace (LOC (0, (width - full_title.length ()) / 2), full_title.length (), full_title); } else { grid.replace (LOC (0, (width - full_title.length ()) / 2), full_title.length (), full_title); grid.replace (LOC (1, (width - title.length ()) / 2), title.length (), title); } } else { grid.replace (LOC (0, (width - full_title.length ()) / 2), full_title.length (), full_title); } // Legend. grid.replace (LOC (graph_height / 2 - 1, width - 10), 10, "DD " + leftJustify (STRING_CMD_BURN_DONE, 7)); grid.replace (LOC (graph_height / 2, width - 10), 10, "SS " + leftJustify (STRING_CMD_BURN_STARTED, 7)); grid.replace (LOC (graph_height / 2 + 1, width - 10), 10, "PP " + leftJustify (STRING_CMD_BURN_PENDING, 7)); // Determine y-axis labelling. std::vector <int> labels; yLabels (labels); max_label = (int) log10 ((double) labels[2]) + 1; // Draw y-axis. for (int i = 0; i < graph_height; ++i) grid.replace (LOC (i + 1, max_label + 1), 1, "|"); // Draw y-axis labels. char label [12]; sprintf (label, "%*d", max_label, labels[2]); grid.replace (LOC (1, max_label - strlen (label)), strlen (label), label); sprintf (label, "%*d", max_label, labels[1]); grid.replace (LOC (1 + (graph_height / 2), max_label - strlen (label)), strlen (label), label); grid.replace (LOC (graph_height + 1, max_label - 1), 1, "0"); // Draw x-axis. grid.replace (LOC (height - 6, max_label + 1), 1, "+"); grid.replace (LOC (height - 6, max_label + 2), graph_width, std::string (graph_width, '-')); // Draw x-axis labels. std::vector <time_t> bars_in_sequence; std::map <time_t, Bar>::iterator it; for (it = bars.begin (); it != bars.end (); ++it) bars_in_sequence.push_back (it->first); std::sort (bars_in_sequence.begin (), bars_in_sequence.end ()); std::vector <time_t>::iterator seq; std::string major_label; for (seq = bars_in_sequence.begin (); seq != bars_in_sequence.end (); ++seq) { Bar bar = bars[*seq]; // If it fits within the allowed space. if (bar.offset < actual_bars) { grid.replace (LOC (height - 5, max_label + 3 + ((actual_bars - bar.offset - 1) * 3)), bar.minor_label.length (), bar.minor_label); if (major_label != bar.major_label) grid.replace (LOC (height - 4, max_label + 2 + ((actual_bars - bar.offset - 1) * 3)), bar.major_label.length (), " " + bar.major_label); major_label = bar.major_label; } } // Draw bars. for (seq = bars_in_sequence.begin (); seq != bars_in_sequence.end (); ++seq) { Bar bar = bars[*seq]; // If it fits within the allowed space. if (bar.offset < actual_bars) { int pending = ( bar.pending * graph_height) / labels[2]; int started = ((bar.pending + bar.started) * graph_height) / labels[2]; int done = ((bar.pending + bar.started + bar.done + carryover_done) * graph_height) / labels[2]; for (int b = 0; b < pending; ++b) grid.replace (LOC (graph_height - b, max_label + 3 + ((actual_bars - bar.offset - 1) * 3)), 2, "PP"); for (int b = pending; b < started; ++b) grid.replace (LOC (graph_height - b, max_label + 3 + ((actual_bars - bar.offset - 1) * 3)), 2, "SS"); for (int b = started; b < done; ++b) grid.replace (LOC (graph_height - b, max_label + 3 + ((actual_bars - bar.offset - 1) * 3)), 2, "DD"); } } // Draw rates. calculateRates (bars_in_sequence); char rate[12]; if (find_rate != 0.0) sprintf (rate, "%.1f/d", find_rate); else strcpy (rate, "-"); grid.replace (LOC (height - 2, max_label + 3), 18 + strlen (rate), std::string ("Add rate: ") + rate); if (fix_rate != 0.0) sprintf (rate, "%.1f/d", fix_rate); else strcpy (rate, "-"); grid.replace (LOC (height - 1, max_label + 3), 18 + strlen (rate), std::string ("Done/Delete rate: ") + rate); // Draw completion date. if (completion.length ()) grid.replace (LOC (height - 2, max_label + 32), 22 + completion.length (), "Estimated completion: " + completion); optimizeGrid (); if (context.color ()) { // Colorize the grid. Color color_pending (context.config.get ("color.burndown.pending")); Color color_done (context.config.get ("color.burndown.done")); Color color_started (context.config.get ("color.burndown.started")); // Replace DD, SS, PP with colored strings. std::string::size_type i; while ((i = grid.find ("PP")) != std::string::npos) grid.replace (i, 2, color_pending.colorize (" ")); while ((i = grid.find ("SS")) != std::string::npos) grid.replace (i, 2, color_started.colorize (" ")); while ((i = grid.find ("DD")) != std::string::npos) grid.replace (i, 2, color_done.colorize (" ")); } else { // Replace DD, SS, PP with ./+/X strings. std::string::size_type i; while ((i = grid.find ("PP")) != std::string::npos) grid.replace (i, 2, " X"); while ((i = grid.find ("SS")) != std::string::npos) grid.replace (i, 2, " +"); while ((i = grid.find ("DD")) != std::string::npos) grid.replace (i, 2, " ."); } return grid; }
void ColumnDescription::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { std::string description = task.get (_name); // This is a description // <date> <anno> // ... if (_style == "default" || _style == "combined") { std::map <std::string, std::string> annos; task.getAnnotations (annos); if (annos.size ()) { for (auto& i : annos) { ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10)); description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i.second; } } std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); for (auto& i : raw) lines.push_back (color.colorize (leftJustify (i, width))); } // This is a description else if (_style == "desc") { std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); for (auto& i : raw) lines.push_back (color.colorize (leftJustify (i, width))); } // This is a description <date> <anno> ... else if (_style == "oneline") { std::map <std::string, std::string> annos; task.getAnnotations (annos); if (annos.size ()) { for (auto& i : annos) { ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10)); description += " " + dt.toString (_dateformat) + " " + i.second; } } std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); for (auto& i : raw) lines.push_back (color.colorize (leftJustify (i, width))); } // This is a des... else if (_style == "truncated") { int len = utf8_width (description); if (len > width) lines.push_back (color.colorize (description.substr (0, width - 3) + "...")); else lines.push_back (color.colorize (leftJustify (description, width))); } // This is a description [2] else if (_style == "count") { std::map <std::string, std::string> annos; task.getAnnotations (annos); if (annos.size ()) description += " [" + format ((int) annos.size ()) + "]"; std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); for (auto& i : raw) lines.push_back (color.colorize (leftJustify (i, width))); } // This is a des... [2] else if (_style == "truncated_count") { std::map <std::string, std::string> annos; task.getAnnotations (annos); int len = utf8_width (description); std::string annos_count; int len_annos = 0; if (annos.size ()) { annos_count = " [" + format ((int) annos.size ()) + "]"; len_annos = utf8_width (annos_count); len += len_annos; } if (len > width) lines.push_back (color.colorize (description.substr (0, width - len_annos - 3) + "..." + annos_count)); else lines.push_back (color.colorize (leftJustify (description + annos_count, width))); } }
void RinexMetHeader::reallyPutRecord(FFStream& ffs) const throw(std::exception, FFStreamError, gpstk::StringUtils::StringException) { RinexMetStream& strm = dynamic_cast<RinexMetStream&>(ffs); // since they want to output this header, let's store // it internally for use by the data strm.header = (*this); // i'm casting out const here to set the correct required valid bits. // deal with it =P unsigned long allValid; if (version == 2.0) allValid = allValid20; else if (version == 2.1) allValid = allValid21; else { FFStreamError err("Unknown RINEX version: " + asString(version,2)); err.addText("Make sure to set the version correctly."); GPSTK_THROW(err); } if ((valid & allValid) != allValid) { string errstr("Incomplete or invalid header: missing: "); errstr += bitString(allValid & ~valid); FFStreamError err(errstr); err.addText("Make sure you set all header valid bits for all of the available data."); GPSTK_THROW(err); } string line; // line by line, let's do this. if (valid & versionValid) { line = rightJustify(asString(version,2), 9); line += string(11, ' '); line += leftJustify(fileType, 40); line += versionString; strm << line << endl; strm.lineNumber++; } if (valid & runByValid) { line = leftJustify(fileProgram,20); line += leftJustify(fileAgency,20); DayTime dt; dt.setLocalTime(); string dat = dt.printf("%02m/%02d/%04Y %02H:%02M:%02S"); line += leftJustify(dat, 20); line += runByString; strm << line << endl; strm.lineNumber++; } if (valid & commentValid) { vector<string>::const_iterator itr = commentList.begin(); while (itr != commentList.end()) { line = leftJustify((*itr), 60); line += commentString; strm << line << endl; strm.lineNumber++; itr++; } } if (valid & markerNameValid) { line = leftJustify(markerName, 60); line += markerNameString; strm << line << endl; strm.lineNumber++; } if (valid & markerNumberValid) { line = leftJustify(markerNumber, 60); line += markerNumberString; strm << line << endl; strm.lineNumber++; } if (valid & obsTypeValid) { line = rightJustify(asString(obsTypeList.size()),6); vector<RinexMetType>::const_iterator itr = obsTypeList.begin(); size_t numWritten = 0; while (itr != obsTypeList.end()) { numWritten++; // stupid continuation lines =P if ((numWritten % (maxObsPerLine+1)) == 0) { line += obsTypeString; strm << line << endl; strm.lineNumber++; line = string(6,' '); } line += rightJustify(convertObsType(*itr), 6); itr++; } // pad the line out to 60 chrs and add label line += string(60 - line.size(), ' '); line += obsTypeString; strm << line << endl; strm.lineNumber++; } if (valid & sensorTypeValid) { // only write out the sensor types that are // in the obsTypeList vector<sensorType>::const_iterator itr = sensorTypeList.begin(); while (itr != sensorTypeList.end()) { if (std::find(obsTypeList.begin(), obsTypeList.end(), (*itr).obsType) != obsTypeList.end()) { line = leftJustify((*itr).model, 20); line += leftJustify((*itr).type, 20); line += string(6, ' '); line += rightJustify(asString((*itr).accuracy,1),7); line += string(4, ' '); line += convertObsType((*itr).obsType); line += string(1, ' '); line += sensorTypeString; strm << line << endl; strm.lineNumber++; } itr++; } } if (valid & sensorPosValid) { // only write out the sensor positions that are // in the obsTypeList vector<sensorPosType>::const_iterator itr = sensorPosList.begin(); while (itr != sensorPosList.end()) { if (std::find(obsTypeList.begin(), obsTypeList.end(), (*itr).obsType) != obsTypeList.end()) { line = rightJustify(asString((*itr).position[0],4),14); line += rightJustify(asString((*itr).position[1],4),14); line += rightJustify(asString((*itr).position[2],4),14); line += rightJustify(asString((*itr).height,4),14); line += string(1, ' '); line += convertObsType((*itr).obsType); line += string(1, ' '); line += sensorPosString; strm << line << endl; strm.lineNumber++; } itr++; } } if (valid & endValid) { line = string(60, ' '); line += endOfHeader; strm << line << endl; strm.lineNumber++; } }
void YumaData::reallyPutRecord(FFStream& ffs) const throw(std::exception, FFStreamError, gpstk::StringUtils::StringException) { string line; YumaStream& strm = dynamic_cast<YumaStream&>(ffs); // first the epoch line to 'line' line = "******** Week"; int epochWeek = week % 1024; line += rightJustify(asString<short>(epochWeek), 5); line += " almanac for PRN-"; line += rightJustify(asString<short>(PRN), 2, '0'); line += " ********"; // write the header line strm << line << endl; line.erase(); // Write the ID line line = sID; line += rightJustify(asString<short>(PRN),2,'0'); strm << line << endl; line.erase(); // Write the Health line line = sHlth; line += rightJustify(asString<short>(SV_health),3,'0'); // should be hex strm << line << endl; line.erase(); // Write the Ecc line line = sEcc; line += leftJustify(asString(doub2for(ecc,17,3,false)),18); strm << line << endl; line.erase(); // Write the Toa line line = sTOA; line += leftJustify(asString((double)Toa,4),11); strm << line << endl; line.erase(); // Write the Orbital Inc line line = sOrbI; double i_total = i_offset + 54.0 * (gpstk::PI / 180.0 ); if (i_total >=0) line += " "; line += leftJustify(asString(i_total,10),17); strm << line << endl; line.erase(); // Write the Rate of Right Ascen line line = sRRA; line += leftJustify(asString(doub2for(OMEGAdot,17,3,false)),18); strm << line << endl; line.erase(); // Write the SqrtA line line = sSqrA; line += " "; line += leftJustify(asString(Ahalf,6),18); strm << line << endl; line.erase(); // Write the Right Ascen at Week line line = sRtAs; line += leftJustify(asString(doub2for(OMEGA0,17,3,false)),18); strm << line << endl; line.erase(); // Write the Argument of Perigee line line = sArgP; if (w>=0) line += " "; line += leftJustify(asString(w,9),18); strm << line << endl; line.erase(); // Write Mean Anomaly line line = sMnAn; line += leftJustify(asString(doub2for(M0,17,3,false)),18); strm << line << endl; line.erase(); // Write the Af0 line line = sAf0; line += leftJustify(asString(doub2for(AF0,17,3,false)),18); strm << line << endl; line.erase(); // Write the AF1 line line = sAf1; line += leftJustify(asString(doub2for(AF1,17,3,false)),18); // should be hex strm << line << endl; line.erase(); // Write the week line line = sweek; line += rightJustify(asString<short>(epochWeek),5); // should be hex strm << line << endl; line.erase(); strm << endl; } // end YumaData::reallyPutRecord
void ColumnDescription::render ( std::vector <std::string>& lines, Task& task, int width, Color& color) { std::string description = task.get (_name); // This is a description // <date> <anno> // ... if (_style == "default" || _style == "combined") { std::map <std::string, std::string> annos; task.getAnnotations (annos); if (annos.size ()) { std::map <std::string, std::string>::iterator i; for (i = annos.begin (); i != annos.end (); i++) { Date dt (strtol (i->first.substr (11).c_str (), NULL, 10)); description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i->second; } } std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); std::vector <std::string>::iterator i; for (i = raw.begin (); i != raw.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); } // This is a description else if (_style == "desc") { std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); std::vector <std::string>::iterator i; for (i = raw.begin (); i != raw.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); } // This is a description <date> <anno> ... else if (_style == "oneline") { std::map <std::string, std::string> annos; task.getAnnotations (annos); if (annos.size ()) { std::map <std::string, std::string>::iterator i; for (i = annos.begin (); i != annos.end (); i++) { Date dt (atoi (i->first.substr (11).c_str ())); description += " " + dt.toString (_dateformat) + " " + i->second; } } std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); std::vector <std::string>::iterator i; for (i = raw.begin (); i != raw.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); } // This is a des... else if (_style == "truncated") { int len = utf8_width (description); if (len > width) lines.push_back (color.colorize (description.substr (0, width - 3) + "...")); else lines.push_back (color.colorize (leftJustify (description, width))); } // This is a description [2] else if (_style == "count") { std::map <std::string, std::string> annos; task.getAnnotations (annos); if (annos.size ()) description += " [" + format ((int) annos.size ()) + "]"; std::vector <std::string> raw; wrapText (raw, description, width, _hyphenate); std::vector <std::string>::iterator i; for (i = raw.begin (); i != raw.end (); ++i) lines.push_back (color.colorize (leftJustify (*i, width))); } }
void RinexNavHeader::reallyPutRecord(FFStream& ffs) const throw(std::exception, FFStreamError, StringException) { RinexNavStream& strm = dynamic_cast<RinexNavStream&>(ffs); strm.header = (*this); unsigned long allValid; if (version == 2.0) allValid = allValid20; else if (version == 2.1) allValid = allValid21; else if (version == 2.11) allValid = allValid211; else { FFStreamError err("Unknown RINEX version: " + asString(version,3)); err.addText("Make sure to set the version correctly."); GPSTK_THROW(err); } if ((valid & allValid) != allValid) { FFStreamError err("Incomplete or invalid header."); err.addText("Make sure you set all header valid bits for all of the available data."); GPSTK_THROW(err); } string line; if (valid & versionValid) { line = rightJustify(asString(version,3), 10); line += string(10, ' '); line += string("NAVIGATION"); //leftJustify(fileType, 20); line += string(30, ' '); line += versionString; strm << line << endl; strm.lineNumber++; } if (valid & runByValid) { line = leftJustify(fileProgram,20); line += leftJustify(fileAgency,20); DayTime dt; dt.setLocalTime(); string dat = dt.printf("%02m/%02d/%04Y %02H:%02M:%02S"); line += leftJustify(dat, 20); line += runByString; strm << line << endl; strm.lineNumber++; } if (valid & commentValid) { vector<string>::const_iterator itr = commentList.begin(); while (itr != commentList.end()) { line = leftJustify((*itr), 60); line += commentString; strm << line << endl; strm.lineNumber++; itr++; } } if (valid & ionAlphaValid) { line = string(2, ' '); for (int i = 0; i < 4; i++) { line += rightJustify(doub2for(ionAlpha[i], 12, 2),12); // should be 12.4 } line += string(10, ' '); line += ionAlphaString; strm << line << endl; strm.lineNumber++; } if (valid & ionBetaValid) { line = string(2, ' '); for (int i = 0; i < 4; i++) { line += rightJustify(doub2for(ionBeta[i], 12, 2),12); } line += string(10, ' '); line += ionBetaString; strm << line << endl; strm.lineNumber++; } if (valid & deltaUTCValid) { line = string(3, ' '); //line += string(2, ' '); line += doub2for(A0, 19, 2); line += doub2for(A1, 19, 2); line += rightJustify(asString(UTCRefTime),9); line += rightJustify(asString(UTCRefWeek),9); line += string(1, ' '); line += deltaUTCString; strm << line << endl; strm.lineNumber++; } if (valid & leapSecondsValid) { line = rightJustify(asString(leapSeconds), 6); line += string(54, ' '); line += leapSecondsString; strm << line << endl; strm.lineNumber++; } if (valid & endValid) { line = string(60,' '); line += endOfHeader; strm << line << endl; strm.lineNumber++; } }
int main (int argc, char** argv) { UnitTest t (264); // void wrapText (std::vector <std::string>& lines, const std::string& text, const int width, bool hyphenate) std::string text = "This is a test of the line wrapping code."; std::vector <std::string> lines; wrapText (lines, text, 10, true); t.is (lines.size (), (size_t) 5, "wrapText 'This is a test of the line wrapping code.' -> total 5 lines"); t.is (lines[0], "This is a", "wrapText line 0 -> 'This is a'"); t.is (lines[1], "test of", "wrapText line 1 -> 'test of'"); t.is (lines[2], "the line", "wrapText line 2 -> 'the line'"); t.is (lines[3], "wrapping", "wrapText line 3 -> 'wrapping'"); t.is (lines[4], "code.", "wrapText line 4 -> 'code.'"); text = "This ☺ is a test of utf8 line extraction."; lines.clear (); wrapText (lines, text, 7, true); t.is (lines.size (), (size_t) 7, "wrapText 'This ☺ is a test of utf8 line extraction.' -> total 7 lines"); t.is (lines[0], "This ☺", "wrapText line 0 -> 'This ☺'"); t.is (lines[1], "is a", "wrapText line 1 -> 'is a'"); t.is (lines[2], "test of", "wrapText line 2 -> 'test of'"); t.is (lines[3], "utf8", "wrapText line 3 -> 'utf8'"); t.is (lines[4], "line", "wrapText line 4 -> 'line'"); t.is (lines[5], "extrac-", "wrapText line 5 -> 'extrac-'"); t.is (lines[6], "tion.", "wrapText line 6 -> 'tion.'"); text = "one two three\n four"; lines.clear (); wrapText (lines, text, 13, true); t.is (lines.size (), (size_t) 2, "wrapText 'one two three\\n four' -> 2 lines"); t.is (lines[0], "one two three", "wrapText line 0 -> 'one two three'"); t.is (lines[1], " four", "wrapText line 1 -> ' four'"); // void extractLine (std::string& text, std::string& line, int length, bool hyphenate, unsigned int& offset) text = "This ☺ is a test of utf8 line extraction."; unsigned int offset = 0; std::string line; extractLine (line, text, 7, true, offset); t.is (line, "This ☺", "extractLine 7 'This ☺ is a test of utf8 line extraction.' -> 'This ☺'"); // void extractLine (std::string& text, std::string& line, int length, bool hyphenate, unsigned int& offset) text = "line 1\nlengthy second line that exceeds width"; offset = 0; extractLine (line, text, 10, true, offset); t.is (line, "line 1", "extractLine 10 'line 1\\nlengthy second line that exceeds width' -> 'line 1'"); extractLine (line, text, 10, true, offset); t.is (line, "lengthy", "extractLine 10 'lengthy second line that exceeds width' -> 'lengthy'"); extractLine (line, text, 10, true, offset); t.is (line, "second", "extractLine 10 'second line that exceeds width' -> 'second'"); extractLine (line, text, 10, true, offset); t.is (line, "line that", "extractLine 10 'line that exceeds width' -> 'line that'"); extractLine (line, text, 10, true, offset); t.is (line, "exceeds", "extractLine 10 'exceeds width' -> 'exceeds'"); extractLine (line, text, 10, true, offset); t.is (line, "width", "extractLine 10 'width' -> 'width'"); t.notok (extractLine (line, text, 10, true, offset), "extractLine 10 '' -> ''"); // void split (std::vector<std::string>& results, const std::string& input, const char delimiter) std::vector <std::string> items; std::string unsplit = ""; split (items, unsplit, '-'); t.is (items.size (), (size_t) 0, "split '' '-' -> 0 items"); unsplit = "a"; split (items, unsplit, '-'); t.is (items.size (), (size_t) 1, "split 'a' '-' -> 1 item"); t.is (items[0], "a", "split 'a' '-' -> 'a'"); split (items, unsplit, '-'); t.is (items.size (), (size_t) 1, "split 'a' '-' -> 1 item"); t.is (items[0], "a", "split 'a' '-' -> 'a'"); unsplit = "-"; split (items, unsplit, '-'); t.is (items.size (), (size_t) 2, "split '-' '-' -> '' ''"); t.is (items[0], "", "split '-' '-' -> [0] ''"); t.is (items[1], "", "split '-' '-' -> [1] ''"); split_minimal (items, unsplit, '-'); t.is (items.size (), (size_t) 0, "split '-' '-' ->"); unsplit = "-a-bc-def"; split (items, unsplit, '-'); t.is (items.size (), (size_t) 4, "split '-a-bc-def' '-' -> '' 'a' 'bc' 'def'"); t.is (items[0], "", "split '-a-bc-def' '-' -> [0] ''"); t.is (items[1], "a", "split '-a-bc-def' '-' -> [1] 'a'"); t.is (items[2], "bc", "split '-a-bc-def' '-' -> [2] 'bc'"); t.is (items[3], "def", "split '-a-bc-def' '-' -> [3] 'def'"); split_minimal (items, unsplit, '-'); t.is (items.size (), (size_t) 3, "split '-a-bc-def' '-' -> 'a' 'bc' 'def'"); t.is (items[0], "a", "split '-a-bc-def' '-' -> [1] 'a'"); t.is (items[1], "bc", "split '-a-bc-def' '-' -> [2] 'bc'"); t.is (items[2], "def", "split '-a-bc-def' '-' -> [3] 'def'"); // void split (std::vector<std::string>& results, const std::string& input, const std::string& delimiter) unsplit = ""; split (items, unsplit, "--"); t.is (items.size (), (size_t) 0, "split '' '--' -> 0 items"); unsplit = "a"; split (items, unsplit, "--"); t.is (items.size (), (size_t) 1, "split 'a' '--' -> 1 item"); t.is (items[0], "a", "split 'a' '-' -> 'a'"); unsplit = "--"; split (items, unsplit, "--"); t.is (items.size (), (size_t) 2, "split '-' '--' -> '' ''"); t.is (items[0], "", "split '-' '-' -> [0] ''"); t.is (items[1], "", "split '-' '-' -> [1] ''"); unsplit = "--a--bc--def"; split (items, unsplit, "--"); t.is (items.size (), (size_t) 4, "split '-a-bc-def' '--' -> '' 'a' 'bc' 'def'"); t.is (items[0], "", "split '-a-bc-def' '--' -> [0] ''"); t.is (items[1], "a", "split '-a-bc-def' '--' -> [1] 'a'"); t.is (items[2], "bc", "split '-a-bc-def' '--' -> [2] 'bc'"); t.is (items[3], "def", "split '-a-bc-def' '--' -> [3] 'def'"); unsplit = "one\ntwo\nthree"; split (items, unsplit, "\n"); t.is (items.size (), (size_t) 3, "split 'one\\ntwo\\nthree' -> 'one', 'two', 'three'"); t.is (items[0], "one", "split 'one\\ntwo\\nthree' -> [0] 'one'"); t.is (items[1], "two", "split 'one\\ntwo\\nthree' -> [1] 'two'"); t.is (items[2], "three", "split 'one\\ntwo\\nthree' -> [2] 'three'"); // void splitq (std::vector<std::string>&, const std::string&, const char); unsplit = "one 'two' '' 'three four' \"five six seven\" eight'nine ten'"; splitq (items, unsplit, ' '); t.is (items.size () , (size_t) 6, "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten'"); t.is (items[0], "one", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [0] 'one'"); t.is (items[1], "two", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [1] 'two'"); t.is (items[2], "", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [2] ''"); t.is (items[3], "three four", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [3] 'three four'"); t.is (items[4], "five six seven", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [4] 'five six seven'"); t.is (items[5], "eight'nine ten'", "splitq 'one \\'two\\' \\'\\' \\'three four\\' \"five six seven\" eight'nine ten' -> [4] 'eight\\'nine ten\\''"); // void join (std::string& result, const std::string& separator, const std::vector<std::string>& items) std::vector <std::string> unjoined; std::string joined; join (joined, "", unjoined); t.is (joined.length (), (size_t) 0, "join -> length 0"); t.is (joined, "", "join -> ''"); unjoined.push_back (""); unjoined.push_back ("a"); unjoined.push_back ("bc"); unjoined.push_back ("def"); join (joined, "", unjoined); t.is (joined.length (), (size_t) 6, "join '' 'a' 'bc' 'def' -> length 6"); t.is (joined, "abcdef", "join '' 'a' 'bc' 'def' -> 'abcdef'"); join (joined, "-", unjoined); t.is (joined.length (), (size_t) 9, "join '' - 'a' - 'bc' - 'def' -> length 9"); t.is (joined, "-a-bc-def", "join '' - 'a' - 'bc' - 'def' -> '-a-bc-def'"); // void join (std::string& result, const std::string& separator, const std::vector<int>& items) std::vector <int> unjoined2; join (joined, "", unjoined2); t.is (joined.length (), (size_t) 0, "join -> length 0"); t.is (joined, "", "join -> ''"); unjoined2.push_back (0); unjoined2.push_back (1); unjoined2.push_back (2); join (joined, "", unjoined2); t.is (joined.length (), (size_t) 3, "join 0 1 2 -> length 3"); t.is (joined, "012", "join 0 1 2 -> '012'"); join (joined, "-", unjoined2); t.is (joined.length (), (size_t) 5, "join 0 1 2 -> length 5"); t.is (joined, "0-1-2", "join 0 1 2 -> '0-1-2'"); // std::string trimLeft (const std::string& in, const std::string& t /*= " "*/) t.is (trimLeft (""), "", "trimLeft '' -> ''"); t.is (trimLeft (" "), "", "trimLeft ' ' -> ''"); t.is (trimLeft ("", " \t"), "", "trimLeft '' -> ''"); t.is (trimLeft ("xxx"), "xxx", "trimLeft 'xxx' -> 'xxx'"); t.is (trimLeft ("xxx", " \t"), "xxx", "trimLeft 'xxx' -> 'xxx'"); t.is (trimLeft (" \t xxx \t "), "\t xxx \t ", "trimLeft ' \\t xxx \\t ' -> '\\t xxx \\t '"); t.is (trimLeft (" \t xxx \t ", " \t"), "xxx \t ", "trimLeft ' \\t xxx \\t ' -> 'xxx \\t '"); // std::string trimRight (const std::string& in, const std::string& t /*= " "*/) t.is (trimRight (""), "", "trimRight '' -> ''"); t.is (trimRight (" "), "", "trimRight ' ' -> ''"); t.is (trimRight ("", " \t"), "", "trimRight '' -> ''"); t.is (trimRight ("xxx"), "xxx", "trimRight 'xxx' -> 'xxx'"); t.is (trimRight ("xxx", " \t"), "xxx", "trimRight 'xxx' -> 'xxx'"); t.is (trimRight (" \t xxx \t "), " \t xxx \t", "trimRight ' \\t xxx \\t ' -> ' \\t xxx \\t'"); t.is (trimRight (" \t xxx \t ", " \t"), " \t xxx", "trimRight ' \\t xxx \\t ' -> ' \\t xxx'"); // std::string trim (const std::string& in, const std::string& t /*= " "*/) t.is (trim (""), "", "trim '' -> ''"); t.is (trim (" "), "", "trim ' ' -> ''"); t.is (trim ("", " \t"), "", "trim '' -> ''"); t.is (trim ("xxx"), "xxx", "trim 'xxx' -> 'xxx'"); t.is (trim ("xxx", " \t"), "xxx", "trim 'xxx' -> 'xxx'"); t.is (trim (" \t xxx \t "), "\t xxx \t", "trim ' \\t xxx \\t ' -> '\\t xxx \\t'"); t.is (trim (" \t xxx \t ", " \t"), "xxx", "trim ' \\t xxx \\t ' -> 'xxx'"); // std::string unquoteText (const std::string& text) t.is (unquoteText (""), "", "unquoteText '' -> ''"); t.is (unquoteText ("x"), "x", "unquoteText 'x' -> 'x'"); t.is (unquoteText ("'x"), "'x", "unquoteText ''x' -> ''x'"); t.is (unquoteText ("x'"), "x'", "unquoteText 'x'' -> 'x''"); t.is (unquoteText ("\"x"), "\"x", "unquoteText '\"x' -> '\"x'"); t.is (unquoteText ("x\""), "x\"", "unquoteText 'x\"' -> 'x\"'"); t.is (unquoteText ("''"), "", "unquoteText '''' -> ''"); t.is (unquoteText ("'''"), "'", "unquoteText ''''' -> '''"); t.is (unquoteText ("\"\""), "", "unquoteText '\"\"' -> ''"); t.is (unquoteText ("\"\"\""), "\"", "unquoteText '\"\"\"' -> '\"'"); t.is (unquoteText ("''''"), "''", "unquoteText '''''' -> ''''"); t.is (unquoteText ("\"\"\"\""), "\"\"", "unquoteText '\"\"\"\"' -> '\"\"'"); t.is (unquoteText ("'\"\"'"), "\"\"", "unquoteText '''\"\"' -> '\"\"'"); t.is (unquoteText ("\"''\""), "''", "unquoteText '\"''\"' -> ''''"); t.is (unquoteText ("'x'"), "x", "unquoteText ''x'' -> 'x'"); t.is (unquoteText ("\"x\""), "x", "unquoteText '\"x\"' -> 'x'"); // int longestWord (const std::string&) t.is (longestWord (" "), 0, "longestWord ( ) --> 0"); t.is (longestWord ("this is a test"), 4, "longestWord (this is a test) --> 4"); t.is (longestWord ("this is a better test"), 6, "longestWord (this is a better test) --> 6"); t.is (longestWord ("house Çirçös clown"), 6, "longestWord (Çirçös) --> 6"); // int longestLine (const std::string&) t.is (longestLine ("one two three four"), 18, "longestLine (one two three four) --> 18"); t.is (longestLine ("one\ntwo three four"), 14, "longestLine (one\\ntwo three four) --> 14"); t.is (longestLine ("one\ntwo\nthree\nfour"), 5, "longestLine (one\\ntwo\\nthree\\nfour) --> 5"); // std::string commify (const std::string& data) t.is (commify (""), "", "commify '' -> ''"); t.is (commify ("1"), "1", "commify '1' -> '1'"); t.is (commify ("12"), "12", "commify '12' -> '12'"); t.is (commify ("123"), "123", "commify '123' -> '123'"); t.is (commify ("1234"), "1,234", "commify '1234' -> '1,234'"); t.is (commify ("12345"), "12,345", "commify '12345' -> '12,345'"); t.is (commify ("123456"), "123,456", "commify '123456' -> '123,456'"); t.is (commify ("1234567"), "1,234,567", "commify '1234567' -> '1,234,567'"); t.is (commify ("12345678"), "12,345,678", "commify '12345678' -> '12,345,678'"); t.is (commify ("123456789"), "123,456,789", "commify '123456789' -> '123,456,789'"); t.is (commify ("1234567890"), "1,234,567,890", "commify '1234567890' -> '1,234,567,890'"); t.is (commify ("pre"), "pre", "commify 'pre' -> 'pre'"); t.is (commify ("pre1234"), "pre1,234", "commify 'pre1234' -> 'pre1,234'"); t.is (commify ("1234post"), "1,234post", "commify '1234post' -> '1,234post'"); t.is (commify ("pre1234post"), "pre1,234post", "commify 'pre1234post' -> 'pre1,234post'"); // std::string lowerCase (const std::string& input) t.is (lowerCase (""), "", "lowerCase '' -> ''"); t.is (lowerCase ("pre01_:POST"), "pre01_:post", "lowerCase 'pre01_:POST' -> 'pre01_:post'"); // std::string upperCase (const std::string& input) t.is (upperCase (""), "", "upperCase '' -> ''"); t.is (upperCase ("pre01_:POST"), "PRE01_:POST", "upperCase 'pre01_:POST' -> 'PRE01_:POST'"); // bool nontrivial (const std::string&); t.notok (nontrivial (""), "nontrivial '' -> false"); t.notok (nontrivial (" "), "nontrivial ' ' -> false"); t.notok (nontrivial ("\t\t"), "nontrivial '\\t\\t' -> false"); t.notok (nontrivial (" \t \t"), "nontrivial ' \\t \\t' -> false"); t.ok (nontrivial ("a"), "nontrivial 'a' -> true"); t.ok (nontrivial (" a"), "nontrivial ' a' -> true"); t.ok (nontrivial ("a "), "nontrivial 'a ' -> true"); t.ok (nontrivial (" \t\ta"), "nontrivial ' \\t\\ta' -> true"); t.ok (nontrivial ("a\t\t "), "nontrivial 'a\\t\\t ' -> true"); // bool digitsOnly (const std::string&); t.ok (digitsOnly (""), "digitsOnly '' -> true"); t.ok (digitsOnly ("0"), "digitsOnly '0' -> true"); t.ok (digitsOnly ("123"), "digitsOnly '123' -> true"); t.notok (digitsOnly ("12fa"), "digitsOnly '12fa' -> false"); // bool noSpaces (const std::string&); t.ok (noSpaces (""), "noSpaces '' -> true"); t.ok (noSpaces ("a"), "noSpaces 'a' -> true"); t.ok (noSpaces ("abc"), "noSpaces 'abc' -> true"); t.notok (noSpaces (" "), "noSpaces ' ' -> false"); t.notok (noSpaces ("ab cd"), "noSpaces 'ab cd' -> false"); // bool noVerticalSpace (const std::string&); t.ok (noVerticalSpace (""), "noVerticalSpace '' -> true"); t.ok (noVerticalSpace ("a"), "noVerticalSpace 'a' -> true"); t.ok (noVerticalSpace ("abc"), "noVerticalSpace 'abc' -> true"); t.notok (noVerticalSpace ("a\nb"), "noVerticalSpace 'a\\nb' -> false"); t.notok (noVerticalSpace ("a\rb"), "noVerticalSpace 'a\\rb' -> false"); t.notok (noVerticalSpace ("a\fb"), "noVerticalSpace 'a\\fb' -> false"); text = "Hello, world."; // 0123456789012 // s e s e // bool isWordStart (const std::string&, std::string::size_type); t.notok (isWordStart ("", 0), "isWordStart (\"\", 0) -> false"); t.ok (isWordStart ("foo", 0), "isWordStart (\"foo\", 0) -> true"); t.ok (isWordStart (text, 0), "isWordStart (\"Hello, world.\", 0) -> true"); t.notok (isWordStart (text, 1), "isWordStart (\"Hello, world.\", 1) -> false"); t.notok (isWordStart (text, 2), "isWordStart (\"Hello, world.\", 2) -> false"); t.notok (isWordStart (text, 3), "isWordStart (\"Hello, world.\", 3) -> false"); t.notok (isWordStart (text, 4), "isWordStart (\"Hello, world.\", 4) -> false"); t.notok (isWordStart (text, 5), "isWordStart (\"Hello, world.\", 5) -> false"); t.notok (isWordStart (text, 6), "isWordStart (\"Hello, world.\", 6) -> false"); t.ok (isWordStart (text, 7), "isWordStart (\"Hello, world.\", 7) -> true"); t.notok (isWordStart (text, 8), "isWordStart (\"Hello, world.\", 8) -> false"); t.notok (isWordStart (text, 9), "isWordStart (\"Hello, world.\", 9) -> false"); t.notok (isWordStart (text, 10), "isWordStart (\"Hello, world.\", 10) -> false"); t.notok (isWordStart (text, 11), "isWordStart (\"Hello, world.\", 11) -> false"); t.notok (isWordStart (text, 12), "isWordStart (\"Hello, world.\", 12) -> false"); // bool isWordEnd (const std::string&, std::string::size_type); t.notok (isWordEnd ("", 0), "isWordEnd (\"\", 0) -> false"); t.ok (isWordEnd ("foo", 2), "isWordEnd (\"foo\", 2) -> true"); t.notok (isWordEnd (text, 0), "isWordEnd (\"Hello, world.\", 0) -> false"); t.notok (isWordEnd (text, 1), "isWordEnd (\"Hello, world.\", 1) -> false"); t.notok (isWordEnd (text, 2), "isWordEnd (\"Hello, world.\", 2) -> false"); t.notok (isWordEnd (text, 3), "isWordEnd (\"Hello, world.\", 3) -> false"); t.ok (isWordEnd (text, 4), "isWordEnd (\"Hello, world.\", 4) -> true"); t.notok (isWordEnd (text, 5), "isWordEnd (\"Hello, world.\", 5) -> false"); t.notok (isWordEnd (text, 6), "isWordEnd (\"Hello, world.\", 6) -> false"); t.notok (isWordEnd (text, 7), "isWordEnd (\"Hello, world.\", 7) -> false"); t.notok (isWordEnd (text, 8), "isWordEnd (\"Hello, world.\", 8) -> false"); t.notok (isWordEnd (text, 9), "isWordEnd (\"Hello, world.\", 9) -> false"); t.notok (isWordEnd (text, 10), "isWordEnd (\"Hello, world.\", 10) -> false"); t.ok (isWordEnd (text, 11), "isWordEnd (\"Hello, world.\", 11) -> true"); t.notok (isWordEnd (text, 12), "isWordEnd (\"Hello, world.\", 12) -> false"); // bool compare (const std::string&, const std::string&, bool caseless = false); // Make sure degenerate cases are handled. t.ok (compare ("", ""), "'' == ''"); t.notok (compare ("foo", ""), "foo != ''"); t.notok (compare ("", "foo"), "'' != foo"); // Make sure the default is case-sensitive. t.ok (compare ("foo", "foo"), "foo == foo"); t.notok (compare ("foo", "FOO"), "foo != foo"); // Test case-sensitive. t.notok (compare ("foo", "xx", true), "foo != xx"); t.ok (compare ("foo", "foo", true), "foo == foo"); t.notok (compare ("foo", "FOO", true), "foo != FOO"); t.notok (compare ("FOO", "foo", true), "FOO != foo"); t.ok (compare ("FOO", "FOO", true), "FOO == FOO"); // Test case-insensitive. t.notok (compare ("foo", "xx", false), "foo != foo (caseless)"); t.ok (compare ("foo", "foo", false), "foo == foo (caseless)"); t.ok (compare ("foo", "FOO", false), "foo == FOO (caseless)"); t.ok (compare ("FOO", "foo", false), "FOO == foo (caseless)"); t.ok (compare ("FOO", "FOO", false), "FOO == FOO (caseless)"); // std::string::size_type find (const std::string&, const std::string&, bool caseless = false); // Make sure degenerate cases are handled. t.is ((int) find ("foo", ""), (int) 0, "foo !contains ''"); t.is ((int) find ("", "foo"), (int) std::string::npos, "'' !contains foo"); // Make sure the default is case-sensitive. t.is ((int) find ("foo", "fo"), 0, "foo contains fo"); t.is ((int) find ("foo", "FO"), (int) std::string::npos, "foo !contains fo"); // Test case-sensitive. t.is ((int) find ("foo", "xx", true), (int) std::string::npos, "foo !contains xx"); t.is ((int) find ("foo", "oo", true), 1, "foo contains oo"); t.is ((int) find ("foo", "fo", true), 0, "foo contains fo"); t.is ((int) find ("foo", "FO", true), (int) std::string::npos, "foo !contains fo"); t.is ((int) find ("FOO", "fo", true), (int) std::string::npos, "foo !contains fo"); t.is ((int) find ("FOO", "FO", true), 0, "foo contains fo"); // Test case-insensitive. t.is ((int) find ("foo", "xx", false), (int) std::string::npos, "foo !contains xx (caseless)"); t.is ((int) find ("foo", "oo", false), 1, "foo contains oo (caseless)"); t.is ((int) find ("foo", "fo", false), 0, "foo contains fo (caseless)"); t.is ((int) find ("foo", "FO", false), 0, "foo contains FO (caseless)"); t.is ((int) find ("FOO", "fo", false), 0, "FOO contains fo (caseless)"); t.is ((int) find ("FOO", "FO", false), 0, "FOO contains FO (caseless)"); // Test start offset. t.is ((int) find ("one two three", "e", 3, true), (int) 11, "offset obeyed"); t.is ((int) find ("one two three", "e", 11, true), (int) 11, "offset obeyed"); // int strippedLength (const std::string&); t.is (strippedLength (std::string ("")), 0, "strippedLength -> 0"); t.is (strippedLength (std::string ("abc")), 3, "strippedLength abc -> 3"); t.is (strippedLength (std::string ("one\033[5;38;255mtwo\033[0mthree")), 11, "strippedLength one^[[5;38;255mtwo^[[0mthree -> 11"); t.is (strippedLength (std::string ("\033[0m")), 0, "strippedLength ^[[0m -> 0"); t.is (strippedLength (std::string ("\033[1m\033[0m")), 0, "strippedLength ^[[1m^[[0m -> 0"); // std::string format (char); t.is (format ('A'), "A", "format ('A') -> A"); // std::string format (int); t.is (format (0), "0", "format (0) -> 0"); t.is (format (-1), "-1", "format (-1) -> -1"); // std::string formatHex (int); t.is (formatHex (0), "0", "formatHex (0) -> 0"); t.is (formatHex (10), "a", "formatHex (10) -> a"); t.is (formatHex (123), "7b", "formatHex (123) -> 7b"); // std::string format (float, int, int); t.is (format (1.23456789, 8, 1), " 1", "format (1.23456789, 8, 1) -> _______1"); t.is (format (1.23456789, 8, 2), " 1.2", "format (1.23456789, 8, 2) -> _____1.2"); t.is (format (1.23456789, 8, 3), " 1.23", "format (1.23456789, 8, 3) -> ____1.23"); t.is (format (1.23456789, 8, 4), " 1.235", "format (1.23456789, 8, 4) -> ___1.235"); t.is (format (1.23456789, 8, 5), " 1.2346", "format (1.23456789, 8, 5) -> __1.2346"); t.is (format (1.23456789, 8, 6), " 1.23457", "format (1.23456789, 8, 6) -> 1.23457"); t.is (format (1.23456789, 8, 7), "1.234568", "format (1.23456789, 8, 7) -> 1.234568"); t.is (format (1.23456789, 8, 8), "1.2345679", "format (1.23456789, 8, 8) -> 1.2345679"); t.is (format (2444238.56789, 12, 11), "2444238.5679", "format (2444238.56789, 12, 11) -> 2444238.5679"); // std::string format (double, int, int); // std::string leftJustify (const std::string&, const int); t.is (leftJustify (123, 3), "123", "leftJustify 123,3 -> '123'"); t.is (leftJustify (123, 4), "123 ", "leftJustify 123,4 -> '123 '"); t.is (leftJustify (123, 5), "123 ", "leftJustify 123,5 -> '123 '"); // std::string leftJustify (const std::string&, const int); t.is (leftJustify ("foo", 3), "foo", "leftJustify foo,3 -> 'foo'"); t.is (leftJustify ("foo", 4), "foo ", "leftJustify foo,4 -> 'foo '"); t.is (leftJustify ("foo", 5), "foo ", "leftJustify foo,5 -> 'foo '"); t.is (leftJustify ("föo", 5), "föo ", "leftJustify föo,5 -> 'föo '"); // std::string rightJustify (const std::string&, const int); t.is (rightJustify (123, 3), "123", "rightJustify 123,3 -> '123'"); t.is (rightJustify (123, 4), " 123", "rightJustify 123,4 -> ' 123'"); t.is (rightJustify (123, 5), " 123", "rightJustify 123,5 -> ' 123'"); // std::string rightJustify (const std::string&, const int); t.is (rightJustify ("foo", 3), "foo", "rightJustify foo,3 -> 'foo'"); t.is (rightJustify ("foo", 4), " foo", "rightJustify foo,4 -> ' foo'"); t.is (rightJustify ("foo", 5), " foo", "rightJustify foo,5 -> ' foo'"); t.is (rightJustify ("föo", 5), " föo", "rightJustify föo,5 -> ' föo'"); // int utf8_length (const std::string&); t.is ((int) utf8_length ("Çirçös"), 6, "utf8_length (Çirçös) == 6"); t.is ((int) utf8_length ("ツネナラム"), 5, "utf8_length (ツネナラム) == 5"); t.is ((int) utf8_length ("Zwölf Boxkämpfer"), 16, "utf8_length (Zwölf Boxkämpfer) == 16"); return 0; }