当前位置: 首页>>代码示例>>C++>>正文


C++ RegEx类代码示例

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


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

示例1: regex_replace

//native regex_replace(Regex:pattern, string[], maxLen, const replace[], flags = REGEX_FORMAT_DEFAULT, &errcode = 0);
static cell AMX_NATIVE_CALL regex_replace(AMX *amx, cell *params)
{
	int id = params[1] - 1;
	if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
		return 0;
	}

	int textLen, replaceLen;
	char *text = MF_GetAmxString(amx, params[2], 0, &textLen);
	const char *replace = MF_GetAmxString(amx, params[4], 1, &replaceLen);

	cell *erroCode = MF_GetAmxAddr(amx, params[6]);

	RegEx *x = PEL[id]; 
	int e = x->Replace(text, params[3] + 1, replace, replaceLen, params[5]);

	if (e == -1)
	{
		*erroCode = x->mErrorOffset;
		x->ClearMatch();
		return -2;
	}
	else if (e == 0)
	{
		*erroCode = 0;
		x->ClearMatch();
		return 0;
	}

	MF_SetAmxString(amx, params[2], text, params[3]);

	return e;
}
开发者ID:Chuvi-w,项目名称:amxmodx,代码行数:36,代码来源:module.cpp

示例2: OnHandleDestroy

void RegexHandler::OnHandleDestroy(HandleType_t type, void *object)
{
	RegEx *x = (RegEx *)object;

	x->Clear();
	delete x;
}
开发者ID:FlaminSarge,项目名称:sourcemod,代码行数:7,代码来源:extension.cpp

示例3: cFile

/**
*  @brief
*    Reads memory information from the '/proc/meminfo'-file
*/
bool SystemLinux::GetMemoryInformation(MemoryInformation &sMemoryInformation) const
{
	// Initialize memory information
	sMemoryInformation.nTotalPhysicalMemory	= 0;
	sMemoryInformation.nFreePhysicalMemory	= 0;
	sMemoryInformation.nTotalSwapMemory		= 0;
	sMemoryInformation.nFreeSwapMemory		= 0;

	// Parse kernel information file
	File cFile("/proc/meminfo");
	if (cFile.Open(File::FileRead | File::FileText)) {
		static RegEx cRegEx("^\\s*(MemTotal|MemFree|SwapTotal|SwapFree):\\s*(\\d+).*$");
		while (!cFile.IsEof()) {
			const String sLine = cFile.GetS();
			if (cRegEx.Match(sLine)) {
				const String sName   = cRegEx.GetResult(0);
				const String sResult = cRegEx.GetResult(1);
				if (sName == "MemTotal")
					sMemoryInformation.nTotalPhysicalMemory = sResult.GetInt() * 1024;
				if (sName == "MemFree")
					sMemoryInformation.nFreePhysicalMemory = sResult.GetInt() * 1024;
				if (sName == "SwapTotal")
					sMemoryInformation.nTotalSwapMemory = sResult.GetInt() * 1024;
				if (sName == "SwapFree")
					sMemoryInformation.nFreeSwapMemory = sResult.GetInt() * 1024;
			}
		}

		// Done
		return true;
	}

	// Error!
	return false;
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:39,代码来源:SystemLinux.cpp

示例4: CompileRegex

static cell_t CompileRegex(IPluginContext *pCtx, const cell_t *params)
{
	char *regex;
	pCtx->LocalToString(params[1], &regex);

	RegEx *x = new RegEx();
	
	if (x->Compile(regex, params[2]) == 0)
	{
		cell_t *eError;
		pCtx->LocalToPhysAddr(params[5], &eError);
		const char *err = x->mError;
		// Convert error code to posix error code but use pcre's error string since it is more detailed.
		*eError = pcre_posix_compile_error_map[x->mErrorCode];
		pCtx->StringToLocal(params[3], params[4], err ? err:"unknown");
		delete x;
		return 0;
	}

	HandleError error = HandleError_None;
	Handle_t regexHandle = g_pHandleSys->CreateHandle(g_RegexHandle, (void*)x, pCtx->GetIdentity(), myself->GetIdentity(), &error);
	if (!regexHandle || error != HandleError_None)
	{
		delete x;
		pCtx->ReportError("Allocation of regex handle failed, error code #%d", error);
		return 0;
	}
	
	return regexHandle;
}
开发者ID:FlaminSarge,项目名称:sourcemod,代码行数:30,代码来源:extension.cpp

示例5: regex_substr

// native regex_substr(Regex:id, str_id, buffer[], maxLen);
static cell AMX_NATIVE_CALL regex_substr(AMX *amx, cell *params)
{
	int id = params[1]-1;
	if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
		return 0;
	}

	RegEx *x = PEL[id];
	static char buffer[16384]; // Same as AMXX buffer.

	size_t length;
	size_t maxLength = ke::Min<size_t>(params[4], sizeof(buffer) - 1);

	const char *ret = x->GetSubstring(params[2], buffer, maxLength, &length);

	if (ret == NULL)
	{
		return 0;
	}

	if (length >= maxLength && ret[length - 1] & 1 << 7)
	{
		maxLength -= UTIL_CheckValidChar((char *)ret + length - 1);
	}

	MF_SetAmxString(amx, params[3], ret, maxLength);

	return 1;
}
开发者ID:Chuvi-w,项目名称:amxmodx,代码行数:32,代码来源:module.cpp

