Example #1
0
String MyKeyReplace(const String& raw, const String& key, const String& value) {
	int i;
	String result = raw;

	if((i = StringSearch(result, (String)"<<" + key + ">>"))	>= 0) {
		result.Remove(i, key.GetLength()+4);
		result.Insert(i, value);
	}
	return result;
}
Example #2
0
void StringMatch::setMethod(Method method) {
	isWildCard = false;
	switch(method) {
		case PARTIAL: search = StringSearch(); break;
		case EXACT: search = string(); break;
		case REGEX: search = boost::regex(); break;
		case WILDCARD: search = boost::regex(); isWildCard=true; break;
		//case TTH: search = TTHValue(); break;
		//case TTH: search = string(); break;
		case METHOD_LAST: break;
	}
	//m = method;
}
Example #3
0
int main( void )
{ 
	char stringA[50];
	char stringSearch[50];
	char* stringAPtr = stringA;
	char* stringSearchPtr = stringSearch;

	FillStringWithUserInput( stringAPtr, SENTENCE );
	FillStringWithUserInput( stringSearchPtr, WORD );

	StringSearch( stringAPtr, stringSearchPtr );

	
	return 0; //indicates successful termination

} //end main
Example #4
0
void ADLSearch::prepare(StringMap& params) {
	// Prepare quick search of substrings
	stringSearches.clear();

	// Replace parameters such as %[nick]
	string s = Util::formatParams(searchString, params, false);

	// Split into substrings
	StringTokenizer<string> st(s, ' ');
	for(auto i = st.getTokens().begin(), iend = st.getTokens().end(); i != iend; ++i) {
		if(!i->empty()) {			
			// Add substring search
			stringSearches.push_back(StringSearch(*i));
		}
	}
}
Example #5
0
int String::index( const char *searchstr, std::size_t pos ) const
/***************************************************************/
// "index" member function: find the position of C string "searchstr" in
// String "*this", starting at position "pos".
// Return -1 if the string does not occur.
// If either *this is not well-formed or searchstr is NULL, then the result is
// undefined (in this case -1).
{
    long result;

    if( __srep == NULL  ||  searchstr == NULL ) return( -1 );
    if( pos > __slength ) return( -1 );
    result = StringSearch( __srep->__value + __offset + pos,
                           __slength - pos,
                           searchstr,
                           std::strlen( searchstr ) );
    return( (int)(result < 0 ? result : result + pos ));
}
Example #6
0
void grep(char* file_name, char* str)
{
    // Проверка на корректность открытия файла
    int fd = open(file_name, O_RDONLY);
    if(fd == -1)
    {
        perror("Open file");
        exit(1);
    }

    const int size = 1;         // Размер буфера
    char* buf;                  // Буфер для считывания символов
    char* StringBuffer;         // Буфер для хранения строки
    int read_bytes;             // Число прочитанных байтов

    int StringBuffer_size = 256;
    int i = 0;

    buf = malloc(size);
    StringBuffer = malloc(StringBuffer_size);

    for(;;)
    {
        read_bytes = ReadFile(fd, buf, size);

        if( (read_bytes == 0) || (read_bytes == -1) )
            break;

        char s = buf[0];

        // Если это не символ конца строки
        if(s != '\n')
        {
            // Если буфер для хранения строки переполнен
            if(i == StringBuffer_size)
            {
                StringBuffer_size = StringBuffer_size * 2;
                StringBuffer = realloc(StringBuffer, StringBuffer_size);
                i = 0;
            }

            StringBuffer[i] = s;
            i++;
        }
        // Если это символ конца строки
        else
        {
            StringBuffer[i] = '\0';
            if(StringSearch(StringBuffer, str) == 1)
                printf("%s\n", StringBuffer);

            free(StringBuffer);
            StringBuffer = malloc(StringBuffer_size);
            i = 0;
        }
    }

    free(buf);
    free(StringBuffer);

    close(fd);
}