本文整理汇总了C++中String::Exists方法的典型用法代码示例。如果您正苦于以下问题:C++ String::Exists方法的具体用法?C++ String::Exists怎么用?C++ String::Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::Exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogChange_str
bool Settings::LogChange_str(const String& strSection, const String& strKey,
const String& strValue)
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Empty!\n";
OT_FAIL;
}
if (!strKey.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strKey"
<< " is Empty!\n";
OT_FAIL;
}
const char* const szValue = (strValue.Exists() && !strValue.Compare(""))
? strValue.Get()
: "nullptr";
String strCategory, strOption;
if (!Log::StringFill(strCategory, strSection.Get(), 12)) return false;
if (!Log::StringFill(strOption, strKey.Get(), 30, " to:")) return false;
otWarn << "Setting " << strCategory << " " << strOption << " " << szValue
<< " \n";
return true;
}
示例2: CheckSetSection
bool Settings::CheckSetSection(const String& strSection,
const String& strComment,
bool& out_bIsNewSection)
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Empty!\n";
OT_FAIL;
}
if (!strComment.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strComment"
<< " is Empty!\n";
OT_FAIL;
}
const char* const szComment =
(strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
: nullptr;
const int64_t lSectionSize =
pvt->iniSimple.GetSectionSize(strSection.Get());
if (1 > lSectionSize) {
out_bIsNewSection = true;
SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), nullptr,
nullptr, szComment, false);
if (0 > rc) return false;
}
else {
out_bIsNewSection = false;
}
return true;
}
示例3: AppendFile
// static
bool OTPaths::AppendFile(String& out_strPath, const String& strBasePath,
const String& strFileName)
{
if (!strBasePath.Exists()) {
otErr << __FUNCTION__ << ": Null: "
<< "strBasePath"
<< " passed in!\n";
OT_FAIL;
}
if (!strFileName.Exists()) {
otErr << __FUNCTION__ << ": Null: "
<< "strFileName"
<< " passed in!\n";
OT_FAIL;
}
String l_strBasePath_fix(""), l_strFileName_fix("");
if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false;
if (!FixPath(strFileName, l_strFileName_fix, false)) return false;
std::string l_strBasePath(l_strBasePath_fix.Get()),
l_strFileName(l_strFileName_fix.Get());
l_strBasePath.append(l_strFileName);
const String l_strPath(l_strBasePath);
out_strPath = l_strPath;
return true;
}
示例4: WriteArmoredFile
bool OTASCIIArmor::WriteArmoredFile(
const String& foldername, const String& filename,
const // for "-----BEGIN OT LEDGER-----", str_type would contain "LEDGER"
std::string str_type, // There's no default, to force you to enter the right
// string.
bool bEscaped) const
{
OT_ASSERT(foldername.Exists());
OT_ASSERT(filename.Exists());
String strOutput;
if (WriteArmoredString(strOutput, str_type, bEscaped) &&
strOutput.Exists()) {
// WRITE IT TO THE FILE
// StorePlainString will attempt to create all the folders leading up to
// the path
// for the output file.
//
bool bSaved = OTDB::StorePlainString(strOutput.Get(), foldername.Get(),
filename.Get());
if (!bSaved) {
otErr << "OTASCIIArmor::WriteArmoredFile"
<< ": Failed saving to file: %s%s%s\n\n Contents:\n\n"
<< strOutput << "\n\n",
foldername.Get(), Log::PathSeparator(), filename.Get();
return false;
}
return true;
}
return false;
}
示例5: Set
// static
bool OTPaths::Set(OTSettings& config, const String& strSection,
const String& strKey, const String& strValue,
const bool& bIsRelative, bool& out_bIsNewOrUpdated,
const String& strComment)
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Null: "
<< "strSection"
<< " passed in!\n";
OT_FAIL;
}
if (!strKey.Exists()) {
otErr << __FUNCTION__ << ": Null: "
<< "strKey"
<< " passed in!\n";
OT_FAIL;
}
out_bIsNewOrUpdated = false;
const bool bPreLoaded(config.IsLoaded());
if (!bPreLoaded) // we only need to load, if not already loaded.
{
config.Reset();
if (!config.Load()) {
OT_FAIL;
}
}
bool bBoolIsNew(false);
String strRelativeKey("");
strRelativeKey.Format("%s%s", strKey.Get(), OT_CONFIG_ISRELATIVE);
if (config.Set_bool(strSection, strRelativeKey, bIsRelative, bBoolIsNew,
strComment)) {
bool bStringIsNew = false;
if (config.Set_str(strSection, strKey, strValue, bStringIsNew)) {
if (bBoolIsNew && bStringIsNew) // using existing key
{
out_bIsNewOrUpdated = true;
}
if (!bPreLoaded) {
if (!config.Save()) {
OT_FAIL;
}
config.Reset();
}
return true;
}
}
// if we get here, there has been a error!
OT_FAIL;
}
示例6: CheckSet_str
bool Settings::CheckSet_str(const String& strSection, const String& strKey,
const String& strDefault, std::string& out_strResult,
bool& out_bIsNew, const String& strComment)
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Empty!\n";
OT_FAIL;
}
if (!strKey.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strKey"
<< " is Empty!\n";
OT_FAIL;
}
const char* const szDefault =
(strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get()
: nullptr;
String strTempResult;
bool bKeyExist;
if (!Check_str(strSection, strKey, strTempResult, bKeyExist)) return false;
if (bKeyExist) {
// Already have a key, lets use it's value.
out_bIsNew = false;
out_strResult = strTempResult.Get();
return true;
}
else {
bool bNewKeyCheck;
if (!Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
return false;
if (nullptr == szDefault) // The Default is to have no key.
{
// Success
out_bIsNew = false;
out_strResult = "";
return true;
}
if (bNewKeyCheck) {
// Success
out_bIsNew = true;
out_strResult = strDefault.Get();
return true;
}
}
// If we get here, error!
OT_FAIL;
}
示例7: Check_bool
bool Settings::Check_bool(const String& strSection, const String& strKey,
bool& out_bResult, bool& out_bKeyExist) const
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Empty!\n";
OT_FAIL;
}
if (strSection.Compare("")) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Blank!\n";
OT_FAIL;
}
if (!strKey.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strKey"
<< " is Empty!\n";
OT_FAIL;
}
if (strKey.Compare("")) {
otErr << __FUNCTION__ << ": Error: "
<< "strKey"
<< " is Blank!\n";
OT_FAIL;
}
const char* szVar =
pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr);
String strVar(szVar);
if (strVar.Exists() &&
(strVar.Compare("false") || strVar.Compare("true"))) {
out_bKeyExist = true;
if (strVar.Compare("true"))
out_bResult = true;
else
out_bResult = false;
}
else {
out_bKeyExist = false;
out_bResult = false;
}
return true;
}
示例8: GetHomeFromSystem
// static
bool OTPaths::GetHomeFromSystem(String& out_strHomeFolder)
{
#ifdef _WIN32
#ifdef _UNICODE
TCHAR szPath[MAX_PATH] = L"";
#else
TCHAR szPath[MAX_PATH] = "";
#endif
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
nullptr, 0, szPath))) {
#ifdef UNICODE
out_strHomeFolder.Set(utf8util::UTF8FromUTF16(szPath));
#else
out_strHomeFolder.Set(szPath);
#endif
}
else {
out_strHomeFolder.Set("");
return false;
}
#elif defined(__APPLE__)
String home(getenv("HOME"));
String library = "";
AppendFolder(library, home, "Library");
AppendFolder(out_strHomeFolder, library, "Application Support");
#else
out_strHomeFolder.Set(getenv("HOME"));
#endif
return out_strHomeFolder.Exists();
}
示例9: Decrypt
bool LegacySymmetric::Decrypt(
const api::Crypto& crypto,
const String& strKey,
String& strCiphertext,
String& strOutput,
const String& pstrDisplay,
const OTPassword* pAlreadyHavePW)
{
if (!strKey.Exists()) {
LogDetail(OT_METHOD)(__FUNCTION__)(
": Nonexistent: The symmetric key. Please supply. (Failure).")
.Flush();
return false;
}
implementation::LegacySymmetric theKey(crypto);
if (!theKey.SerializeFrom(strKey)) {
LogDetail(OT_METHOD)(__FUNCTION__)(
": Failed trying to load symmetric key from "
"string. (Returning false).")
.Flush();
return false;
}
// By this point, we know we have a ciphertext envelope and a symmetric Key.
//
return Decrypt(
theKey, strCiphertext, strOutput, pstrDisplay, pAlreadyHavePW);
}
示例10: Contains
bool String::Contains(const String& strCompare) const
{
if (nullptr == data_ || !strCompare.Exists()) {
return false;
}
if (strstr(data_, strCompare.Get())) return true;
return false;
}
示例11: Concatenate
// append a string at the end of the current buffer.
void String::Concatenate(const String& strBuf)
{
std::string str_output;
if ((length_ > 0) && (nullptr != data_)) str_output += data_;
if (strBuf.Exists() && (strBuf.GetLength() > 0)) str_output += strBuf.Get();
Set(str_output.c_str());
}
示例12: CheckSet_long
bool Settings::CheckSet_long(const String& strSection, const String& strKey,
const int64_t& lDefault, int64_t& out_lResult,
bool& out_bIsNew, const String& strComment)
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Empty!\n";
OT_FAIL;
}
if (!strKey.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strKey"
<< " is Empty!\n";
OT_FAIL;
}
int64_t lTempResult;
bool bKeyExist;
if (!Check_long(strSection, strKey, lTempResult, bKeyExist)) return false;
if (bKeyExist) {
// Already have a key, lets use it's value.
out_bIsNew = false;
out_lResult = lTempResult;
return true;
}
else {
bool bNewKeyCheck;
if (!Set_long(strSection, strKey, lDefault, bNewKeyCheck, strComment))
return false;
if (bNewKeyCheck) {
// Success
out_bIsNew = true;
out_lResult = lDefault;
return true;
}
}
// If we get here, error!
OT_FAIL;
}
示例13: Set_bool
bool Settings::Set_bool(const String& strSection, const String& strKey,
const bool& bValue, bool& out_bNewOrUpdate,
const String& strComment)
{
if (!strSection.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strSection"
<< " is Empty!\n";
OT_FAIL;
}
if (!strKey.Exists()) {
otErr << __FUNCTION__ << ": Error: "
<< "strKey"
<< " is Empty!\n";
OT_FAIL;
}
const String strValue(bValue ? "true" : "false");
return Set_str(strSection, strKey, strValue, out_bNewOrUpdate, strComment);
}
示例14: FlatFile_DeleteSecret
// static
bool OTKeyring::FlatFile_DeleteSecret(const String& strUser,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
const std::string str_pw_folder(OTKeyring::FlatFile_GetPasswordFolder());
if (!str_pw_folder.empty()) {
String strExactPath;
strExactPath.Format("%s%s%s", str_pw_folder.c_str(),
Log::PathSeparator(), strUser.Get());
const std::string str_ExactPath(strExactPath.Get());
std::ofstream ofs(str_ExactPath.c_str(),
std::ios::out | std::ios::binary);
if (ofs.fail()) {
otErr << __FUNCTION__ << ": Error opening file (to delete it): "
<< str_ExactPath.c_str() << '\n';
return false;
}
ofs.clear();
ofs << "(This space intentionally left blank.)\n";
bool bSuccess = ofs.good() ? true : false;
ofs.close();
// Note: I bet you think I should be overwriting the file 7 times here
// with
// random data, right? Wrong: YOU need to override OTKeyring and create
// your
// own subclass, where you can override DeleteSecret and do that stuff
// yourself. It's outside of the scope of OT.
//
if (remove(str_ExactPath.c_str()) != 0) {
bSuccess = false;
otErr << "** (OTKeyring::FlatFile_DeleteSecret) Failed trying to "
<< "delete file (containing secret): "
<< str_ExactPath.c_str() << '\n';
}
else {
bSuccess = true;
otInfo << "** (OTKeyring::FlatFile_DeleteSecret) Success "
<< "deleting file: " << str_ExactPath.c_str() << '\n';
}
return bSuccess;
}
otErr << "OTKeyring::FlatFile_DeleteSecret: Unable to delete any derived "
"key, since password_folder not provided in config file.\n";
return false;
}
示例15: RelativeToCanonical
// this function dosn't change the "strRelativePath" so. It will only fix the
// strBasePath.
// static
bool OTPaths::RelativeToCanonical(String& out_strCanonicalPath,
const String& strBasePath,
const String& strRelativePath)
{
if (!strBasePath.Exists()) {
otErr << __FUNCTION__ << ": Null: "
<< "strBasePath"
<< " passed in!\n";
OT_FAIL;
}
if (!strRelativePath.Exists()) {
otErr << __FUNCTION__ << ": Null: "
<< "strRelativePath"
<< " passed in!\n";
OT_FAIL;
}
String l_strBasePath_fix("");
if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false;
if (strRelativePath.Compare(".")) {
out_strCanonicalPath = strBasePath;
return true;
} // if ".", return base path.
std::string l_strBasePath(l_strBasePath_fix.Get()),
l_strRelativePath(strRelativePath.Get());
l_strBasePath.append(l_strRelativePath);
String l_strPath(l_strBasePath), l_strCanonicalPath("");
if (!ToReal(l_strPath, l_strCanonicalPath)) return false;
out_strCanonicalPath = l_strCanonicalPath;
return true;
}