void test_int_range () { int inputs [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 99, 999, -1, -3, -99, 234234 }; int outputs [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, -1, -1, -1, 10 }; std::vector<int> results; std::vector<int> in_v; std::copy ( a_begin(inputs), a_end(inputs), std::back_inserter ( in_v )); ba::clamp_range ( a_begin(inputs), a_end(inputs), std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v.begin (), in_v.end (), std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( a_begin(inputs), a_end(inputs), std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v.begin (), in_v.end (), std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( a_range(inputs), std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v, std::back_inserter ( results ), -1, 10 ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( a_range(inputs), std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); ba::clamp_range ( in_v, std::back_inserter ( results ), 10, -1, intGreater ); BOOST_CHECK ( std::equal ( results.begin(), results.end (), outputs )); results.clear (); int junk[elementsof(inputs)]; ba::clamp_range ( inputs, junk, 10, -1, intGreater ); BOOST_CHECK ( std::equal ( b_e(junk), outputs )); }
int compare_filenames(const std::string& a, const std::string& b) { utf8_const_iterator a_begin(a.begin()), a_end(a.end()); utf8_const_iterator b_begin(b.begin()), b_end(b.end()); utf8_const_iterator a_it(a_begin); utf8_const_iterator b_it(b_begin); for (; a_it != a_end && b_it != b_end; ) { int a_chr = *a_it; int b_chr = *b_it; if ((a_chr >= '0') && (a_chr <= '9') && (b_chr >= '0') && (b_chr <= '9')) { utf8_const_iterator a_it2 = a_it; utf8_const_iterator b_it2 = b_it; while (a_it2 != a_end && (*a_it2 >= '0') && (*a_it2 <= '9')) ++a_it2; while (b_it2 != b_end && (*b_it2 >= '0') && (*b_it2 <= '9')) ++b_it2; int a_num = std::strtol(std::string(a_it, a_it2).c_str(), NULL, 10); int b_num = std::strtol(std::string(b_it, b_it2).c_str(), NULL, 10); if (a_num != b_num) return a_num - b_num < 0 ? -1: 1; a_it = a_it2; b_it = b_it2; } else if (is_path_separator(a_chr) && is_path_separator(b_chr)) { ++a_it; ++b_it; } else { a_chr = std::tolower(a_chr); b_chr = std::tolower(b_chr); if (a_chr != b_chr) return a_chr - b_chr < 0 ? -1: 1; ++a_it; ++b_it; } } if (a_it == a_end && b_it == b_end) return 0; else if (a_it == a_end) return -1; else return 1; }
char * ovOverlap::toString(char *str, ovOverlapDisplayType type, bool newLine) { switch (type) { case ovOverlapAsHangs: sprintf(str, "%10"F_U32P" %10"F_U32P" %c %6"F_S32P" %6"F_U32P" %6"F_S32P" %7.6f%s%s", a_iid, b_iid, flipped() ? 'I' : 'N', a_hang(), span(), b_hang(), erate(), (overlapIsDovetail()) ? "" : " PARTIAL", (newLine) ? "\n" : ""); break; case ovOverlapAsCoords: sprintf(str, "%10"F_U32P" %10"F_U32P" %c %6"F_U32P" %6"F_U32P" %6"F_U32P" %6"F_U32P" %6"F_U32P" %7.6f%s", a_iid, b_iid, flipped() ? 'I' : 'N', span(), a_bgn(), a_end(), b_bgn(), b_end(), erate(), (newLine) ? "\n" : ""); break; case ovOverlapAsRaw: sprintf(str, "%10"F_U32P" %10"F_U32P" %c %6"F_U32P" %6"F_U64P" %6"F_U64P" %6"F_U64P" %6"F_U64P" %7.6f %s %s %s%s", a_iid, b_iid, flipped() ? 'I' : 'N', span(), dat.ovl.ahg5, dat.ovl.ahg3, dat.ovl.bhg5, dat.ovl.bhg3, erate(), dat.ovl.forOBT ? "OBT" : " ", dat.ovl.forDUP ? "DUP" : " ", dat.ovl.forUTG ? "UTG" : " ", (newLine) ? "\n" : ""); break; case ovOverlapAsCompat: sprintf(str, "%8"F_U32P" %8"F_U32P" %c %6d %6d %5.2f %5.2f%s", a_iid, b_iid, dat.ovl.flipped ? 'I' : 'N', a_hang(), b_hang(), erate() * 100.0, erate() * 100.0, (newLine) ? "\n" : ""); break; case ovOverlapAsPaf: // miniasm/map expects entries to be separated by tabs // no padding spaces on names we don't confuse read identifiers sprintf(str, "%"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%c\t%"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P" %s", a_iid, (g->gkStore_getRead(a_iid)->gkRead_sequenceLength()), a_bgn(), a_end(), flipped() ? '-' : '+', b_iid, (g->gkStore_getRead(b_iid)->gkRead_sequenceLength()), flipped() ? b_end() : b_bgn(), flipped() ? b_bgn() : b_end(), (uint32)floor(span() == 0 ? (1-erate() * (a_end()-a_bgn())) : (1-erate()) * span()), span() == 0 ? a_end() - a_bgn() : span(), 255, (newLine) ? "\n" : ""); break; } return(str); }
void link_check::inspect( const string & library_name, const path & full_path, // example: c:/foo/boost/filesystem/path.hpp const string & contents ) // contents of file to be inspected { if (contents.find( "boostinspect:" "nounlinked" ) != string::npos) m_paths[ relative_to( full_path, search_root_path() ) ] |= m_nounlinked_errors; bool no_link_errors = (contents.find( "boostinspect:" "nolink" ) != string::npos); // build bookmarks databases bookmarks.clear(); bookmarks_lowercase.clear(); string::const_iterator a_start( contents.begin() ); string::const_iterator a_end( contents.end() ); boost::match_results< string::const_iterator > a_what; boost::match_flag_type a_flags = boost::match_default; if(!is_css(full_path)) { string previous_id; while( boost::regex_search( a_start, a_end, a_what, html_bookmark_regex, a_flags) ) { // a_what[0] contains the whole string iterators. // a_what[1] contains the tag iterators. // a_what[2] contains the attribute name. // a_what[4] contains the bookmark iterators. if (a_what[4].matched) { string tag( a_what[1].first, a_what[1].second ); boost::algorithm::to_lower(tag); string attribute( a_what[2].first, a_what[2].second ); boost::algorithm::to_lower(attribute); string bookmark( a_what[4].first, a_what[4].second ); bool name_following_id = ( attribute == "name" && previous_id == bookmark ); if ( tag != "meta" && attribute == "id" ) previous_id = bookmark; else previous_id.clear(); if ( tag != "meta" && !name_following_id ) { bookmarks.insert( bookmark ); // std::cout << "******************* " << bookmark << '\n'; // w3.org recommends case-insensitive checking for duplicate bookmarks // since some browsers do a case-insensitive match. string bookmark_lowercase( bookmark ); boost::algorithm::to_lower(bookmark_lowercase); std::pair<bookmark_set::iterator, bool> result = bookmarks_lowercase.insert( bookmark_lowercase ); if (!result.second) { ++m_duplicate_bookmark_errors; int ln = std::count( contents.begin(), a_what[3].first, '\n' ) + 1; error( library_name, full_path, "Duplicate bookmark: " + bookmark, ln ); } } } a_start = a_what[0].second; // update search position a_flags |= boost::match_prev_avail; // update flags a_flags |= boost::match_not_bob; } } // process urls string::const_iterator start( contents.begin() ); string::const_iterator end( contents.end() ); boost::match_results< string::const_iterator > what; boost::match_flag_type flags = boost::match_default; if(!is_css(full_path)) { while( boost::regex_search( start, end, what, html_url_regex, flags) ) { // what[0] contains the whole string iterators. // what[1] contains the element type iterators. // what[3] contains the URL iterators. if(what[3].matched) { string type( what[1].first, what[1].second ); boost::algorithm::to_lower(type); // TODO: Complain if 'link' tags use external stylesheets. do_url( string( what[3].first, what[3].second ), library_name, full_path, no_link_errors, type == "a" || type == "link", contents.begin(), what[3].first ); } start = what[0].second; // update search position flags |= boost::match_prev_avail; // update flags flags |= boost::match_not_bob; } } while( boost::regex_search( start, end, what, css_url_regex, flags) ) { // what[0] contains the whole string iterators. // what[2] contains the URL iterators. if(what[2].matched) { do_url( string( what[2].first, what[2].second ), library_name, full_path, no_link_errors, false, contents.begin(), what[3].first ); } start = what[0].second; // update search position flags |= boost::match_prev_avail; // update flags flags |= boost::match_not_bob; } }