• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ stlw::string类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中stlw::string的典型用法代码示例。如果您正苦于以下问题:C++ string类的具体用法?C++ string怎么用?C++ string使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了string类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: InitHandler

//
// Initialize handler
//
INT_32 IrisEchoHandler::InitHandler(IRIS::GlobalContext        & oGlobalContext,
                                    const IRIS::HandlerConfig  & oHandlerConfig,
                                    IRIS::Logger               & oLogger)
{
	// Create thread group
	pThreadGroup = new IrisEchoThreadGroup;

	// Create set of threads
	for (UINT_32 iPos = 0; iPos < oHandlerConfig.start_threads; ++iPos)
	{
		pThreadGroup -> CreateThread(new IrisEchoThreadWorker(oWorkerContext));
		++oWorkerContext.threads;
		oLogger.Notice("Echo thread %d started", oWorkerContext.threads);
	}

	const STLW::string sLogger = oHandlerConfig.logger.empty() ? oGlobalContext.config.logger_type : oHandlerConfig.logger;
	// Get logger from factory for main process
	pLoggerObject = static_cast<IRIS::LoggerObject *>(oGlobalContext.factory.GetObject("Logger/" + sLogger));
	if (pLoggerObject == NULL)
	{
		oLogger.Emerg("Can't get logger `%s` for %s", sLogger.c_str(), GetObjectName());
		return -1;
	}

	oLogger.Notice("Echo module initialized");

return 0;
}
开发者ID:CommunicoPublic,项目名称:iris,代码行数:31,代码来源:IrisEchoHandler.cpp


示例2: CDT

// CTPP2
CTPP2::CTPP2(unsigned int arg_stack_size, unsigned int code_stack_size, unsigned int steps_limit, unsigned int max_functions,
             STLW::string src_charset, STLW::string dst_charset) {
    try {
        params = new CDT(CDT::HASH_VAL);
        syscalls = new SyscallFactory(max_functions);
        STDLibInitializer::InitLibrary(*syscalls);
        vm = new VM(syscalls, arg_stack_size, code_stack_size, steps_limit);

        int i = 0;
        while (functions[i])
            bind(functions[i++]());

        if (src_charset.size() && dst_charset.size()) {
            charset.src = src_charset;
            charset.dst = dst_charset;
            charset.convert = true;
        } else {
            // Конвертирование не требуется
            charset.convert = false;
        }
    } catch (...) {
        cpp_free(params);
        if (syscalls) {
            STDLibInitializer::DestroyLibrary(*syscalls);
            cpp_free(syscalls);
        }
        cpp_free(vm);
    }
}
开发者ID:Azq2,项目名称:php-ctpp2,代码行数:30,代码来源:ctpp2.cpp


示例3: Handler

//
// Handler
//
INT_32 FnTruncate::Handler(CDT            * aArguments,
                           const UINT_32    iArgNum,
                           CDT            & oCDTRetVal,
                           Logger         & oLogger)
{
	if (iArgNum == 2)
	{
		const UINT_32       iMaxLen = UINT_32(aArguments[0].GetInt());
		const STLW::string   sData   = aArguments[1].GetString();

		if (sData.size() > iMaxLen) { oCDTRetVal = STLW::string(sData, 0, iMaxLen); }
		else                        { oCDTRetVal = sData;                          }

		return 0;
	}
	else if (iArgNum == 3)
	{
		const UINT_32  iMaxLen = UINT_32(aArguments[1].GetInt());
		STLW::string    sData   = aArguments[2].GetString();

		if (sData.size() > iMaxLen)
		{
			sData = STLW::string(sData, 0, iMaxLen);
			sData.append(aArguments[0].GetString());
		}

		oCDTRetVal = sData;
		return 0;
	}

	oLogger.Emerg("Usage: TRUNCATE(x, offest[, addon])");
return -1;
}
开发者ID:Azq2,项目名称:ctpp2,代码行数:36,代码来源:FnTruncate.cpp


示例4: FindFile

//
// Find file in specified list of directories
//
INT_32 MainProcess::FindFile(const STLW::vector<STLW::string>  & vDirectories,
                             const STLW::string                & sFilename,
                             STLW::string                      & sFullpath)
{
	STLW::vector<STLW::string>::const_iterator itvDirectories = vDirectories.begin();
	while (itvDirectories != vDirectories.end())
	{
		sFullpath.erase();
		const STLW::string & sDir(*itvDirectories);
		if (sDir.size())
		{
			sFullpath.assign(sDir);
			if (sDir[sDir.size() - 1] != '/') { sFullpath.append(1, '/'); }
		}

		sFullpath.append(sFilename);

		const INT_64 iFileHandle = File::Open(sFullpath.c_str(), OpenMode::READ);
		if (iFileHandle != -1)
		{
			File::Close(iFileHandle);
			return 0;
		}

		++itvDirectories;
	}
return -1;
}
开发者ID:CommunicoPublic,项目名称:iris,代码行数:31,代码来源:MainProcess.cpp


