本文整理汇总了C++中stlw::string::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ string::empty方法的具体用法?C++ string::empty怎么用?C++ string::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stlw::string
的用法示例。
在下文中一共展示了string::empty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EscapeString
static STLW::string EscapeString(const STLW::string & sSource)
{
if (sSource.empty()) { return "\"\""; }
STLW::string::const_iterator itsSource = sSource.begin();
while (itsSource != sSource.end())
{
const UCHAR_8 ucTMP = *itsSource;
if (!((ucTMP >= 'a' && ucTMP <= 'z') ||
(ucTMP >= 'A' && ucTMP <= 'Z') ||
(ucTMP >= '0' && ucTMP <= '9') ||
ucTMP == '.' || ucTMP == '_' || ucTMP == ':' || ucTMP == '*' ||
ucTMP == '[' || ucTMP == ']' || ucTMP == '\\' || ucTMP == '/' || ucTMP == '-'))
{
return '"' + sSource + '"';
}
++itsSource;
}
return sSource;
}
示例2: FmtChar
//
// Character
//
static void FmtChar(StringBuffer & oBuffer,
const CDT & oCurrentArgument,
const UINT_32 iFmtFlags,
const INT_32 iWidth,
CHAR_8 chPadSymbol)
{
const CDT::eValType oValType = oCurrentArgument.GetType();
if (oValType == CDT::UNDEF && iWidth > 0)
{
oBuffer.Append(iWidth, chPadSymbol);
return;
}
UCHAR_8 ucTMP = ' ';
if (oValType == CDT::INT_VAL || oValType == CDT::REAL_VAL)
{
ucTMP = oCurrentArgument.GetInt();
}
else if (oValType == CDT::STRING_VAL)
{
const STLW::string sTMP = oCurrentArgument.GetString();
if (sTMP.empty() && iWidth > 0)
{
oBuffer.Append(iWidth, chPadSymbol);
return;
}
ucTMP = sTMP[0];
}
else if (oValType == CDT::POINTER_VAL) { ucTMP = 'P'; }
else if (oValType == CDT::ARRAY_VAL) { ucTMP = 'A'; }
else if (oValType == CDT::HASH_VAL) { ucTMP = 'H'; }
if (iFmtFlags & F_LEFT_ALIGN)
{
oBuffer.Append(1, ucTMP);
if (iWidth > 1) { oBuffer.Append(iWidth - 1, chPadSymbol); }
}
else
{
if (iWidth > 1) { oBuffer.Append(iWidth - 1, chPadSymbol); }
oBuffer.Append(1, ucTMP);
}
}
示例3: main
int main(int argc, char ** argv)
{
const char * szConfigFile = NULL;
if (argc == 1)
{
fprintf(stderr, "Global config not given, ");
szConfigFile = getenv("CAS_GLOBAL_CONFIG");
if (szConfigFile != NULL)
{
fprintf(stderr, " using %s from ENVIRONMENT", szConfigFile);
}
else
{
szConfigFile = CAS_GLOBAL_CONFIG_FILE;
fprintf(stderr, " using %s as DEFAULT\n", szConfigFile);
}
}
else if (argc == 2) { szConfigFile = argv[1]; }
else { fprintf(stderr, "usage: %s [global-config.xml]\n", argv[0]); return EX_USAGE; }
FILE * F = fopen(szConfigFile, "rb");
if (F == NULL) { fprintf(stderr, "ERROR: Cannot open `%s` for reading: %s\n", szConfigFile, strerror(errno)); return EX_SOFTWARE; }
// Store path to file as include directory
CCHAR_P szTMP = szConfigFile + strlen(szConfigFile);
while (szTMP != szConfigFile && *szTMP != '/' && *szTMP != '\\') { --szTMP; }
STLW::vector<STLW::string> vIncludeDirs;
if (szTMP != szConfigFile) { vIncludeDirs.push_back(STLW::string(szConfigFile, (szTMP - szConfigFile))); }
try
{
ASGlobalConfig oGlobalConfig;
ASGlobalConfigHandler oHandler(oGlobalConfig, vIncludeDirs);
ASXMLParser oParser(&oHandler);
if (oParser.ParseFile(F) == -1)
{
fprintf(stderr, "ERROR: In file %s: %s\n", szConfigFile, oHandler.GetError().c_str());
return EX_CONFIG;
}
fclose(F);
fprintf(stdout, " Libexec dirs:\n");
UINT_32 iI = 0;
for(; iI < oGlobalConfig.libexec_dirs.size(); ++iI)
{
fprintf(stdout, " %s\n", oGlobalConfig.libexec_dirs[iI].c_str());
}
fprintf(stdout, "\n Modules:\n");
for(iI = 0; iI < oGlobalConfig.modules_list.size(); ++iI)
{
fprintf(stdout, " Name: %s\n"
" Type: %s\n",
oGlobalConfig.modules_list[iI].name.c_str(),
oGlobalConfig.modules_list[iI].moduletype.c_str());
STLW::string sTMP = CheckFile(oGlobalConfig.libexec_dirs, oGlobalConfig.modules_list[iI].library);
if (sTMP.size() == 0)
{
fprintf(stdout, " *** ERROR: Cannot find Library file: %s\n", oGlobalConfig.modules_list[iI].library.c_str());
}
else
{
fprintf(stdout, " Library file: %s\n", CheckFile(oGlobalConfig.libexec_dirs, oGlobalConfig.modules_list[iI].library).c_str());
}
STLW::string sData = Dump(oGlobalConfig.modules_list[iI].configuration);
if (!sData.empty() && sData != "\"\"\n") { fprintf(stdout, " Configuration: %s\n", sData.c_str()); }
// TBD
fprintf(stdout, "\n");
}
}
catch(STLW::exception &e) { fprintf(stderr, "ERROR: %s\n", e.what()); return EX_SOFTWARE; }
catch(...) { fprintf(stderr, "ERROR: Ouch!\n"); return EX_SOFTWARE; }
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
示例4: GetParams
//
// Get parameters
//
static INT_32 GetParams(const INT_32 iArgc,
CHAR_P * aArgv,
STLW::string & sGlobalConfigFile,
STLW::string & sConfigFile,
STLW::string & sModuleName,
bool & bDebugInfo,
bool & bPrintHelp,
bool & bPrintVersion,
bool & bPrintCompileInfo,
bool & bDaemonize)
{
bDebugInfo = bPrintHelp = bPrintVersion = bPrintCompileInfo = false;
bDaemonize = true;
sConfigFile.erase();
UINT_32 iArgNum = 1;
CCHAR_P szArgValue;
for(;;)
{
INT_32 iOption = GetOpt(oOptions, iArgNum, iArgc, aArgv, szArgValue);
if (iOption == -1) { break; }
switch (iOption)
{
case 'g':
sGlobalConfigFile = szArgValue;
break;
case 'f':
sConfigFile = szArgValue;
break;
case 'm':
sModuleName = szArgValue;
break;
case 'd':
bDebugInfo = true;
break;
case 'h':
bPrintHelp = true;
break;
case 'v':
bPrintVersion = true;
break;
case 'V':
bPrintCompileInfo = true;
break;
case 'F':
bDaemonize = false;
break;
case '?':
fprintf(stderr, "Unknown option `%s` or option with missed argument\n", aArgv[iArgNum]);
return EX_CONFIG;
break;
}
}
if (sConfigFile.empty())
{
// Check environment
CCHAR_P szConfigFile = getenv(ENV_CONFIG_FILE);
if (szConfigFile != NULL && *szConfigFile != '\0') { sConfigFile = szConfigFile; }
if (sConfigFile.empty()) { sConfigFile.assign(DEFAULT_CONFIG_FILE); }
}
if (sGlobalConfigFile.empty())
{
CCHAR_P szConfigFile = getenv("CAS_GLOBAL_CONFIG");
if (szConfigFile != NULL)
{
fprintf(stderr, "Global config not given, using %s from ENVIRONMENT\n", szConfigFile);
sGlobalConfigFile = szConfigFile;
}
}
return EX_OK;
}