示例6: getUserId

UtlBoolean
ValidateMailboxCGIHelper::isNumeric( const UtlString& mailboxIdentity ) const
{
    UtlString userid ;
    getUserId( mailboxIdentity, userid ) ;

    static RegEx sAllDigits("^\\d+$");

    return sAllDigits.Search(userid.data());
}
开发者ID:mranga,项目名称:sipxecs,代码行数:10,代码来源:ValidateMailboxCGIHelper.cpp

示例7: MatchRegexAll

static cell_t MatchRegexAll(IPluginContext *pCtx, const cell_t *params)
{
	Handle_t hndl = static_cast<Handle_t>(params[1]);
	HandleError err;
	HandleSecurity sec;
	sec.pOwner = NULL;
	sec.pIdentity = myself->GetIdentity();

	RegEx *x;

	if ((err = g_pHandleSys->ReadHandle(hndl, g_RegexHandle, &sec, (void **)&x)) != HandleError_None)
	{
		return pCtx->ThrowNativeError("Invalid regex handle %x (error %d)", hndl, err);
	}

	if (!x)
	{
		pCtx->ThrowNativeError("Regex data not found\n");

		return 0;
	}

	char *str;
	pCtx->LocalToString(params[2], &str);

	int e = x->MatchAll(str);

	if (e == -1)
	{
		/* there was a match error.  move on. */
		cell_t *res;
		pCtx->LocalToPhysAddr(params[3], &res);
		*res = x->mErrorCode;
		/* only clear the match results, since the regex object
		may still be referenced later */
		x->ClearMatch();

		return -1;
	}
	else if (e == 0)
	{
		/* only clear the match results, since the regex object
		may still be referenced later */
		x->ClearMatch();

		return 0;
	}
	else
	{
		return x->mMatchCount;
	}
}
开发者ID:FlaminSarge,项目名称:sourcemod,代码行数:52,代码来源:extension.cpp

示例8: parse

String EmotHandler::parse(const StringRef& body) {
  RegEx reg;
  reg.setSubject(prepareBody(body));

  for (tPackages::iterator it = _packages.begin(); it != _packages.end(); it++) {
    parseSet(reg, (eMSet&) **it);
  }

  reg.replaceItself("#<kiev2:emot:insertion id=\"([0-9]+)\" />#", &EmotHandler::replaceEmot, 0, (void*) this);
  emotInsertions.clear();

  return prepareBody(reg.getSubject(), false);
}
开发者ID:Konnekt,项目名称:kieview2,代码行数:13,代码来源:EmotHandler.cpp

示例9: ei

void EmotHandler::parseSet(RegEx& reg, eMSet& set) {
  if (!set.isEnabled()) return;

  for (eMSet::tEmots::iterator it = set.getEmots().begin(); it != set.getEmots().end(); it++) {
    sEmotInsertion ei(emotInsertions.size(), &*it, &set);
    try {
      reg.setPattern(prepareBody(!it->isPreg() ? "/" + reg.addSlashes(it->getText()) + "/i" : it->getText(), true, false));
      reg.replaceItself(&EmotHandler::emotInsertion, 0, (void*) &ei);
    } catch (const RegEx::CompileException& e) {
      IMLOG("[EmotHandler::parseSet()] B³¹d definicji emotikony: %s, pos %i", e.error, e.pos);
      continue;
    }
    emotInsertions.push_back(ei);
  }
}
开发者ID:Konnekt,项目名称:kieview2,代码行数:15,代码来源:EmotHandler.cpp

示例10: regex_free

static cell AMX_NATIVE_CALL regex_free(AMX *amx, cell *params)
{
	cell *c = MF_GetAmxAddr(amx, params[1]);
	int id = *c;
	*c = 0;
	id -= 1;
	if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree())
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id);
		return 0;
	}

	RegEx *x = PEL[id];
	x->Clear();

	return 1;
}
开发者ID:Chuvi-w,项目名称:amxmodx,代码行数:17,代码来源:module.cpp

示例11: file

