int main(int argc, char** argv) { if (argc < 3) return usage(); if (strlen(argv[1]) != 3) return usage(); std::string conv(argv[1]); FileInputStream fis(argv[2]); std::stringstream ss; StreamCopier::copyStream(fis, ss); fis.close(); FileOutputStream fos(argv[2]); if (0 == icompare(conv, "u2d")) unixToDos(ss, fos); else if (0 == icompare(conv, "d2u")) dosToUnix(ss, fos); else return usage(); fos.flush(); return 0; }
//-------------------------------------------------------------- int testApp::isCommonWord(string _testString, vector<string> _ignoreWords){ //returns 0 if common word is found from a given vector or list of words to Ignore, returns 1 or -1 if no word can be found vector<string>::iterator g; int isCommon; for(int i =0; i<_ignoreWords.size(); i++){ isCommon = icompare(_testString, _ignoreWords[i]); if(isCommon == 0) break; } return isCommon; }
const BaosIpEnumerator::Device& BaosIpEnumerator::findByAddress(const std::string& ipAddress) const { for (const auto& device : devices_) { if (!icompare(getAddress(device), ipAddress)) { return device; } } throw ClientException("Device Not Found"); }
const BaosIpEnumerator::Device& BaosIpEnumerator::find(const std::string& name) const { for (const auto& device : devices_) { if (!icompare(getName(device), name)) { return device; } } throw ClientException("Device Not Found"); }
//_________________________ nameStruct testApp::createNameStructs(string token, vector<string> &_baseText, int flagPosition){ //function should return nameStruct with a point, properName and appearances for sizing this can be called to create vector of structs int appearances =1; int sumOfLocations =0; ofPoint aPoint; for(int j = 0; j< _baseText.size(); j++){ int foundToken = icompare(token, _baseText[j]); if(foundToken == 0){ appearances ++; sumOfLocations +=j; } } aPoint.y = (float) sumOfLocations/appearances; if(flagPosition ==0) aPoint.x = 0.30*(float) ofGetWidth(); if(flagPosition ==1) aPoint.x = .70*(float) ofGetWidth(); nameStruct _theName = nameStruct(aPoint, token, appearances); return _theName; }
void StringTest::testIcompare() { std::string s1 = "AAA"; std::string s2 = "aaa"; std::string s3 = "bbb"; std::string s4 = "cCcCc"; std::string s5; assert (icompare(s1, s2) == 0); assert (icompare(s1, s3) < 0); assert (icompare(s1, s4) < 0); assert (icompare(s3, s1) > 0); assert (icompare(s4, s2) > 0); assert (icompare(s2, s4) < 0); assert (icompare(s1, s5) > 0); assert (icompare(s5, s4) < 0); std::string ss1 = "xxAAAzz"; std::string ss2 = "YaaaX"; std::string ss3 = "YbbbX"; assert (icompare(ss1, 2, 3, ss2, 1, 3) == 0); assert (icompare(ss1, 2, 3, ss3, 1, 3) < 0); assert (icompare(ss1, 2, 3, ss2, 1) == 0); assert (icompare(ss1, 2, 3, ss3, 1) < 0); assert (icompare(ss1, 2, 2, ss2, 1, 3) < 0); assert (icompare(ss1, 2, 2, ss2, 1, 2) == 0); assert (icompare(ss3, 1, 3, ss1, 2, 3) > 0); assert (icompare(s1, s2.c_str()) == 0); assert (icompare(s1, s3.c_str()) < 0); assert (icompare(s1, s4.c_str()) < 0); assert (icompare(s3, s1.c_str()) > 0); assert (icompare(s4, s2.c_str()) > 0); assert (icompare(s2, s4.c_str()) < 0); assert (icompare(s1, s5.c_str()) > 0); assert (icompare(s5, s4.c_str()) < 0); assert (icompare(ss1, 2, 3, "aaa") == 0); assert (icompare(ss1, 2, 2, "aaa") < 0); assert (icompare(ss1, 2, 3, "AAA") == 0); assert (icompare(ss1, 2, 2, "bb") < 0); assert (icompare(ss1, 2, "aaa") > 0); }
void MailMessageTest::testReadWriteMultiPartStore() { std::string msgin( "Content-Type: multipart/mixed; boundary=MIME_boundary_31E8A8D61DF53389\r\n" "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" "From: [email protected]\r\n" "Mime-Version: 1.0\r\n" "Subject: Test Message\r\n" "To: John Doe <*****@*****.**>\r\n" "\r\n" "--MIME_boundary_31E8A8D61DF53389\r\n" "Content-Disposition: inline\r\n" "Content-Transfer-Encoding: 8bit\r\n" "Content-Type: text/plain\r\n" "\r\n" "Hello World!\r\n" "\r\n" "--MIME_boundary_31E8A8D61DF53389\r\n" "Content-Disposition: attachment; filename=sample.dat\r\n" "Content-ID: abcd1234\r\n" "Content-Transfer-Encoding: base64\r\n" "Content-Type: application/octet-stream; name=sample\r\n" "\r\n" "VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n" "--MIME_boundary_31E8A8D61DF53389--\r\n" ); std::istringstream istr(msgin); std::ostringstream ostr; FilePartStoreFactory pfsf; MailMessage message(&pfsf); message.read(istr); MailMessage::PartVec::const_iterator it = message.parts().begin(); MailMessage::PartVec::const_iterator end = message.parts().end(); for (; it != end; ++it) { FilePartStore* fps = dynamic_cast<FilePartStore*>(it->pSource); if (fps && fps->filename().size()) { std::string filename = fps->filename(); assert (filename == "sample.dat"); std::string path = fps->path(); // for security reasons, the filesystem temporary // filename is not the same as attachment name std::size_t sz = (path.size() > filename.size()) ? filename.size() : path.size(); assert (0 != icompare(path, path.size() - sz, sz, path)); Poco::FileInputStream fis(path); assert (fis.good()); std::string read; std::string line; while (std::getline(fis, line)) read += line; assert (!read.empty()); assert (read == "This is some binary data. Really."); } } message.write(ostr); std::string msgout(ostr.str()); assert (msgout == msgin); }