Exemplo n.º 1
0
bool RegExp::search(const char* str, const char** outBegin, const char** outEnd, uint start)
{
	if (_peer == NULL) return false;

	bool found = sqstd_rex_search((SQRex*)_peer, str+start, outBegin, outEnd);
	return found;
}
Exemplo n.º 2
0
bool FeRomListSorter::operator()( const FeRomInfo &one_obj, const FeRomInfo &two_obj ) const
{
	const std::string &one = one_obj.get_info( m_comp );
	const std::string &two = two_obj.get_info( m_comp );

	if (( m_comp == FeRomInfo::Title ) && m_rex )
	{
		size_t one_begin( 0 ), one_len( one.size() ), two_begin( 0 ), two_len( two.size() );

		const SQChar *one_begin_ptr( NULL );
		const SQChar *one_end_ptr( NULL );
		const SQChar *two_begin_ptr( NULL );
		const SQChar *two_end_ptr( NULL );

		//
		// I couldn't get Squirrel's no capture regexp (?:) working the way I would expect it to.
		// I'm probably doing something dumb but I can't figure it out and docs seem nonexistent
		//
		// So we do this kind of backwards, instead of defining what we want to compare based on,
		// the regexp instead defines the part of the string we want to strip out up front
		//
		if ( sqstd_rex_search( m_rex, one.c_str(), &one_begin_ptr, &one_end_ptr ) == SQTrue )
		{
			one_begin = one_end_ptr - one.c_str();
			one_len -= one_begin;
		}

		if ( sqstd_rex_search( m_rex, two.c_str(), &two_begin_ptr, &two_end_ptr ) == SQTrue )
		{
			two_begin = two_end_ptr - two.c_str();
			two_len -= two_begin;
		}

		return ( one.compare( one_begin, one_len, two, two_begin, two_len ) < 0 );
	}
	else if (( m_comp == FeRomInfo::PlayedCount )
				|| ( m_comp == FeRomInfo::PlayedTime ))
	{
		return ( as_int( one ) > as_int( two ) );
	}

	if ( m_reverse )
		return ( one.compare( two ) > 0 );
	else
		return ( one.compare( two ) < 0 );
}
Exemplo n.º 3
0
static SQInteger _regexp_search( HSQUIRRELVM v ) {
	SETUP_REX( v );
	const SQChar *str, *begin, *end;
	SQInteger start = 0;
	sq_getstring( v, 2, &str );
	if ( sq_gettop( v ) > 2 ) sq_getinteger( v, 3, &start );
	if ( sqstd_rex_search( self, str + start, &begin, &end ) == SQTrue ) {
		_addrexmatch( v, str, begin, end );
		return 1;
	}
	return 0;
}
Exemplo n.º 4
0
bool RegExp::capture(const char* str, String& outResult, uint subExpIndex, uint start)
{
	if (_peer == NULL) return false;
	ASSERT_THROW(subExpIndex == 0 || subExpIndex < getSubExpCount(), EX_INVALID_RANGE);

	SQRex* rex = (SQRex*)_peer;
	bool found = sqstd_rex_search(rex, str+start, NULL, NULL);
	if (!found) return false;

	SQRexMatch match;
	sqstd_rex_getsubexp(rex, subExpIndex, &match);
	outResult.assign(match.begin, match.begin + match.len);

	return true;
}
Exemplo n.º 5
0
bool RegExp::search(const String& str, size_t* outBegin, size_t* outEnd, uint start)
{
	if (_peer == NULL) return false;

	const char *cstr, *begin, *end;

	cstr = str.c_str();
	bool found = sqstd_rex_search((SQRex*)_peer, cstr+start, &begin, &end);

	if (found)
	{
		if (outBegin) *outBegin = begin - cstr;
		if (outEnd) *outEnd = end - cstr;
	}
	return found;
}
Exemplo n.º 6
0
String RegExp::format(const char* str, const char* fmt, uint start)
{
	if (_peer == NULL) return fmt;

	String ret;

	SQRex* rex = (SQRex*)_peer;
	const char *begin, *end;
	bool found = sqstd_rex_search(rex, str+start, &begin, &end);
	if (!found) return ret;

	uint n = sqstd_rex_getsubexpcount(rex);

	for (const char* f = fmt; *f; ++f)
	{
		int ch = *f;
		if (ch != '%')
		{
			ret.push_back(ch);
			continue;
		}

		ch = *++f;

		if (ch == '*')
			ret.append(str);
		else if (ch == '<')
			ret.append(str, begin);
		else if (ch == '>')
			ret.append(end);
		else if ('0' <= ch && ch <= '9')
		{
			uint subIdx = ch - '0';
			if (subIdx < n)
			{
				SQRexMatch match;
				sqstd_rex_getsubexp(rex, subIdx, &match);
				ret.append(match.begin, match.len);
			}
			else
				NIT_THROW_FMT(EX_INVALID_PARAMS, "no subexp: %d", subIdx);
		}
		else ret.push_back(ch);
	}

	return ret;
}
Exemplo n.º 7
0
const char FeRomListSorter::get_first_letter( const FeRomInfo &one_info )
{
	const std::string &name = one_info.get_info( FeRomInfo::Title );
	if ( name.empty() )
		return '0';

	size_t b( 0 );

	if ( m_rex )
	{
		const SQChar *bp;
		const SQChar *ep;
		if ( sqstd_rex_search( m_rex, name.c_str(), &bp, &ep ) == SQTrue )
			b = ep - name.c_str();
	}

	return name.at( b );
}
Exemplo n.º 8
0
bool RegExp::captureAll(const char* str, StringVector& outResults, uint start)
{
	if (_peer == NULL) return false;

	SQRex* rex = (SQRex*)_peer;
	bool found = sqstd_rex_search(rex, str+start, NULL, NULL);
	if (!found) return false;

	SQInteger n = sqstd_rex_getsubexpcount(rex);
	for (SQInteger i=0; i < n; ++i)
	{
		SQRexMatch match;
		sqstd_rex_getsubexp(rex, i, &match);
		outResults.push_back(String());
		outResults.back().assign(match.begin, match.begin + match.len);
	}

	return true;
}
Exemplo n.º 9
0
String RegExp::substitute(const char* str, const char* replacement, uint subExpIndex, uint start)
{
	if (_peer == NULL) return str;
	ASSERT_THROW(subExpIndex == 0 || subExpIndex < getSubExpCount(), EX_INVALID_RANGE);

	String ret;

	SQRex* rex = (SQRex*)_peer;
	bool found = sqstd_rex_search(rex, str+start, NULL, NULL);
	if (!found) return str;

	SQRexMatch match;
	sqstd_rex_getsubexp(rex, subExpIndex, &match);

	ret.assign(str, match.begin);
	ret.append(replacement);
	ret.append(match.begin + match.len);

	return ret;
}
Exemplo n.º 10
0
bool RegExp::captureAll(const char* str, vector<SubExp>::type& outResults, uint start)
{
	if (_peer == NULL) return false;

	SQRex* rex = (SQRex*)_peer;
	bool found = sqstd_rex_search(rex, str+start, NULL, NULL);
	if (!found) return false;

	SQInteger n = sqstd_rex_getsubexpcount(rex);
	for (SQInteger i=0; i < n; ++i)
	{
		SQRexMatch match;
		sqstd_rex_getsubexp(rex, i, &match);
		outResults.push_back(SubExp());
		SubExp& e = outResults.back();
		e.begin = match.begin;
		e.end = match.begin + match.len;
	}

	return true;
}
Exemplo n.º 11
0
static SQInteger _regexp_capture( HSQUIRRELVM v ) {
	SETUP_REX( v );
	const SQChar *str, *begin, *end;
	SQInteger start = 0;
	sq_getstring( v, 2, &str );
	if ( sq_gettop( v ) > 2 ) sq_getinteger( v, 3, &start );
	if ( sqstd_rex_search( self, str + start, &begin, &end ) == SQTrue ) {
		SQInteger n = sqstd_rex_getsubexpcount( self );
		SQRexMatch match;
		sq_newarray( v, 0 );
		for ( SQInteger i = 0;i < n; i++ ) {
			sqstd_rex_getsubexp( self, i, &match );
			if ( match.len > 0 )
				_addrexmatch( v, str, match.begin, match.begin + match.len );
			else
				_addrexmatch( v, str, str, str ); //empty match
			sq_arrayappend( v, -2 );
		}
		return 1;
	}
	return 0;
}