void StringTest::testTrim() { { std::string s = "abc"; assert (trim(s) == "abc"); } { std::string s = "abc "; assert (trim(s) == "abc"); } { std::string s = " ab c "; assert (trim(s) == "ab c"); } }
// create a directory if it doesnt exist yet. bool createDirectory(string dir, bool relativeToDataDir, bool createSubDirectories) { try { trim(dir); if(relativeToDataDir) { dir = getDataPath() +dir; } Poco::File f(dir); try { if(f.isDirectory()) { // throws! return true; } } catch(...) { if(createSubDirectories) { f.createDirectories(); } else { f.createDirectory(); } } } catch(Poco::FileException& ex) { printf("Cannot create directory: '%s' reason:'%s'\n" ,dir.c_str() ,ex.displayText().c_str() ); return false; } return true; }
bool IPAddress::tryParse(const std::string& addr, IPAddress& result) { IPv4AddressImpl impl4(IPv4AddressImpl::parse(addr)); if (impl4 != IPv4AddressImpl() || trim(addr) == "0.0.0.0") { result.newIPv4(impl4.addr()); return true; } #if defined(POCO_HAVE_IPv6) IPv6AddressImpl impl6(IPv6AddressImpl::parse(addr)); if (impl6 != IPv6AddressImpl()) { result.newIPv6(impl6.addr(), impl6.scope()); return true; } #endif return false; }
int main(int argc, char** argv) { string hello(" Hello, world! "); cout << hello << "\n"; string s1(trimLeft(hello)); // "Hello, world! " cout << s1 << "\n"; trimRightInPlace(s1); // "Hello, world!" cout << s1 << "\n"; string s2(trim(hello)); // "Hello, world!" cout << s2 << "\n"; return 0; }