示例#1
0
bool CzString::SplitVarIndex(CzString& var, int& index, CzString& vindex)
{
	char* pData = Data;
	index = -1;

	FindReset();

	// Split string at colon char and return value after colon
	for (int t = 0; t < Length; t++)
	{
		if (*pData++ == ':')
		{
			var.setString(Data, t);
			vindex.Copy(pData, 0, Length - t - 1);
			if (CzString::IsNumber(*pData))
				index = vindex.getAsInt();
			return true;
		}
	}

	// No split found so just copy this string to output
	var = *this;

	return true;
}
示例#2
0
CFile *CNTFSDirectory::FindFirst(const wstring &name, int attribs)
{
	if ( !isvalid() ) return NULL;

	// Reset
	FindReset();

	CStream *rootstream = m_file.openstream(m_ir_attribnum, false);
	if ( !rootstream ) return NULL;
	NTFSindexroot *indexroot = NTFSindexroot::Read(rootstream);
	delete rootstream;
	if ( !indexroot ) return NULL;

	CBlockStream *indexnodestream = NULL;
	int blocksize = 0;

	if ( indexroot->islargeindex() )
	{
		indexnodestream = m_file.openstream(m_ia_attribnum, false);
		if ( !indexnodestream ) { free(indexroot); return NULL; }
		blocksize = indexnodestream->PhysicalBlockSize();
	}

	bool result = read(m_ntfs, indexnodestream, &indexroot->indexentries, indexroot->indexnodesize, blocksize, name, attribs);

	free(indexroot);
	if ( indexnodestream )
	{
		delete indexnodestream;
		indexnodestream = NULL;
	}

	return result ? FindNext(name, attribs) : NULL;
}
bool PhoneEmailDetector::FindContent(const string16::const_iterator& begin,
                             const string16::const_iterator& end,
                             size_t* start_pos,
                             size_t* end_pos)
{
    #define HANDLE_FOUND_RESULTS() \
            if (foundResult == FOUND_COMPLETE && \
                (m_foundResult != FOUND_COMPLETE || \
                findState.mStartResult < m_findState.mStartResult)) { \
                FindStateCopy(&m_findState, &findState); \
                m_foundResult = foundResult; \
            }

    FindReset(&m_findState);
    m_foundResult = FOUND_NONE;
    if (m_isPhoneDetectionEnabled) {
        FoundState foundResult = FOUND_NONE;
        FindState findState;

        ChinaFindReset(&findState);
        foundResult = ChinaFindPhoneNum(begin, end - begin, &findState);
        HANDLE_FOUND_RESULTS();

        FindReset(&findState);
        foundResult = FindPartialNumber(begin, end - begin, &findState);
        HANDLE_FOUND_RESULTS();
    }

    if (m_foundResult == FOUND_COMPLETE)
        m_prefix = kTelSchemaPrefix;
    else {
        FindReset(&m_findState);
        if (m_isEmailDetectionEnabled)
            m_foundResult = FindPartialEMail(begin, end - begin, &m_findState);
        m_prefix = kEmailSchemaPrefix;
    }
    *start_pos = m_findState.mStartResult;
    *end_pos = m_findState.mEndResult;
    return m_foundResult == FOUND_COMPLETE;
}
示例#4
0
bool PhoneEmailDetector::FindContent(const string16::const_iterator& begin,
                             const string16::const_iterator& end,
                             size_t* start_pos,
                             size_t* end_pos)
{
#if 0 // CAPPFIX_WEB_NUMBER_PASSING
    FindReset(&m_findState);
    m_foundResult = FOUND_NONE;
    if (m_isPhoneDetectionEnabled)
        m_foundResult = FindPartialNumber(begin, end - begin, &m_findState);
    if (m_foundResult == FOUND_COMPLETE)
        m_prefix = kTelSchemaPrefix;
    else {
        FindReset(&m_findState);
        if (m_isEmailDetectionEnabled)
            m_foundResult = FindPartialEMail(begin, end - begin, &m_findState);
        m_prefix = kEmailSchemaPrefix;
    }
#else
    FindReset(&m_findState);
    m_foundResult = FOUND_NONE;
    if (m_isEmailDetectionEnabled)
        m_foundResult = FindPartialEMail(begin, end - begin, &m_findState);
    if (m_foundResult == FOUND_COMPLETE)
        m_prefix = kEmailSchemaPrefix;
    else {
        FindReset(&m_findState);
        if (m_isPhoneDetectionEnabled)
            m_foundResult = FindPartialNumber(begin, end - begin, &m_findState);
        m_prefix = kTelSchemaPrefix;
    }
#endif // CAPPFIX_WEB_NUMBER_PASSING_END
    *start_pos = m_findState.mStartResult;
    *end_pos = m_findState.mEndResult;
    return m_foundResult == FOUND_COMPLETE;
}
示例#5
0
void CzString::Split(char split_char, CzSlotArray<CzString*>* strings)
{
	char* pData = Data;

	FindReset();
	strings->clear();
	int start = 0, len = 0;
	for (int t = 0; t < Length + 1; t++)
	{
		char c = *pData++;
		if (c == split_char || c == 0)
		{
			CzString* s = new CzString();
			s->setString(Data + start, t - start);
			start = t + 1;
			strings->add(s);
		}
	}
}
示例#6
0
bool CzString::SplitPropVarIndex(CzString& prop, CzString& var, int& index, CzString& vindex)
{
	char* pData = Data;
	index = -1;

	FindReset();

	// Get property
	int pos = StepFindIndexNoneWhiteSpace();
	if (pos < 0)
		return false;
	int start_pos = 0;
	int len = GetNextMarkedString('[', ']', start_pos);
	if (len >= 0)
		prop.setString(Data + start_pos, len);
	if (StepFindIndex(1) == Length)
		return false;

	// Split string at colon char and return value after colon
	pData += FindIndex;
	for (int t = 0; t < Length - FindIndex; t++)
	{
		if (*pData++ == ':')
		{
			var.setString(Data + FindIndex, t);
			vindex.Copy(pData, 0, Length - t - 1);
			if (CzString::IsNumber(*pData))
				index = vindex.getAsInt();

			return true;
		}
	}

	// No split found so just copy out the var
	var.setString(Data + FindIndex, Length - FindIndex);

	return true;
}
示例#7
0
int CzString::Replace(const char* string, const char* with)
{
	int len = strlen(string);
	int wlen = strlen(with);

	// Find the string
	FindReset();

	// Count how many times the string occurs
	int occcurances = 0;
	int pos = 0;
	do
	{
		pos = FindNext(string, len);
		FindIndex = pos + len;
		if (pos >= 0)
			occcurances++;
	}
	while (pos >= 0);
	if (occcurances == 0)
		return -1;

	// Calculate new string size
	int new_size = Length - len * occcurances + wlen * occcurances;
	char* new_buffer = alloc(new_size + 1);

	// Build new string with replacements
	FindReset();
	int start_pos = 0, buff_pos = 0;
	pos = 0;
	do
	{
		pos = FindNext(string, len);
		FindIndex = pos + len;
		if (pos < 0)
		{
			// Copy any remaining string
			memcpy(new_buffer + buff_pos, Data + start_pos, Length - start_pos);
			buff_pos += Length - start_pos;
			break;
		}

		// Copy string that doesnt match
		int plen = pos - start_pos;
		memcpy(new_buffer + buff_pos, Data + start_pos, plen);
		buff_pos += plen;

		// Copy replacement
		memcpy(new_buffer + buff_pos, with, wlen);
		buff_pos += wlen;

		start_pos = FindIndex;
	}
	while (pos >= 0);

	new_buffer[buff_pos] = 0;
	free(Data);
	Data = new_buffer;
	Length = new_size;
	Size = new_size + 1;

	if (AutoHash)
		DataHash = CzString::CalculateHash(Data);

	return pos;
}