本文整理汇总了C++中stringT::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ stringT::c_str方法的具体用法?C++ stringT::c_str怎么用?C++ stringT::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringT
的用法示例。
在下文中一共展示了stringT::c_str方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Process
// ---------------------------------------------------------------------------
bool XFileXMLProcessor::Process(const bool &bvalidation, const stringT &ImportedPrefix,
const stringT &strXMLFileName, const stringT &strXSDFileName,
const bool &bImportPSWDsOnly)
{
USES_XMLCH_STR
bool bErrorOccurred = false;
bool b_into_empty = 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)
{
strResultText = stringT(_X2ST(toCatch.getMessage()));
return false;
}
const XMLCh* xmlfilename = _W2X(strXMLFileName.c_str());
const XMLCh* schemafilename = _W2X(strXSDFileName.c_str());
// 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::fgXercesDynamic, false);
pSAX2Parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
pSAX2Parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false);
pSAX2Parser->setFeature(XMLUni::fgXercesSkipDTDValidation, true);
// Set properties
pSAX2Parser->setProperty(XMLUni::fgXercesScannerName,
const_cast<void*>(reinterpret_cast<const void*>(XMLUni::fgSGXMLScanner)));
pSAX2Parser->setInputBufferSize(4096);
// Set schema file name (also via property)
pSAX2Parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
const_cast<void*>(reinterpret_cast<const void*>(schemafilename)));
// Create SAX handler object and install it on the pSAX2Parser, as the
// document and error pSAX2Handler.
XFileSAX2Handlers * pSAX2Handler = new XFileSAX2Handlers;
pSAX2Parser->setContentHandler(pSAX2Handler);
pSAX2Parser->setErrorHandler(pSAX2Handler);
pSAX2Handler->SetVariables(m_bValidation ? NULL : m_pXMLcore, m_bValidation,
ImportedPrefix, m_delimiter, bImportPSWDsOnly,
m_bValidation ? NULL : m_pPossible_Aliases,
m_bValidation ? NULL : m_pPossible_Shortcuts,
m_pmulticmds, m_prpt);
if (!m_bValidation) {
b_into_empty = m_pXMLcore->GetNumEntries() == 0;
}
try {
// Let's begin the parsing now
pSAX2Parser->parse(xmlfilename);
}
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);
bErrorOccurred = true;
}
if (pSAX2Handler->getIfErrors() || bErrorOccurred) {
bErrorOccurred = true;
strResultText = pSAX2Handler->getValidationResult();
Format(m_strXMLErrors, IDSC_XERCESPARSEERROR,
m_bValidation ? cs_validation.c_str() : cs_import.c_str(),
strResultText.c_str());
} else {
if (m_bValidation) {
m_strXMLErrors = pSAX2Handler->getValidationResult();
m_numEntriesValidated = pSAX2Handler->getNumEntries();
m_delimiter = pSAX2Handler->getDelimiter();
} else {
pSAX2Handler->AddXMLEntries();
// Get numbers (may have been modified by AddXMLEntries
//.........这里部分代码省略.........
示例2: Process
// ---------------------------------------------------------------------------
bool MFileXMLProcessor::Process(const bool &bvalidation, const stringT &ImportedPrefix,
const stringT &strXMLFileName, const stringT &strXSDFileName,
const bool &bImportPSWDsOnly)
{
HRESULT hr, hr0, hr60;
bool b_ok = false;
bool b_into_empty;
stringT cs_validation;
LoadAString(cs_validation, IDSC_XMLVALIDATION);
stringT cs_import;
LoadAString(cs_import, IDSC_XMLIMPORT);
m_strXMLErrors = _T("");
m_bValidation = bvalidation; // Validate or Import
// Create SAXReader object
ISAXXMLReader *pSAX2Reader = NULL;
// Get ready for XSD schema validation
IXMLDOMSchemaCollection2 *pSchemaCache = NULL;
if (m_bValidation) { //XMLValidate
hr60 = CoCreateInstance(__uuidof(SAXXMLReader60), NULL, CLSCTX_ALL,
__uuidof(ISAXXMLReader), (void **)&pSAX2Reader);
if (FAILED(hr60)) {
LoadAString(m_strXMLErrors, IDSC_NOMSXMLREADER);
goto exit;
}
} else { // XMLImport
b_into_empty = m_pXMLcore->GetNumEntries() == 0;
hr0 = CoCreateInstance(__uuidof(SAXXMLReader60), NULL, CLSCTX_ALL,
__uuidof(ISAXXMLReader), (void **)&pSAX2Reader);
}
// Create ContentHandlerImpl object
MFileSAX2ContentHandler *pCH = new MFileSAX2ContentHandler();
pCH->SetVariables(m_bValidation ? NULL : m_pXMLcore, m_bValidation,
ImportedPrefix, m_delimiter, bImportPSWDsOnly,
m_bValidation ? NULL : m_pPossible_Aliases,
m_bValidation ? NULL : m_pPossible_Shortcuts,
m_pmulticmds, m_prpt);
// Create ErrorHandlerImpl object
MFileSAX2ErrorHandler *pEH = new MFileSAX2ErrorHandler();
// Set Content Handler
hr = pSAX2Reader->putContentHandler(pCH);
// Set Error Handler
hr = pSAX2Reader->putErrorHandler(pEH);
hr = CoCreateInstance(__uuidof(XMLSchemaCache60), NULL, CLSCTX_ALL,
__uuidof(IXMLDOMSchemaCollection2), (void **)&pSchemaCache);
if (!FAILED(hr)) { // Create SchemaCache
// Initialize the SchemaCache object with the XSD filename
CComVariant cvXSDFileName = strXSDFileName.c_str();
hr = pSchemaCache->add(L"", cvXSDFileName);
// 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
wchar_t wcURL[MAX_PATH] = {0};
_tcscpy_s(wcURL, MAX_PATH, strXMLFileName.c_str());
hr = pSAX2Reader->parseURL(wcURL);
if (!FAILED(hr)) { // Check for parsing errors
if (pEH->bErrorsFound == TRUE) {
m_strXMLErrors = pEH->m_strValidationResult;
//.........这里部分代码省略.........
示例3: LockFile
bool pws_os::LockFile(const stringT &filename, stringT &locker,
HANDLE &lockFileHandle, int &LockCount)
{
const stringT lock_filename = GetLockFileName(filename);
stringT s_locker;
const stringT user = pws_os::getusername();
const stringT host = pws_os::gethostname();
const stringT pid = pws_os::getprocessid();
// Use Win32 API for locking - supposedly better at
// detecting dead locking processes
if (lockFileHandle != INVALID_HANDLE_VALUE) {
// here if we've open another (or same) dbase previously,
// need to unlock it. A bit inelegant...
// If app was minimized and ClearData() called, we've a small
// potential for a TOCTTOU issue here. Worse case, lock
// will fail.
const stringT cs_me = user + _T("@") + host + _T(":") + pid;
GetLocker(lock_filename, s_locker);
if (cs_me == s_locker) {
LockCount++;
locker.clear();
return true;
} else {
pws_os::UnlockFile(filename, lockFileHandle, LockCount);
}
}
// Since ::CreateFile can't create directories, we need to check it exists
// first and, if not, try and create it.
// This is primarily for the config directory in the local APPDATA directory
// but will also be called for the database lock file - and since the database
// is already there, it is a bit of a redundant check but easier than coding
// for every different situation.
stringT sDrive, sDir, sName, sExt;
pws_os::splitpath(lock_filename, sDrive, sDir, sName, sExt);
stringT sNewDir = sDrive + sDir;
DWORD dwAttrib = GetFileAttributes(sNewDir.c_str());
DWORD dwerr(0);
if (dwAttrib == INVALID_FILE_ATTRIBUTES)
dwerr = GetLastError();
BOOL brc(TRUE);
if (dwerr == ERROR_FILE_NOT_FOUND ||
(dwAttrib != INVALID_FILE_ATTRIBUTES) &&
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
SECURITY_ATTRIBUTES secatt = {0};
secatt.nLength = sizeof(secatt);
brc = ::CreateDirectory(sNewDir.c_str(), &secatt);
}
// Obviously, if we can't create the directory - don't bother trying to
// create the lock file!
if (brc) {
lockFileHandle = ::CreateFile(lock_filename.c_str(),
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS, // rely on share to fail if exists!
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH |
// (Lockheed Martin) Secure Coding 11-14-2007
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION,
NULL);
// Make sure it's a file and not a pipe. (Lockheed Martin) Secure Coding 11-14-2007
if (lockFileHandle != INVALID_HANDLE_VALUE) {
if (::GetFileType( lockFileHandle ) != FILE_TYPE_DISK) {
::CloseHandle( lockFileHandle );
lockFileHandle = INVALID_HANDLE_VALUE;
}
}
// End of Change. (Lockheed Martin) Secure Coding 11-14-2007
}
if (lockFileHandle == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
switch (error) {
case ERROR_SHARING_VIOLATION: // already open by a live process
GetLocker(lock_filename, s_locker);
locker = s_locker.c_str();
break;
default: {
// Give detailed error message, if possible
LPTSTR lpMsgBuf = NULL;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL) != 0) {
locker = lpMsgBuf;
LocalFree(lpMsgBuf);
} else { // should never happen!
LoadAString(locker, IDSC_NOLOCKACCESS); // berrer than nothing
}
}
break;
} // switch (error)
//.........这里部分代码省略.........
示例4: DeleteAFile
bool pws_os::DeleteAFile(const stringT &filename)
{
return DeleteFile(filename.c_str()) == TRUE;
}
示例5: RenameFile
bool pws_os::RenameFile(const stringT &oldname, const stringT &newname)
{
_tremove(newname.c_str()); // otherwise rename may fail if newname exists
return FileOP(oldname, newname, FO_MOVE);
}
示例6: MergeDependents
int PWScore::MergeDependents(PWScore *pothercore, MultiCommands *pmulticmds,
uuid_array_t &base_uuid, uuid_array_t &new_base_uuid,
const bool bTitleRenamed, stringT &str_timestring,
const CItemData::EntryType et,
std::vector<StringX> &vs_added)
{
UUIDVector dependentslist;
UUIDVectorIter paiter;
ItemListIter iter;
ItemListConstIter foundPos;
CItemData ci_temp;
int numadded(0);
StringX sx_merged;
LoadAString(sx_merged, IDSC_MERGED);
// Get all the dependents
pothercore->GetAllDependentEntries(base_uuid, dependentslist, et);
for (paiter = dependentslist.begin();
paiter != dependentslist.end(); paiter++) {
iter = pothercore->Find(*paiter);
if (iter == pothercore->GetEntryEndIter())
continue;
CItemData *pci = &iter->second;
ci_temp = (*pci);
if (Find(*paiter) != GetEntryEndIter()) {
ci_temp.CreateUUID();
}
// If the base title was renamed - we should automatically rename any dependent.
// If we didn't, we still need to check uniqueness!
StringX sx_newTitle = ci_temp.GetTitle();
if (bTitleRenamed) {
StringX sx_otherTitle(sx_newTitle);
Format(sx_newTitle, _T("%s%s%s"), sx_otherTitle.c_str(),
sx_merged.c_str(), str_timestring.c_str());
ci_temp.SetTitle(sx_newTitle);
}
// Check this is unique - if not - don't add this one! - its only an alias/shortcut!
// We can't keep trying for uniqueness after adding a timestamp!
foundPos = Find(ci_temp.GetGroup(), sx_newTitle, ci_temp.GetUser());
if (foundPos != GetEntryEndIter())
continue;
Command *pcmd1 = AddEntryCommand::Create(this, ci_temp, new_base_uuid);
pcmd1->SetNoGUINotify();
pmulticmds->Add(pcmd1);
if (et == CItemData::ET_ALIAS) {
ci_temp.SetPassword(_T("[Alias]"));
ci_temp.SetAlias();
} else if (et == CItemData::ET_SHORTCUT) {
ci_temp.SetPassword(_T("[Shortcut]"));
ci_temp.SetShortcut();
} else
ASSERT(0);
StringX sx_added;
Format(sx_added, GROUPTITLEUSERINCHEVRONS,
ci_temp.GetGroup().c_str(), ci_temp.GetTitle().c_str(),
ci_temp.GetUser().c_str());
vs_added.push_back(sx_added);
numadded++;
}
return numadded;
}