示例5: UnixSetup

//
// Switch to unprivileged user
//
static INT_32 UnixSetup(const WorkerConfig  & oWorkerConfig,
                        ASLogger            & oLogger)
{
	// Set proper UID/GID
	if (getuid() == 0)
	{
		oLogger.Info("Switching to user/group %d:%d", oWorkerConfig.gid, oWorkerConfig.uid);
		if (oWorkerConfig.uid == 0)
		{
			oLogger.Emerg("CAS FastCGI server won't work from superuser account (root).");
			return EX_SOFTWARE;
		}
		else
		{
			// Set additional groups
			if (!oWorkerConfig.gids.empty())
			{
				const size_t iGroups = oWorkerConfig.gids.size();
				gid_t * aGids        = new gid_t[iGroups];
				for(UINT_32 iPos = 0; iPos < iGroups; ++iPos) { aGids[iPos] = oWorkerConfig.gids[iPos]; }

				if (setgroups(oWorkerConfig.gids.size(), aGids) == -1)
				{
					STLW::string sGroups;

					for(UINT_32 iPos = 0; iPos < iGroups; ++iPos)
					{
						CHAR_8 szGroup[64];
						snprintf(szGroup, 63, "%llu ", (long long unsigned)aGids[iPos]);
						sGroups.append(szGroup);
					}
					delete [] aGids;

					const INT_32 iErrNo = errno;
					oLogger.Emerg("Can't set additional groups %s: %s error code %d", sGroups.c_str(), strerror(iErrNo), iErrNo);
					return EX_SOFTWARE;
				}
				delete [] aGids;
			}

			if (setgid(oWorkerConfig.gid) == -1)
			{
				const INT_32 iErrNo = errno;
				oLogger.Emerg("Can't set group id to %d: %s error code %d", INT_32(oWorkerConfig.gid), strerror(iErrNo), iErrNo);
				return EX_SOFTWARE;
			}

			if (setuid(oWorkerConfig.uid)  == -1)
			{
				const INT_32 iErrNo = errno;
				oLogger.Emerg("Can't set user id to %d: %s, error code %d", INT_32(oWorkerConfig.uid), strerror(iErrNo), iErrNo);
				return EX_SOFTWARE;
			}
		}
	}
	oLogger.Info("Switching to unprivileged user completed");

return EX_OK;
}
开发者ID:CommunicoPublic,项目名称:cas,代码行数:62,代码来源:FastCGIMain.cpp


示例6: GetBaseDir

static STLW::string GetBaseDir(const STLW::string & szTemplateName, STLW::string & sNormalizedFileName)
{
	STLW::string sResult;
	CHAR_8      szPath[MAX_PATH];
	CHAR_P      szFile = NULL;
	DWORD       dwLen  = ::GetFullPathNameA(szTemplateName.c_str(), MAX_PATH, szPath, &szFile);

	if (szFile == NULL) { return ""; }

	sNormalizedFileName.assign(szPath, dwLen);
	sResult.assign(szPath, szFile);

return sResult;
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:14,代码来源:CTPP2FileSourceLoader.cpp


示例7: Handler

//
// Handler
//
INT_32 FnHTMLEscape::Handler(CDT            * aArguments,
                             const UINT_32    iArgNum,
                             CDT            & oCDTRetVal,
                             Logger         & oLogger)
{
	if (iArgNum < 1)
	{
		oLogger.Emerg("Usage: HTMLESCAPE(a[, b, ...])");
		return -1;
	}

	STLW::string sResult;
	for(INT_32 iPos = iArgNum - 1; iPos >=0; --iPos) { sResult.append(aArguments[iPos].GetString()); }

	oCDTRetVal = HTMLEscape(sResult);

return 0;
}
开发者ID:Azq2,项目名称:ctpp2,代码行数:21,代码来源:FnHTMLEscape.cpp


示例8: main

int main(void)
{

	CDT oArgs;
	oArgs.PushBack(101.5);
	oArgs.PushBack(101.4);

	STLW::string sResult;
	FormatString("_%0.2f_", sResult, oArgs);

	fwrite(sResult.c_str(), sResult.size(), 1, stdout);

	// make valgrind happy
	fclose(stdin);
	fclose(stdout);
	fclose(stderr);

return EX_OK;
}
开发者ID:Azq2,项目名称:ctpp2,代码行数:19,代码来源:CTPP2DTOA.cpp


示例9: 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;
}
开发者ID:CommunicoPublic,项目名称:iris,代码行数:19,代码来源:ConfigFileParserTest.cpp


