void test_helpers_detail::check_equal(const char* expected[], const string_vector& actual) { const char** expected_iter = expected; string_vector::const_iterator actual_iter = actual.begin(); bool equals = true; while (equals && *expected_iter != NULL && actual_iter != actual.end()) { if (*expected_iter != *actual_iter) { equals = false; } else { expected_iter++; actual_iter++; } } if (equals && ((*expected_iter == NULL && actual_iter != actual.end()) || (*expected_iter != NULL && actual_iter == actual.end()))) equals = false; if (!equals) { std::cerr << "EXPECTED:\n"; for (expected_iter = expected; *expected_iter != NULL; expected_iter++) std::cerr << *expected_iter << "\n"; std::cerr << "ACTUAL:\n"; for (actual_iter = actual.begin(); actual_iter != actual.end(); actual_iter++) std::cerr << *actual_iter << "\n"; ATF_FAIL("Expected results differ to actual values"); } }
// returns true if symbol is ok bool filter(const string_vector& nonsyms, const std::string& symbol) { if(symbol.empty()) return false; // Filter out all prohibited words string_vector::const_iterator r = find(nonsyms.begin(), nonsyms.end(), symbol); if(r != nonsyms.end()) return false; // Filter out all numbers groups started with number if(isdigit(symbol[0])) return false; return true; }
inline void write_file( const boost::filesystem::path& path, const string_vector& lines ) { std::ofstream ostr(path.string()); std::copy( lines.begin(), lines.end(), std::ostream_iterator<std::string>(ostr, "\n") ); }
string print_layouts(const string_vector& sv) { ostringstream oss; bool fst = true; oss << "["; for(string_vector::const_iterator i=sv.begin(); i!=sv.end(); i++) { if(!fst) oss << " "; oss << *i; fst = false; } oss << "]"; return oss.str(); }
//功能:在源字符串中查找指定的多个字符串,如果找到任意一个就返回true,一个都没找到返回false //参数: // sSrc: string & 类型,源字符串 // vecSub: const string_vector &类型,查找的多个字符串 //返回值:bool类型,找到任意一个就返回true,一个都没找到返回false bool CXxwCppPub::FindSubStr(string& sSrc, const string_vector &vecSub) { bool bFind = false; if (sSrc.empty() || vecSub.empty()) { return bFind; } typedef string_vector::const_iterator ItSub;//常迭代器,不会修改容器 for (ItSub it = vecSub.begin(); it != vecSub.end(); ++it) { string sSub = *it; if (sSrc.find(sSub) != string::npos) { return true;//找到了一个字符串,返回true } } return bFind; }