本文整理汇总了C++中stringT::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ stringT::empty方法的具体用法?C++ stringT::empty怎么用?C++ stringT::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringT
的用法示例。
在下文中一共展示了stringT::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RemoveHostnameUsername
bool CXMLprefs::RemoveHostnameUsername(const stringT &sHost, const stringT &sUser,
bool &bNoMoreNodes)
{
// If all OK, after removal of supplied hostname/username, then
// bNoMoreNodes indicates if there still remain more nodes (hostname/username)
// in the configuration file
bNoMoreNodes = false;
// Validate parameters
if (sHost.empty() || sUser.empty())
return false;
if (m_pXMLDoc == NULL)
return false;
stringT sPath = stringT(_T("Pwsafe_Settings//")) + sHost;
pugi::xml_node node = m_pXMLDoc->first_element_by_path(sPath.c_str(), _T('\\'));
if (node == NULL)
return false;
if (!node.remove_child(sUser.c_str()))
return false;
// Check if more children
bNoMoreNodes = node.first_child() == NULL;
return true;
}
示例2: ImportFilterXMLFile
int PWSFilters::ImportFilterXMLFile(const FilterPool fpool,
const StringX &strXMLData,
const stringT &strXMLFileName,
const stringT &strXSDFileName,
stringT &strErrors,
Asker *pAsker)
{
#if USE_XML_LIBRARY == MSXML
MFilterXMLProcessor fXML(*this, fpool, pAsker);
#elif USE_XML_LIBRARY == XERCES
XFilterXMLProcessor fXML(*this, fpool, pAsker);
#endif
bool status, validation;
strErrors = _T("");
validation = true;
if (strXMLFileName.empty())
status = fXML.Process(validation, strXMLData, _T(""), strXSDFileName);
else
status = fXML.Process(validation, _T(""), strXMLFileName, strXSDFileName);
strErrors = fXML.getXMLErrors();
if (!status) {
return PWScore::XML_FAILED_VALIDATION;
}
validation = false;
if (strXMLFileName.empty())
status = fXML.Process(validation, strXMLData, _T(""), strXSDFileName);
else
status = fXML.Process(validation, _T(""), strXMLFileName, strXSDFileName);
strErrors = fXML.getXMLErrors();
if (!status) {
return PWScore::XML_FAILED_IMPORT;
}
// By definition - all imported filters are complete!
// Now set this.
PWSFilters::iterator mf_iter;
for (mf_iter = this->begin(); mf_iter != this->end(); mf_iter++) {
st_filters &filters = mf_iter->second;
for_each(filters.vMfldata.begin(), filters.vMfldata.end(),
mem_fun_ref(&st_FilterRow::SetFilterComplete));
for_each(filters.vHfldata.begin(), filters.vHfldata.end(),
mem_fun_ref(&st_FilterRow::SetFilterComplete));
for_each(filters.vPfldata.begin(), filters.vPfldata.end(),
mem_fun_ref(&st_FilterRow::SetFilterComplete));
for_each(filters.vAfldata.begin(), filters.vAfldata.end(),
mem_fun_ref(&st_FilterRow::SetFilterComplete));
}
return PWScore::SUCCESS;
}
示例3: makepath
stringT pws_os::makepath(const stringT &drive, const stringT &dir,
const stringT &file, const stringT &ext)
{
stringT retval(drive);
retval += dir;
if (!dir.empty() && retval[retval.length()-1] != '/')
retval += _T("/");
retval += file;
if (!ext.empty()) {
retval += _T(".");
retval += ext;
}
return retval;
}
示例4: MigrateSettings
bool CXMLprefs::MigrateSettings(const stringT &sNewFilename,
const stringT &sHost, const stringT &sUser)
{
// Validate parameters
if (sNewFilename.empty() || sHost.empty() || sUser.empty())
return false;
if (m_pXMLDoc == NULL)
return false;
pugi::xml_node root_node = m_pXMLDoc->first_element_by_path(_T("Pwsafe_Settings"), _T('\\'));
if (root_node == NULL)
return false;
// Delete all hosts - except the one supplied
for (pugi::xml_node host = root_node.first_child(); host;
host = root_node.next_sibling()) {
if (host.name() != sHost.c_str()) {
root_node.remove_child(host);
} else {
// Same host - now delete all other users on that host
for (pugi::xml_node user = host.first_child(); user;
user = host.next_sibling()) {
if (user.name() != sUser.c_str()) {
host.remove_child(user);
}
}
}
}
// Save just host/user in new file
pugi::xml_node decl = m_pXMLDoc->prepend_child(pugi::node_declaration);
if (decl == NULL)
return false;
decl.append_attribute(_T("version")) = _T("1.0");
decl.append_attribute(_T("encoding")) = _T("utf-8");
decl.append_attribute(_T("standalone")) = _T("yes");
bool result = m_pXMLDoc->save_file(sNewFilename.c_str(), _T(" "),
pugi::format_default | pugi::format_write_bom,
pugi::encoding_utf8);
if (!result) {
return false;
}
return true;
}
示例5: DeleteSetting
// Delete a key or chain of keys
bool CXMLprefs::DeleteSetting(const stringT &csBaseKeyName, const stringT &csValueName)
{
// m_pXMLDoc may be NULL if Load() not called before DeleteSetting,
// or if called & failed
if (m_pXMLDoc == NULL && !CreateXML(false))
return false;
bool bRetVal = false;
stringT csKeyName(csBaseKeyName);
if (!csValueName.empty()) {
csKeyName += _T("\\");
csKeyName += csValueName;
}
pugi::xml_node base_node = m_pXMLDoc->first_element_by_path(csKeyName.c_str(), _T('\\'));
if (base_node == NULL)
return false;
pugi::xml_node node_parent = base_node.parent();
if (node_parent != NULL) {
size_t last_slash = csKeyName.find_last_of(_T("\\"));
stringT sKey = csKeyName.substr(last_slash + 1);
bRetVal = node_parent.remove_child(sKey.c_str());
}
return bRetVal;
}
示例6: GetLockFileName
static stringT GetLockFileName(const stringT &filename)
{
ASSERT(!filename.empty());
// derive lock filename from filename
stringT retval(filename, 0, filename.find_last_of(TCHAR('.')));
retval += _T(".plk");
return retval;
}
示例7: chdir
bool pws_os::chdir(const stringT &dir)
{
assert(!dir.empty());
const char *szdir = NULL;
size_t N = std::wcstombs(NULL, dir.c_str(), 0) + 1;
assert(N > 0);
szdir = new char[N];
std::wcstombs(const_cast<char *>(szdir), dir.c_str(), N);
bool retval = (::chdir(szdir) == 0);
delete[] szdir;
return retval;
}
示例8: makepath
stringT pws_os::makepath(const stringT &drive, const stringT &dir,
const stringT &file, const stringT &ext)
{
stringT retval;
/**
* drive and dir can semantically be "./" with no ill effect,
* but wxFileDialog doesn't like a "filename" with "/"s.
*/
if (drive != L"./")
retval = drive;
if (dir != L"./") {
retval += dir;
if (!dir.empty() && retval[retval.length()-1] != '/')
retval += _T("/");
}
retval += file;
if (!ext.empty()) {
retval += _T(".");
retval += ext;
}
return retval;
}
示例9: splitpath
bool pws_os::splitpath(const stringT &path,
stringT &drive, stringT &dir,
stringT &file, stringT &ext)
{
if (path.empty())
return false;
stringT::size_type last_slash = path.find_last_of(_T("/"));
dir = path.substr(0, last_slash + 1);
if (dir.empty())
dir = _T("./");
drive = (dir[0] == '/') ? _T("/") : _T("./");
stringT::size_type last_dot = path.find_last_of(_T("."));
if (last_dot != stringT::npos && last_dot > last_slash) {
file = path.substr(last_slash + 1, last_dot - last_slash - 1);
ext = path.substr(last_dot + 1);
} else {
file = path.substr(last_slash + 1);
ext = _T("");
}
return true;
}
示例10: tomb
std::string pws_os::tomb(const stringT& val)
{
if (!val.empty()) {
const size_t N = std::wcstombs(NULL, val.c_str(), 0);
assert(N > 0);
char* szstr = new char[N+1];
szstr[N] = 0;
std::wcstombs(szstr, val.c_str(), N);
std::string retval(szstr);
delete[] szstr;
return retval;
} else
return string();
}
示例11: AddDrive
void pws_os::AddDrive(stringT &path)
{
// Adds a drive letter to the path if not there, unless
// empty string or it's a UNC path (\\host\sharename...)
using namespace pws_os;
if (path.empty())
return;
if (!(path[0] == '\\' && path[1] == '\\')) {
stringT drive, dir, file, ext;
splitpath(path, drive, dir, file, ext);
if (drive.empty()) {
const stringT exedir = getexecdir();
stringT exeDrive, dummy;
splitpath(exedir, exeDrive, dummy, dummy, dummy);
path = makepath(exeDrive, dir, file, ext);
}
}
}
示例12: chdir
bool pws_os::chdir(const stringT &dir)
{
ASSERT(!dir.empty());
return (_tchdir(dir.c_str()) == 0);
}
示例13: Process
bool XFilterXMLProcessor::Process(const bool &bvalidation,
const StringX &strXMLData,
const stringT &strXMLFileName,
const stringT &strXSDFileName)
{
USES_XMLCH_STR
bool bErrorOccurred = false;
stringT cs_validation;
LoadAString(cs_validation, IDSC_XMLVALIDATION);
stringT cs_import;
LoadAString(cs_import, IDSC_XMLIMPORT);
stringT strResultText(_T(""));
m_bValidation = bvalidation; // Validate or Import
XSecMemMgr sec_mm;
// Initialize the XML4C2 system
try
{
XMLPlatformUtils::Initialize(XMLUni::fgXercescDefaultLocale, 0, 0, &sec_mm);
}
catch (const XMLException& toCatch)
{
m_strXMLErrors = stringT(_X2ST(toCatch.getMessage()));
return false;
}
// Create a SAX2 parser object.
SAX2XMLReader* pSAX2Parser = XMLReaderFactory::createXMLReader(&sec_mm);
// Set non-default features
pSAX2Parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
pSAX2Parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
pSAX2Parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
pSAX2Parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false);
pSAX2Parser->setFeature(XMLUni::fgXercesSkipDTDValidation, true);
// Set properties
// we need const_cast here, because _W2X return const wchar_t* when
// WCHAR_INCOMPATIBLE_XMLCH isn't set
pSAX2Parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
const_cast<XMLCh*>(_W2X(strXSDFileName.c_str())));
pSAX2Parser->setProperty(XMLUni::fgXercesScannerName,
const_cast<XMLCh*>(XMLUni::fgSGXMLScanner));
pSAX2Parser->setInputBufferSize(4096);
// Create SAX handler object and install it on the pSAX2Parser, as the
// document and error pSAX2Handler.
XFilterSAX2Handlers * pSAX2Handler = new XFilterSAX2Handlers;
pSAX2Parser->setContentHandler(pSAX2Handler);
pSAX2Parser->setErrorHandler(pSAX2Handler);
// Workaround/bypass until Xerces supports retrieving version from the
// <xs:schema ...> statement!
// Set 'dummy' schema version to arbitrary value > 1
pSAX2Handler->SetSchemaVersion(99);
pSAX2Handler->SetVariables(m_pAsker, &m_MapFilters, m_FPool, m_bValidation);
// instantiate converter out of if/else to be sure that string will be valid
// till the end of pSAX2Parser, that may capture pointer to string from MemBufInputSource
CUTF8Conv conv;
try
{
// Let's begin the parsing now
if (!strXMLFileName.empty()) {
pSAX2Parser->parse(_W2X(strXMLFileName.c_str()));
} else {
const char *szID = "database_filters";
// Xerces use encoding from XML (we have set it to utf-8), but transcode() on Windows convert to one-byte cpXXXX,
// so we need to manually convert from wchar to UTF-8
const unsigned char* buffer=nullptr;
size_t len;
if (!conv.ToUTF8(strXMLData, buffer, len)) {
throw std::runtime_error("Can't convert data to UTF-8");
}
//2nd parameter must be number of bytes, so we use a length for char* representation
MemBufInputSource* memBufIS = new MemBufInputSource(
reinterpret_cast<const XMLByte *>(buffer),
strlen(reinterpret_cast<const char*>(buffer)),
szID, false);
pSAX2Parser->parse(*memBufIS);
delete memBufIS;
}
}
catch (const OutOfMemoryException&)
{
LoadAString(strResultText, IDCS_XERCESOUTOFMEMORY);
bErrorOccurred = true;
}
catch (const XMLException& e)
{
strResultText = stringT(_X2ST(e.getMessage()));
bErrorOccurred = true;
}
catch (...)
{
LoadAString(strResultText, IDCS_XERCESEXCEPTION);
//.........这里部分代码省略.........
示例14: Process
bool XFilterXMLProcessor::Process(const bool &bvalidation,
const StringX &strXMLData,
const stringT &strXMLFileName,
const stringT &strXSDFileName)
{
USES_XMLCH_STR
bool bErrorOccurred = false;
stringT cs_validation;
LoadAString(cs_validation, IDSC_XMLVALIDATION);
stringT cs_import;
LoadAString(cs_import, IDSC_XMLIMPORT);
stringT strResultText(_T(""));
m_bValidation = bvalidation; // Validate or Import
XSecMemMgr sec_mm;
// Initialize the XML4C2 system
try
{
XMLPlatformUtils::Initialize(XMLUni::fgXercescDefaultLocale, 0, 0, &sec_mm);
}
catch (const XMLException& toCatch)
{
#ifdef UNICODE
m_strXMLErrors = stringT(_X2ST(toCatch.getMessage()));
#else
char *szData = XMLString::transcode(toCatch.getMessage());
strResultText = stringT(szData);
XMLString::release(&szData);
#endif
return false;
}
// Create a SAX2 parser object.
SAX2XMLReader* pSAX2Parser = XMLReaderFactory::createXMLReader(&sec_mm);
// Set non-default features
pSAX2Parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
pSAX2Parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
pSAX2Parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
pSAX2Parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false);
pSAX2Parser->setFeature(XMLUni::fgXercesSkipDTDValidation, true);
// Set properties
pSAX2Parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
(void *)strXSDFileName.c_str());
pSAX2Parser->setProperty(XMLUni::fgXercesScannerName,
(void *)XMLUni::fgSGXMLScanner);
pSAX2Parser->setInputBufferSize(4096);
// Create SAX handler object and install it on the pSAX2Parser, as the
// document and error pSAX2Handler.
XFilterSAX2Handlers * pSAX2Handler = new XFilterSAX2Handlers;
pSAX2Parser->setContentHandler(pSAX2Handler);
pSAX2Parser->setErrorHandler(pSAX2Handler);
// Workaround/bypass until Xerces supports retrieving version from the
// <xs:schema ...> statement!
// Set 'dummy' schema version to arbitrary value > 1
pSAX2Handler->SetSchemaVersion(99);
pSAX2Handler->SetVariables(m_pAsker, &m_MapFilters, m_FPool, m_bValidation);
try
{
// Let's begin the parsing now
if (!strXMLFileName.empty()) {
pSAX2Parser->parse(_W2X(strXMLFileName.c_str()));
} else {
const char *szID = "database_filters";
#ifdef UNICODE
const char *buffer = XMLString::transcode(_W2X(strXMLData.c_str()));
#else
const char *buffer = strXMLData.c_str();
#endif
MemBufInputSource* memBufIS = new MemBufInputSource(
(const XMLByte*)buffer,
strXMLData.length(),
szID, false);
pSAX2Parser->parse(*memBufIS);
delete memBufIS;
#ifdef UNICODE
XMLString::release((char **)&buffer);
#endif
}
}
catch (const OutOfMemoryException&)
{
LoadAString(strResultText, IDCS_XERCESOUTOFMEMORY);
bErrorOccurred = true;
}
catch (const XMLException& e)
{
#ifdef UNICODE
strResultText = stringT(_X2ST(e.getMessage()));
#else
char *szData = XMLString::transcode(e.getMessage());
strResultText = stringT(szData);
XMLString::release(&szData);
//.........这里部分代码省略.........
示例15: Process
//.........这里部分代码省略.........
hr = pSchemaCache->add(L"", cvXSDFileName);
if (hr != S_OK) {
LoadAString(m_strXMLErrors, IDSC_INVALID_SCHEMA);
goto exit;
}
hr = pSchemaCache->validate();
if (hr != S_OK) {
LoadAString(m_strXMLErrors, IDSC_INVALID_SCHEMA);
goto exit;
}
// Check that we can get the Schema version
BSTR bst_schema, bst_schema_version;
bst_schema = L"";
ISchema *pischema;
hr = pSchemaCache->getSchema(bst_schema, &pischema);
if (hr != S_OK) {
LoadAString(m_strXMLErrors, IDSC_MISSING_SCHEMA_VER);
goto exit;
}
hr = pischema->get_version(&bst_schema_version);
if (hr != S_OK) {
LoadAString(m_strXMLErrors, IDSC_INVALID_SCHEMA_VER);
goto exit;
}
pCH->SetSchemaVersion(&bst_schema_version);
// Set the SAXReader/Schema Cache features and properties
{
/* Documentation is unclear as to what is in which release.
Try them all - if they don't get set, the world will not end!
Common Error codes:
S_OK Operation successful 0x00000000
E_NOTIMPL Not implemented 0x80004001
E_NOINTERFACE No such interface supported 0x80004002
E_ABORT Operation aborted 0x80004004
E_FAIL Unspecified failure 0x80004005
E_INVALIDARG Invalid argument 0x80070057
Normally not supported on a back level MSXMLn.DLL
*/
// Want all validation errors
hr = pSAX2Reader->putFeature(L"exhaustive-errors", VARIANT_TRUE);
// Don't allow user to override validation by using DTDs
hr = pSAX2Reader->putFeature(L"prohibit-dtd", VARIANT_TRUE);
// Don't allow user to override validation by using DTDs (2 features)
hr = pSAX2Reader->putFeature(L"http://xml.org/sax/features/external-general-entities",
VARIANT_FALSE);
hr = pSAX2Reader->putFeature(L"http://xml.org/sax/features/external-parameter-entities",
VARIANT_FALSE);
// Want to validate XML file
hr = pSAX2Reader->putFeature(L"schema-validation", VARIANT_TRUE);
// Ignore any schema specified in the XML file
hr = pSAX2Reader->putFeature(L"use-schema-location", VARIANT_FALSE);
// Ignore any schema in the XML file
hr = pSAX2Reader->putFeature(L"use-inline-schema", VARIANT_FALSE);
// Only use the XSD in PWSafe's installation directory!
hr = pSAX2Reader->putProperty(L"schemas", _variant_t(pSchemaCache));
}
// Let's begin the parsing now
if (!strXMLFileName.empty()) {
wchar_t wcURL[MAX_PATH]={0};
_tcscpy_s(wcURL, MAX_PATH, strXMLFileName.c_str());
hr = pSAX2Reader->parseURL(wcURL);
} else {
CComVariant cvXMLData = strXMLData.c_str();
hr = pSAX2Reader->parse(cvXMLData);
}
if (!FAILED(hr)) { // Check for parsing errors
if (pEH->bErrorsFound == TRUE) {
m_strXMLErrors = pEH->m_strValidationResult;
} else {
b_ok = true;
}
} else {
if (pEH->bErrorsFound == TRUE) {
m_strXMLErrors = pEH->m_strValidationResult;
} else {
Format(m_strXMLErrors, IDSC_MSXMLPARSEERROR, hr,
m_bValidation ? cs_validation.c_str() : cs_import.c_str());
}
} // End Check for parsing errors
} else {
Format(m_strXMLErrors, IDSC_MSXMLBADCREATESCHEMA, hr,
m_bValidation ? cs_validation.c_str() : cs_import.c_str());
} // End Create Schema Cache
exit:
if (pSchemaCache != nullptr)
pSchemaCache->Release();
if (pSAX2Reader != nullptr)
pSAX2Reader->Release();
return b_ok;
}