VecString split( const char* chars, StringRef str )
{
  VecString vs;

  String::size_type n0 = 0;
  String::size_type n1 = str.find_first_of( chars, 0 );
  vs.push_back( str.substr( n0, n1 ) );

  while( n1 != String::npos )
  {
    n0 = n1+1;
    n1 = str.find_first_of( chars, n0 );
    if( n1 != String::npos ) vs.push_back( str.substr( n0, n1-n0 ) );
    else vs.push_back( str.substr( n0 ) );
  }

  return vs;
}
Beispiel #2
0
VecString BZ_StringSplit(const char* cpStr, char cFence)
{
    VecString   retValue;
    const char *cpTmp   = cpStr;
    while ('\0' != *cpStr)
    {
        if (cFence == *cpStr)
        {
            retValue.push_back(std::string(cpTmp, cpStr));
            cpTmp = cpStr;
            ++cpTmp;
        }
        ++cpStr;
    }

    retValue.push_back(std::string(cpTmp, cpStr));

    return retValue;
}
Beispiel #3
0
int RedisClient::scan( VecString& values , const int& index , const string& pattern ,
		const int& count )
{
	BuildCommand cmd("SCAN");
	string val;
	SInt64 nextNo;
	CResult arry;

	cmd << index;

	if ( !pattern.empty() )
	{
		LOG_DEBUG("PATTERN:%s", pattern.c_str());
		cmd << "MATCH" << pattern;
	}

	if ( count > 0 && count != 10 )
	{
		LOG_DEBUG("PATTERN:%s", pattern.c_str());
		cmd << "COUNT" << count;
	}

	if ( !_getArry(cmd, arry) )
		return -1;

	CResult::ListCResult arrList = arry.getArry();
	if ( arrList.size() != 2 )
		return -2;

	CResult::ListCResult::const_iterator it = arrList.begin();

	val = it->getString(); //throw TypeErr
	std::istringstream istr(val);
	istr >> nextNo;

	if ( istr.fail() )
	{
		LOG_ERROR("%s: data received is unexpected",val.c_str());
	}
	LOG_DEBUG("nextNo:%ld", nextNo);

	++it;
	CResult::ListCResult::const_iterator itKeybgein = it->getArry().begin();
	CResult::ListCResult::const_iterator itKeyend = it->getArry().end();

	values.clear();
	while ( itKeybgein != itKeyend )
	{
		val = itKeybgein->getString();
		values.push_back(val);
		itKeybgein++;
	}

	return nextNo;
}
Beispiel #4
0
/**
 * [FuzzyFilter::find find the strings that match the source string in the target]
 * @param  source  [str1]
 * @param  targets [target strings]
 * @param  f       [function that filter the strings, such as to_lower_case()]
 * @return         [vector of matched strings]
 */
FuzzyFilter::VecString FuzzyFilter::find( const String &source,
                                          const VecString &targets,
                                          String (*f)(const String &)
                                        ) const
{
	VecString matches;

	for(int i=0; i<targets.size(); i++)
	{
		if(match(f(source), f(targets[i])))
			matches.push_back(targets[i]);
	}

	return matches;
}
VecString RegKey::getSubkeyNames() const
{
  VecString v;
  DWORD i = 0;

  while(true)
  {
    DWORD len = 4096;
    char name[len];
    LONG result = RegEnumKeyEx( m_hkey, i++, name, &len, NULL, NULL, NULL, NULL );

    if( result == ERROR_NO_MORE_ITEMS )
      break;

    if( result != ERROR_SUCCESS )
      throw std::runtime_error( "error iterating keys in " + m_name );

    v.push_back( String(name, name+len) );
  }

  return v;
}