示例10: 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);
	}
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:46,代码来源:CTPP2Sprintf.cpp


示例11: Handler

//
// Handler
//
INT_32 FnJSONEscape::Handler(CDT            * aArguments,
                             const UINT_32    iArgNum,
                             CDT            & oCDTRetVal,
                             Logger         & oLogger)
{
	if (iArgNum < 1)
	{
		oLogger.Emerg("Usage: JSONESCAPE(a[, b, ...])");
		return -1;
	}

	STLW::string sResult;
	for(INT_32 iPos = iArgNum - 1; iPos >=0; --iPos)
	{
		switch (aArguments[iPos].GetType())
		{
			case CDT::UNDEF:
				sResult.append("null", 4);
				break;

			case CDT::INT_VAL:
			case CDT::REAL_VAL:
			case CDT::POINTER_VAL:
			case CDT::STRING_INT_VAL:
			case CDT::STRING_REAL_VAL:
				sResult.append(aArguments[iPos].GetString());
				break;

			case CDT::STRING_VAL:
				sResult.append(EscapeJSONString(aArguments[iPos].GetString(), true, false));
				break;

			default:
				oLogger.Emerg("Invalid type %s", aArguments[iPos].PrintableType());
				return -1;
		}
	}
	oCDTRetVal = sResult;
return 0;
}
开发者ID:Azq2,项目名称:ctpp2,代码行数:43,代码来源:FnJSONEscape.cpp


示例12: sTMP