iPackage* GGParser::parse(const FindFile::Found& defFile) {
    ifstream file(defFile.getFilePath().c_str());
    string buff;

    if (!file.is_open()) {
        throw CannotOpen("Cannot open file " + defFile.getFilePath());
    }

    bool inMenu;
    eMSet result;
    RegEx reg;

    while (!file.eof()) {
        getline(file, buff);
        eMSet::tEmots emots;

        if (buff[0] == '*') {
            inMenu = false;
            buff.erase(0);
        } else {
            inMenu = true;
        }

        reg.setSubject(buff);
        reg.setPattern("/,?\"(.+?)\",?/");

        while (reg.match_global()) {
            eM emot(inMenu, reg[1][0] == '/');
            emot.setText(reg[1].c_str());
            emots.push_back(emot);

            if (reg.getSubject()[reg.getStart()] == ')' || buff[0] != '(') {
                string img_path;
                string menu_img_path;

                if (reg.match_global()) {
                    img_path = reg[1];
                    menu_img_path = reg.match_global() ? reg[1] : "";

                    for (eMSet::tEmots::iterator it = emots.begin(); it != emots.end(); it++) {
                        if (menu_img_path.length()) it->setMenuImgPath(defFile.getDirectory() + menu_img_path);
                        it->setImgPath(defFile.getDirectory() + img_path);
                    }
                } else {
                    throw WrongFormat("Brak œcie¿ki do obrazka");
                }
                break;
            }
        }
        result.getEmots().insert(result.getEmots().end(), emots.begin(), emots.end());
    }
    file.close();

    return new eMSet(result);
}
开发者ID:Konnekt,项目名称:kieview2,代码行数:55,代码来源:EmotParser.cpp

示例12: regex_compile_ex

// native Regex:regex_compile_ex(const pattern[], flags = 0, error[] = "", maxLen = 0, &errcode = 0);
static cell AMX_NATIVE_CALL regex_compile_ex(AMX *amx, cell *params)
{
	int len;
	const char *regex = MF_GetAmxString(amx, params[1], 0, &len);

	int id = GetPEL();
	RegEx *x = PEL[id];

	if (x->Compile(regex, params[2]) == 0)
	{
		const char *err = x->mError;
		*MF_GetAmxAddr(amx, params[5]) = x->mErrorOffset;
		MF_SetAmxString(amx, params[3], err ? err : "unknown", params[4]);
		return -1;
	}

	return id + 1;
}
开发者ID:Chuvi-w,项目名称:amxmodx,代码行数:19,代码来源:module.cpp

示例13: nextTargetRegEx

UtlBoolean
SubscriptionAuth::isTargetExemptedFromAuthentication(const UtlString& targetUser) const
{
   UtlBoolean targetExempted = FALSE;
   UtlSListIterator nextTargetRegEx(mTargetsExemptedFromAuthentication);

   RegEx* targetRegEx;
   
   while((targetRegEx = dynamic_cast<RegEx*>(nextTargetRegEx())))
   {
      if(targetRegEx->Search(targetUser.data()))
      {
         targetExempted = TRUE;
         break;
      }
   }

   return targetExempted;
}
开发者ID:LordGaav,项目名称:sipxecs,代码行数:19,代码来源:SubscriptionAuth.cpp

示例14: cRegEx

/**
*  @brief
*    Parse next parameter
*/
bool ParamsParser::Next()
{
	// Parse next expression
	if (m_nParsePos > -1 && m_cRegEx.Match(m_sParameters, m_nParsePos)) {
		// Get expression and new parse position
		m_nParsePos			= m_cRegEx.GetPosition();
		String sExpression	= m_cRegEx.GetResult(0);

		// Process the found expression
		if (sExpression[sExpression.GetLength()-1] == '\'') {
			static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*'?\\s*([^\']*)\\s*'?");
			if (cRegEx.Match(sExpression)) {
				// Get name and value
				m_sName  = cRegEx.GetResult(0);
				m_sValue = cRegEx.GetResult(1);
				return true;
			}
		} else {
			static RegEx cRegEx("\\s*(\\w*)\\s*=\\s*\"?\\s*([^\"]*)\\s*\"?");
			if (cRegEx.Match(sExpression)) {
				// Get name and value
				m_sName  = cRegEx.GetResult(0);
				m_sValue = cRegEx.GetResult(1);
				return true;
			}
		}
	}

	// Error, could not parse next expression
	m_sName		= "";
	m_sValue	= "";
	m_nParsePos	= -1;
	return false;
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:38,代码来源:ParamsParser.cpp

示例15: cRegEx

/**
*  @brief
*    From string
*/
bool Color3::FromString(const String &sString)
{
	if (sString.GetLength()) {
		// Parse components
		uint32 nParsePos  = 0;
		uint32 nComponent = 0;
		static RegEx cRegEx("\\s*(\\S+)");
		while (nComponent < 3 && cRegEx.Match(sString, nParsePos)) {
			fColor[nComponent++] = cRegEx.GetResult(0).GetFloat();
			nParsePos = cRegEx.GetPosition();
		}

		// Set unused components to 0
		while (nComponent < 3)
			fColor[nComponent++] = 0.0f;

		// Done
		return true;
	} else {
		// Error!
		r = g = b = 0.0f;
		return false;
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:28,代码来源:Color3.cpp


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