static STLW::string GetBaseDir(const STLW::string & szTemplateName, STLW::string & sNormalizedFileName)
{
	if (szTemplateName.length() == 0) { return ""; }

	STLW::vector<STLW::string> vCurrentDir;

	CCHAR_P sBegin = szTemplateName.c_str();
	CCHAR_P szEnd  = szTemplateName.c_str() + szTemplateName.length();

	CCHAR_P sIter = sBegin;
	while (sIter != szEnd)
	{
		if (*sIter == '/')
		{
			if (sIter != sBegin)
			{
				STLW::string sTMP(sBegin, sIter);

				if      (sTMP == "/." || sTMP == "/") { ;; }
				else if (sTMP == "/..")
				{
					STLW::vector<STLW::string>::iterator itEnd = vCurrentDir.end();
					if (vCurrentDir.begin() == itEnd) { return ""; }
					vCurrentDir.erase(--itEnd);
				}
				else
				{
					vCurrentDir.push_back(sTMP);
				}
			}
			sBegin = sIter;
		}
		++sIter;
	}

	STLW::string sTMP(sBegin, sIter);
	if (sTMP == "/") { return ""; }

	STLW::string sResult;
	for (UINT_32 iI = 0; iI < vCurrentDir.size(); ++iI) { sResult.append(vCurrentDir[iI]); }

	sNormalizedFileName.assign(sResult);
	sNormalizedFileName.append(sTMP);

	sResult.append("/");

return sResult;
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:48,代码来源:CTPP2FileSourceLoader.cpp


示例13: FmtString

//
// String
//
static void FmtString(StringBuffer   & oBuffer,
                      const CDT      & oCurrentArgument,
                      const UINT_32    iFmtFlags,
                      const INT_32     iWidth,
                      const INT_32     iMaxChars,
                      CHAR_8           chPadSymbol)
{
	const STLW::string sTMP    = oCurrentArgument.GetString();

	INT_32 iFormatSize = sTMP.size();
	if (iFormatSize > iMaxChars && iMaxChars > 0) { iFormatSize = iMaxChars; }

	if (iFmtFlags & F_LEFT_ALIGN)
	{
		oBuffer.Append(sTMP.data(), iFormatSize);
		if (iWidth > iFormatSize) { oBuffer.Append(iWidth - iFormatSize, chPadSymbol); }
	}
	else
	{
		if (iWidth > iFormatSize) { oBuffer.Append(iWidth - iFormatSize, chPadSymbol); }
		oBuffer.Append(sTMP.data(), iFormatSize);
	}
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:26,代码来源:CTPP2Sprintf.cpp


示例14: IterateString

static void IterateString(FILE * F, CCHAR_P szData, UINT_64 iDataLen, STLW::string & sResultString)
{
	STLW::string::iterator itsResultString = sResultString.begin();
	for(;;)
	{
		UINT_32 iUCS = 0;
		const INT_64 iCharLen = Unicode::UTF8ToWide(szData, iDataLen, iUCS);
		if (iCharLen <= 0) { break; }

		Unicode::WideToUTF8(iUCS, itsResultString);

		iDataLen -= iCharLen;
		fprintf(F, "0x%X ", iUCS);
	}
	fprintf(F, "\n");
}
开发者ID:CommunicoPublic,项目名称:iris,代码行数:16,代码来源:UnicodeTest.cpp


示例15: sError

//
// Load template with specified name
//
INT_32 CTPP2FileSourceLoader::LoadTemplate(CCHAR_P szTemplateName)
{
	sNormalizedFileName.erase();
	INT_32 iStatCode = 0;
	STLW::vector<STLW::string>::const_iterator itvIncludeDirs = vIncludeDirs.begin();
	while(itvIncludeDirs != vIncludeDirs.end())
	{
		STLW::string sTMP = *itvIncludeDirs;
#ifdef WIN32
		if ( sTMP.length() && sTMP[sTMP.length() - 1] != '/' && sTMP[sTMP.length() - 1] != '\\' ) { sTMP.append("\\", 1); }
#else
		if (sTMP.length() && sTMP[sTMP.length() - 1] != '/') { sTMP.append("/", 1); }
#endif
		sTMP.append(szTemplateName);

		sCurrentDir = GetBaseDir(sTMP, sNormalizedFileName);
		if (sNormalizedFileName.length() == 0)
		{
			STLW::string sError("invalid file name `");
			sError.append(sTMP);
			sError.append("`");
			throw CTPPLogicError(sError.c_str());
		}

		// Get file size
		struct stat oStat;
		iStatCode = stat(sNormalizedFileName.c_str(), &oStat);
		if (iStatCode == 0)
		{
			iTemplateSize = oStat.st_size;
			break;
		}
		++itvIncludeDirs;
	}

	if (iStatCode == -1)
	{
		STLW::string sError("cannot find file in include directories ");
		itvIncludeDirs = vIncludeDirs.begin();
		for (;;)
		{
			sError.append("`");
			if (itvIncludeDirs -> size() != 0) { sError.append(*itvIncludeDirs); }
			else
			{
				CHAR_P szPWD = getcwd(NULL, 0);
				sError.append(szPWD);
				free(szPWD);
			}
			sError.append("`");

			++itvIncludeDirs;
			if (itvIncludeDirs == vIncludeDirs.end()) { break; }

			sError.append(", ");
		}
		throw CTPPLogicError(sError.c_str());
	}

	if (iTemplateSize == 0)
	{
		STLW::string sError("empty file `");
		sError.append(sNormalizedFileName);
		sError.append("` found");
		throw CTPPLogicError(sError.c_str());
	}

	// Load file
	FILE * F = fopen(sNormalizedFileName.c_str(), "rb");
	if (F == NULL) { throw CTPPUnixException("fopen", errno); }

	if (sTemplate != NULL) { free(sTemplate); }

	// Allocate memory
	sTemplate = (CHAR_P)malloc(iTemplateSize);

	// Read from file
	if (fread(sTemplate, iTemplateSize, 1, F) != 1)
	{
		if (ferror(F) != 0)
		{
			free(sTemplate);
			fclose(F);
			throw CTPPUnixException("fread", errno);
		}
		else
		{
			free(sTemplate);
			fclose(F);
			throw CTPPLogicError("Cannot read from file");
		}
	}

	fclose(F);

return 0;
}
开发者ID:androidsoft,项目名称:kiwix_mirror,代码行数:100,代码来源:CTPP2FileSourceLoader.cpp


示例16: InitModule

//
// Initialize module
//
INT_32 FileLogger::InitModule(IRIS::GlobalContext    & oGlobalContext,
                              const IRIS::VariantNC  & oConfig,
                              IRIS::SignalHandler    & oSigHandler,
                              IRIS::Logger           & oLogger)
{
	using namespace IRIS;

	// Re-open log files
	oSigHandler.RegisterHandler(SIGHUP,  &oLoggerSignalHandler);
	oSigHandler.RegisterHandler(SIGUSR1, &oLoggerSignalHandler);
	oSigHandler.RegisterHandler(SIGUSR2, &oLoggerSignalHandler);

	STLW::string sTMP = oConfig["LogLevel"].Str();

	static CCHAR_P  aPriorities[] = { "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", NULL };
	static LogPriority::LogPriorities oPriorities[] = { LogPriority::LOG_EMERG,   LogPriority::LOG_ALERT,
	                                                    LogPriority::LOG_CRIT,    LogPriority::LOG_ERROR,
	                                                    LogPriority::LOG_WARNING, LogPriority::LOG_NOTICE,
	                                                    LogPriority::LOG_INFO,    LogPriority::LOG_DEBUG };

	oActualPriority = oBasePriority = LogPriority::LOG_DEBUG;
	CCHAR_P      * aPriority = aPriorities;
	IRIS::LogPriority::LogPriorities  * oPriority = oPriorities;
	while (*aPriority != NULL)
	{
		if (Unicode::CompareIgnoreCase(sTMP.data(), sTMP.size(), *aPriority, strlen(*aPriority)) == 0)
		{
			oActualPriority = oBasePriority = *oPriority;
			break;
		}
		++aPriority;
		++oPriority;
	}

	iErrorLogBufferSize = iCustomLogBufferSize = -1;

	sErrorLogFormat.assign(oConfig["ErrorLogFormat"]);
	if (sErrorLogFormat.empty())
	{
		oLogger.Emerg("Configuration is broken: parameter %s/%s/ErrorLogFormat not set", GetObjectType(), GetObjectName());
		return -1;
	}

	sErrorLogFile.assign(oConfig["ErrorLog"]);
	if (sErrorLogFile.empty())
	{
		oLogger.Emerg("Configuration is broken: parameter %s/%s/ErrorLog not set", GetObjectType(), GetObjectName());
		return -1;
	}

	sCustomLogFormat.assign(oConfig["CustomLogFormat"]);
	if (sCustomLogFormat.empty())
	{
		oLogger.Emerg("Configuration is broken: parameter %s/%s/CustomLogFormat not set", GetObjectType(), GetObjectName());
		return -1;
	}

	sCustomLogFile.assign(oConfig["CustomLog"]);
	if (sCustomLogFile.empty())
	{
		oLogger.Emerg("Configuration is broken: parameter `%s/%s/CustomLog` not set", GetObjectType(), GetObjectName());
		return -1;
	}

	// Error log permissions
	char * pEnd = NULL;
	iErrorLogPerms = strtol(oConfig["ErrorLogPerms"].Str().c_str(), &pEnd, 8);
	if (iErrorLogPerms == 0) { oLogger.Info("Parameter `%s/%s/ErrorLogPerms` not set", GetObjectType(), GetObjectName()); }

	// User and group
	ConfigHelper::State oConfRC = ConfigHelper::ParseUserGroup(oConfig["ErrorLogOwner"],
	                                                           sErrorLogUser,
	                                                           iErrorLogUID,
	                                                           sErrorLogGroup,
	                                                           iErrorLogGID);
	switch(oConfRC)
	{
		case ConfigHelper::NOT_NEED:
			oLogger.Info("Parameter `%s/%s/ErrorLogOwner` is useful only if Iris starting from root user", GetObjectType(), GetObjectName());
			break;

		case ConfigHelper::CONFIG_ERROR:
			oLogger.Info("Parameter `%s/%s/ErrorLogOwner` not set", GetObjectType(), GetObjectName());
			break;

		case ConfigHelper::NO_SUCH_USER:
			oLogger.Emerg("Parameter `%s/%s/ErrorLogOwner`: no such user: `%s`", GetObjectType(), GetObjectName(), sErrorLogUser.c_str());
			return -1;

		case ConfigHelper::NO_SUCH_GROUP:
			oLogger.Emerg("Parameter `%s/%s/ErrorLogOwner`: no such group: `%s`", GetObjectType(), GetObjectName(), sErrorLogGroup.c_str());
			return -1;
		default:
			;;
	}

	// Buffer size for error log
//.........这里部分代码省略.........
开发者ID:CommunicoPublic,项目名称:iris,代码行数:101,代码来源:IrisFileLogger.cpp


示例17: output_collector

void CTPP2::output(zval *out, Bytecode *bytecode, const char *src_enc, const char *dst_enc) {
    unsigned int IP = 0;

    if (!bytecode || !bytecode->check()) {
        error = CTPPError("", "Invalid Bytecode", CTPP_VM_ERROR | STL_UNKNOWN_ERROR, 0, 0, IP);
    } else {
        try {
            if (charset.convert || (src_enc && dst_enc)) {
                STLW::string src_charset, dst_charset;
                if (src_enc && dst_enc) {
                    src_charset = STLW::string(src_enc);
                    dst_charset = STLW::string(dst_enc);
                } else {
                    src_charset = charset.src;
                    dst_charset = charset.dst;
                }

                STLW::string result;
                CTPPPerlLogger logger;
                StringIconvOutputCollector output_collector(result, src_charset, dst_charset, 3);
                vm->Init(bytecode->getCode(), &output_collector, &logger);
                vm->Run(bytecode->getCode(), &output_collector, IP, *params, &logger);
                vm->Reset();

                ZVAL_STRINGL(out, result.data(), result.length());
                return;
            } else {
                CTPPPerlLogger logger;
                if (out) {
                    //	STLW::string result;
                    //	StringOutputCollector output_collector(result);
                    //	vm->Init(bytecode->getCode(), &output_collector, &logger);
                    //	vm->Run(bytecode->getCode(), &output_collector, IP, *params, &logger);
                    //	ZVAL_STRINGL(out, result.data(), result.length());

                    CTPPPHPVarOutputCollector output_collector(out);
                    vm->Init(bytecode->mem, &output_collector, &logger);
                    vm->Run(bytecode->mem, &output_collector, IP, *params, &logger);
                } else {
                    CTPPPHPOutputCollector output_collector;
                    vm->Init(bytecode->mem, &output_collector, &logger);
                    vm->Run(bytecode->mem, &output_collector, IP, *params, &logger);
                }
                vm->Reset();
                return;
            }
        } catch (ZeroDivision &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_ZERO_DIVISION_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (ExecutionLimitReached &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_EXECUTION_LIMIT_REACHED_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (CodeSegmentOverrun &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_CODE_SEGMENT_OVERRUN_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (InvalidSyscall &e) {
            if (e.GetIP() != 0) {
                error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_INVALID_SYSCALL_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                                  VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
            } else {
                error = CTPPError(e.GetSourceName(), STLW::string("Unsupported syscall: \"") + e.what() + "\"", CTPP_VM_ERROR | CTPP_INVALID_SYSCALL_ERROR,
                                  VMDebugInfo(e.GetDebugInfo()).GetLine(), VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
            }
        } catch (IllegalOpcode &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_ILLEGAL_OPCODE_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (StackOverflow &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_STACK_OVERFLOW_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (StackUnderflow &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_STACK_UNDERFLOW_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (VMException &e) {
            error = CTPPError(e.GetSourceName(), e.what(), CTPP_VM_ERROR | CTPP_VM_GENERIC_ERROR, VMDebugInfo(e.GetDebugInfo()).GetLine(),
                              VMDebugInfo(e.GetDebugInfo()).GetLinePos(), e.GetIP());
        } catch (CTPPUnixException &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_UNIX_ERROR, 0, 0, IP);
        } catch (CDTRangeException &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_RANGE_ERROR, 0, 0, IP);
        } catch (CDTAccessException &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_ACCESS_ERROR, 0, 0, IP);
        } catch (CDTTypeCastException &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_TYPE_CAST_ERROR, 0, 0, IP);
        } catch (CTPPLogicError &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_LOGIC_ERROR, 0, 0, IP);
        } catch(CTPPCharsetRecodeException &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_CHARSET_RECODE_ERROR, 0, 0, 0);
        } catch (CTPPException &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | CTPP_UNKNOWN_ERROR, 0, 0, IP);
        } catch (STLW::exception &e) {
            error = CTPPError("", e.what(), CTPP_VM_ERROR | STL_UNKNOWN_ERROR, 0, 0, IP);
        } catch (...) {
            error = CTPPError("", "Unknown Error", CTPP_VM_ERROR | STL_UNKNOWN_ERROR, 0, 0, IP);
        }
    }
    vm->Reset();

    if (error.line > 0) {
        php_error(E_WARNING, "CTPP2::output(): %s (error code 0x%08X); IP: 0x%08X, file %s line %d pos %d", error.error_descr.c_str(),
                  error.error_code, error.ip, error.template_name.c_str(), error.line, error.pos);
//.........这里部分代码省略.........
开发者ID:Azq2,项目名称:php-ctpp2,代码行数:101,代码来源:ctpp2.cpp


示例18: main

int main(int argc, char ** argv)
{
	STLW::string  sGlobalConfigFile;
	STLW::string  sConfigFile;
	STLW::string  sModuleName;
	bool  bPrintHelp        = false;
	bool  bPrintVersion     = false;
	bool  bPrintCompileInfo = false;
	bool  bDaemonize        = true;
	bool  bDebugInfo        = false;

	initproctitle(argc, argv);

	// Read and parse command-line options
	INT_32 iRC = GetParams(argc, argv, sGlobalConfigFile, sConfigFile, sModuleName, bDebugInfo, bPrintHelp, bPrintVersion, bPrintCompileInfo, bDaemonize);
	if (iRC != EX_OK) { Usage(argv[0]); return EX_USAGE; }

	// Just print help and exit
	if (bPrintHelp) { Help(argv[0]); return EX_OK; }

	// Print version
	if (bPrintVersion) { Version(); return EX_OK; }

	// Print compiler settings
	if (bPrintCompileInfo) { CompileInfo(); return EX_OK; }

	FILE * F = fopen(sConfigFile.c_str(), "rb");
	if (F == NULL) { fprintf(stderr, "ERROR: Cannot open `%s` for reading: %s\n", sConfigFile.c_str(), strerror(errno)); return EX_SOFTWARE; }

	WorkerConfig oWorkerConfig;
	oWorkerConfig.global_config_file = sGlobalConfigFile;
	oWorkerConfig.procname           = argv[0];
	oWorkerConfig.debug              = bDebugInfo;
	oWorkerConfig.foreground         = !bDaemonize;
	try
	{
		ConfigHandler oConfigHandler(oWorkerConfig);
		ASXMLParser oParser(&oConfigHandler);
		if (oParser.ParseFile(F) == -1)
		{
			fprintf(stderr, "ERROR: In file %s: %s\n", sConfigFile.c_str(), oConfigHandler.GetError().c_str());
			return EX_CONFIG;
		}
		fclose(F);
	}
	catch(STLW::exception &e) { fprintf(stderr, "ERROR: %s\n", e.what()); return EX_SOFTWARE; }
	catch(...)                { fprintf(stderr, "ERROR: Ouch!\n"); return EX_SOFTWARE; }

	if (GetSystemUserData(oWorkerConfig) != EX_OK) { return EX_SOFTWARE; }

	if (oWorkerConfig.global_config_file.empty())
	{
		oWorkerConfig.global_config_file = CAS_GLOBAL_CONFIG_FILE;
		fprintf(stderr, "Global config not given, using %s as DEFAULT\n", CAS_GLOBAL_CONFIG_FILE);
	}

	MainProcess oMainProcess(oWorkerConfig);

	ASLoggerFile oLogger(stderr);
	if (bDaemonize)
	{
		if (Daemonize(oWorkerConfig.pid_file.c_str(), oLogger) != EX_OK) { return EX_SOFTWARE; }
	}
	if (UnixSetup(oWorkerConfig, oLogger) != EX_OK) { return EX_SOFTWARE; }

	try
	{
		if (oMainProcess.Setup() == -1)
		{
			fprintf(stderr, "Can't start FastCGI server: %s; config file %s\n", strerror(errno), sConfigFile.c_str());
			return EX_SOFTWARE;
		}
	}
	catch(STLW::exception &e) { fprintf(stderr, "ERROR: %s\n", e.what()); return EX_SOFTWARE; }
	catch(...)                { fprintf(stderr, "ERROR: Ouch!\n"); return EX_SOFTWARE; }

return oMainProcess.Run();
}
开发者ID:CommunicoPublic,项目名称:cas,代码行数:78,代码来源:FastCGIMain.cpp


示例19: oMutexLocker

//
// Write message to log file
//
IRIS::Logger::State ParametrizedLogger::ParametrizedLogger::WriteLog(const IRIS::LogPriority::LogPriorities  ePriority,
                                                                     CCHAR_P                                 szString,
                                                                     const UINT_32                           iStringLen)
{
	using namespace IRIS;
	MutexLocker oMutexLocker(oMutex);
/*
	# $timegm.unix      - current GMT unixtime, seconds
	# $timegm.ascii     - current GMT time, ascii representation [Wkd Mmm DD HH:MM:SS YYYY]
	# $time.unix        - current LOCAL unixtime, seconds
	# $time.ascii       - current LOCAL time, ascii representation
*/
	SystemVars::Time oTimeGM = SystemVars::GetTime();

	IRIS::DataBuffer & oDataBuffer = oLogWriter;

	struct tm oLocalTime;
	time_t iTime = oTimeGM.sec;
	localtime_r(&iTime, &oLocalTime);

	STLW::string::const_iterator itsLogFormat = sLogFormat.begin();
	STLW::stringstream sStream;
	for (;;)
	{
		STLW::string::const_iterator itsTMP = itsLogFormat;
		while(itsLogFormat != sLogFormat.end() && *itsLogFormat != '$') { ++itsLogFormat; }
		sStream << STLW::string(itsTMP, itsLogFormat);

		if (itsLogFormat == sLogFormat.end()) { break; }

		itsTMP = itsLogFormat++;
		while(itsLogFormat != sLogFormat.end())
		{
			const CHAR_8 chTMP = *itsLogFormat;
			if (!((chTMP >= 'a' && chTMP <= 'z') ||
			      (chTMP >= 'A' && chTMP <= 'Z') ||
			      (chTMP >= '0' && chTMP <= '9') ||
			       chTMP == '.' || chTMP == '_')) { break; }
			++itsLogFormat;
		}

		const STLW::string sParam(++itsTMP, itsLogFormat);
		if      (sParam == "message.str")  { sStream << STLW::string(szString, iStringLen); }
		else if (sParam == "timegm.unix")  { sStream << oTimeGM.sec << '.' << oTimeGM.nsec; }
		else if (sParam == "time.unix")
		{
#if defined(sun) || defined(_AIX)
			sStream << oTimeGM.sec + GetGMTOff(iTime, oLocalTime) << '.' << oTimeGM.nsec;
#else
			sStream << oTimeGM.sec + oLocalTime.tm_gmtoff << '.' << oTimeGM.nsec;
#endif
		}
		else if (sParam == "timegm.ascii") { sStream << FormatDate(oTimeGM.sec); }
		else if (sParam == "time.ascii")
		{
#if defined(sun) || defined(_AIX)
			sStream << FormatDate(oTimeGM.sec + GetGMTOff(iTime, oLocalTime));
#else
			sStream << FormatDate(oTimeGM.sec + oLocalTime.tm_gmtoff);
#endif
		}
		else if (sParam == "priority")     { sStream << LogPriority::GetPrintableState(ePriority); }
		else
		{
			if (pLoggerContext == NULL)
			{
				sStream << "-";
			}
			else
			{
				STLW::string sValue;
				pLoggerContext -> GetParam(sParam, sValue);
				sStream << sValue;
			}
		}
	}

	const STLW::string sResult = sStream.str();
	STLW::string::const_iterator itsResult = sResult.begin();
	for (;;)
	{
		STLW::string::const_iterator itsStart = itsResult;
		while (itsResult != sResult.end() && *itsResult >= ' ') { ++itsResult; }
		oDataBuffer.Append(itsStart, itsResult);
		if (itsResult == sResult.end()) { break; }

		const UCHAR_8 ucTMP = *itsResult;
		switch (ucTMP)
		{
			case '\n':
				oDataBuffer.Append("\\n");
				break;
			case '\r':
				oDataBuffer.Append("\\r");
				break;
			case '\t':
				oDataBuffer.Append("\\t");
//.........这里部分代码省略.........
开发者ID:CommunicoPublic,项目名称:iris,代码行数:101,代码来源:IrisFileLogger.cpp


示例20: oLogger

// Thread function
static void * ThreadFunction(void * pContext)
{
	ThreadContext * pThreadContext = (ThreadContext *)pContext;

	pthread_mutex_lock(&(pThreadContext -> output_mutex));
	fprintf(stderr, "Initilalizing...\n");
	pthread_mutex_unlock(&(pThreadContext -> output_mutex));

	// Create per-thread VM instance

	// Syscall factory
	SyscallFactory * pSyscallFactory = new SyscallFactory(pThreadContext -> max_handlers);
	// Init standard library
	STDLibInitializer::InitLibrary(*pSyscallFactory);
	// Virtual machine
	VM * pVM = new VM(pSyscallFactory);
	// Okay, all done with thread-specific

	// Fill data
	CDT oData;
	oData["hello"] = "Hello, World!";

	pthread_mutex_lock(&(pThreadContext -> output_mutex));
	fprintf(stderr, "Okay, ready to work\n");
	pthread_mutex_unlock(&(pThreadContext -> output_mutex));

	FileLogger oLogger(stderr);

	// Perform some work
	const VMMemoryCore * pVMMemoryCore = NULL;
	for (UINT_32 iCount = 0; iCount < MAX_ITERATIONS; ++iCount)
	{
		STLW::string sResult;
		StringOutputCollector  oDataCollector(sResult);

		// Get template, thread-safe
		pthread_mutex_lock(&(pThreadContext -> template_mutex));
		STLW::map<STLW::string, VMFileLoader *>::iterator itLoader = pThreadContext -> templates.find("hello.ct2");
		if (itLoader == pThreadContext -> templates.end())
		{
			continue;
		}

		pVMMemoryCore = itLoader -> second -> GetCore();
		pthread_mutex_unlock(&(pThreadContext -> template_mutex));

		// Run VM
		pVM -> Init(pVMMemoryCore, &oDataCollector, &oLogger);
		UINT_32 iIP = 0;
		pVM -> Run(pVMMemoryCore, &oDataCollector, iIP, oData, &oLogger);

		// All done, print results
		pthread_mutex_lock(&(pThreadContext -> output_mutex));
		fwrite(sResult.c_str(), sResult.size(), 1, stdout);
		pthread_mutex_unlock(&(pThreadContext -> output_mutex));
	}

	delete pVM;
	delete pSyscallFactory;

return NULL;
}
开发者ID:Azq2,项目名称:ctpp2,代码行数:63,代码来源:CTPP2MT.cpp



注:本文中的stlw::string类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ store::Item_t类代码示例发布时间:2022-06-01
下一篇:
C++ mesh::Entity类代码示例发布时间:2022-06-01
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap