Esempio n. 1
0
string trimmedName(string& s)
{
    //printf("splitting %s\n",s.c_str());
    StrVec vec;
    int n=strsplit_slash(s, vec);

    //for(int i=0;i<n;i++) printf("  '%s'\n",vec[i].c_str());

    unsigned int i=0;
    while(i<vec.size())
    {
        if(i>0)
        {
            if(vec[i]==".." && vec[i-1]!="..")
            {
                i--;
                vec.erase(vec.begin()+i,vec.begin()+i+2);
                continue;
            }
        }

        i++;
    }
    if(!vec.size()) return "";
    string ret="";
    for(unsigned int i=0; i<vec.size(); i++)
    {
        ret+=vec[i];
        if(i+1!=vec.size()) ret+="/";
    }
    return ret;
}
Esempio n. 2
0
int Http_Response_Package::prase_package(std::string package)
{
	m_line.clear();
	m_fields.clear();
	StrVec fields;
	split_string(package,fields,"\r\n");
	if (fields.size()>1)
	{
		m_line=fields[0];
	}

	for (unsigned int i=1;i<fields.size(); i++ )
	{
		int colon_pos=fields[i].find(':');
		std::string key=fields[i].substr(0,colon_pos);
		std::string value=fields[i].substr(colon_pos+1);
		value=trim_string(value," ");
		if ( m_fields.find(key)==m_fields.end() )
		{
			m_fields[key]=value;
		}
		else
		{
			m_fields[key]+=";"+value;
		}
	}
	return 0;
}
int main() {
  StrVec sv;
  print(sv);

  sv.push_back("s1"); print(sv);
  sv.push_back("s2"); print(sv);
  sv.push_back("s3"); print(sv);
  sv.push_back("s4"); print(sv);
  sv.push_back("s5"); print(sv);

  {
    StrVec sv2(sv); print(sv2);
    sv2.push_back("s6"); print(sv); print(sv2);
    sv.pop_back(); print(sv); print(sv2);
    sv = sv2; print(sv); print(sv2);
  }

  sv.reserve(sv.capacity() / 2); print(sv);
  sv.reserve(sv.capacity() * 2); print(sv);

  sv.resize(sv.size() + 2); print(sv);
  sv.resize(sv.size() + 2, "s7"); print(sv);
  sv.resize(sv.size() - 2); print(sv);
  sv.resize(sv.size() - 2, "s7"); print(sv);

  return 0;
}
Esempio n. 4
0
void cGRASS::breakDir(string Dir)
{
	StrVec Vec;
	Vec.clear();
	char dir[255];
	strcpy(dir,Dir.c_str());
	char * t;
	string temp;
	printf ("Splitting string \"%s\" into tokens:\n",dir);
	t = strtok (dir,"/");
	while (t != NULL)
	{
		temp = t;
		Vec.push_back(temp);
  		t = strtok (NULL, "/");
	}
	MapSet = Vec[Vec.size()-1];
	Location = Vec[Vec.size()-2];
	GDBase = "";
	for (uint i = 0; i < Vec.size()-2; i++)
	{
		GDBase = GDBase + "/" + Vec[i];
	}
//	printf(MapSet);
//	printf(Location);
//	printf(GDBase);
}
Esempio n. 5
0
    void Console::exec(std::string cmd)
    {
        StrVec args;

        if(cmd.find(' ') != std::string::npos)
        {
            args.push_back(cmd.substr(cmd.find(' ') + 1, cmd.size() - cmd.find(' ')));
            cmd = cmd.substr(0, cmd.find(' '));

            while(args.back().find(' ') != std::string::npos)
            {
                args.push_back(args.back().substr(args.back().find(' ') + 1 , args.size() - args.back().find(' ')));
                args.at(args.size() - 1) = args.at(args.size() - 1).substr(0, args.at(args.size() - 1).find(' ') - 1);
            }
        }

        if(commands.find(cmd) == commands.end())
        {
            addString("Command '" + cmd + "' not found");
            return;
        }

        if(!commands[cmd].exec(args)) addString("Wrong number of arguments for command '" + cmd + "'.");

    }
Esempio n. 6
0
bool operator>=(const StrVec &lhs, const StrVec &rhs)
{
	auto sz = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
	auto pl = lhs.begin(), pr = rhs.begin();
	while (sz-- && *pl == *pr)
		++pl, ++pr;
	return sz ? *pl >= *pr : pr == rhs.end();
}
Esempio n. 7
0
bool operator==(const StrVec &lhs, const StrVec &rhs)
{
	if (lhs.size() != rhs.size())
		return false;
	for (auto pl = lhs.begin(), pr = rhs.begin(); pl != lhs.end(); )
		if (*pl != *pr)
			return false;
	return true;
}
Esempio n. 8
0
 bool match(const PackInfo &other) const
 {
   if(other.dirs.size() != dirs.size()) return false;
   assert(dirs.size() == paths.size());
   assert(dirs.size() == other.paths.size());
   for(int i=0; i<dirs.size(); i++)
     if(dirs[i] != other.dirs[i] || paths[i] != other.paths[i])
       return false;
   return true;
 }
Esempio n. 9
0
bool operator< (const StrVec & s1,const StrVec &s2)
{
	for(size_t i =0 ; i< s1.size() && i < s2.size(); i++)
	{
		if(*(s1.elements+i ) < *(s2.elements+i) )
			return true ;
		else if(*(s1.elements+i ) < *(s2.elements+i) )
			return false;
	}
	if(s1.size() < s2.size())
		return true ;	
	return false;
}
Esempio n. 10
0
bool operator==(const StrVec &s1 ,const StrVec &s2)
{
	if(s1.size() == s2.size())
	{
		for(size_t i =0 ; i< s1.size() ; i++)
		{
			if(*(s1.elements+i ) != *(s2.elements+i) )
				return false ;
		}	
		return true;
	}
	return false ;
}
bool operator==(const StrVec& lhs, const StrVec& rhs)
{
    if(lhs.size() != rhs.size())
    {
        return false;
    }
    for(auto itrL=lhs.begin(), itrR=rhs.begin(); itrL!=lhs.end(), itrR!=rhs.end(); itrL++, itrR++)
    {
        if(itrL != itrR)
        {
            return false;
        }
    }
    return true;
}
Esempio n. 12
0
int main() {
    StrVec words;
    words.push_back("ss");
    words.push_back("sb");
    words.push_back("asf");
    words.push_back("safasfd");
    words.push_back("asfas");
    std::cout<<words.size()<<std::endl;
    //words = StrVec();
    //words = words;
    std::cout<<"cap "<<words.capacity()<<std::endl;
    std::cout<<"sz "<<words.size()<<std::endl;
    for_each(words.begin(), words.end(), [](const std::string &s){std::cout<<s<<std::endl;});
    std::cout<<"exit"<<std::endl;
}
Esempio n. 13
0
void CorbaNotifyUtils::getORBOptions(const std::string &appName,const std::string &orbOptions,
		int &orbArgc,ACE_TCHAR*** orbArgv)
{
	StrVec ORBOptionsVec;
	size_t ini = orbOptions.find_first_not_of(" \t");
	size_t end;

	while(ini != std::string::npos)
	{
		end = orbOptions.find_first_of(" \t", ini + 1);
		if(end != std::string::npos)
		{
			ORBOptionsVec.push_back(orbOptions.substr(ini, end - ini));
			ini = orbOptions.find_first_not_of(" \t", end);
		} else {
			ORBOptionsVec.push_back(orbOptions.substr(ini));
			ini = std::string::npos;
		}
	}

	int i = 1;
	orbArgc = ORBOptionsVec.size() + 1;
	*orbArgv = new ACE_TCHAR*[orbArgc];
	(*orbArgv)[0] = new ACE_TCHAR[appName.size() + 1];
	strncpy((*orbArgv)[0], appName.c_str(), appName.size());
	(*orbArgv)[0][appName.size()] = '\0';
	for(StrVec::const_iterator it = ORBOptionsVec.begin();
			it != ORBOptionsVec.end(); ++it, ++i)
	{
		(*orbArgv)[i] = new ACE_TCHAR[it->size() + 1];
		strncpy((*orbArgv)[i], it->c_str(), it->size());
		(*orbArgv)[i][it->size()] = '\0';
		ACE_DEBUG((LM_INFO, "%T ORB option: %s\n", (*orbArgv)[i]));
	}
}
Esempio n. 14
0
int main(int argc, char *argv[])
{
	argc--, argv++;
	if (argc == 0) {
		fprintf(stderr, "mecab_smpl filename\n");
		return 1;
	}
	try {
		const std::string fileName = argv[0];
		cybozu::Mmap mmap(fileName);
		if (mmap.size() > (1 << 30)) {
			fprintf(stderr, "file is too large %lld\n", (long long)mmap.size());
			return 1;
		}

		cybozu::nlp::Mecab mecab;
		typedef std::vector<std::string> StrVec;
		StrVec sv;
		if (mecab.parse(sv, mmap.get(), (int)mmap.size())) {
			for (size_t i = 0, n = sv.size(); i < n; i++) {
				printf("%s ", sv[i].c_str());
			}
			printf("\n");
		}
		return 0;
	} catch (std::exception& e) {
		fprintf(stderr, "exception %s\n", e.what());
	} catch (...) {
		fprintf(stderr, "unknown exception\n");
	}
	return 1;
}
Esempio n. 15
0
void print(const StrVec &sv) {
  std::cout << "<" << &sv << "> size: " << sv.size()
            << " capacity: " << sv.capacity() << " contents:";
  for (const auto &s : sv)
    std::cout << " <" << s << ">";
  std::cout << std::endl;
}
Esempio n. 16
0
bool TestPathops::process ()
{
#ifdef _MSC_VER
    const char* paths [] = {"\\kokos\\banan", "d:\\Encyclopedia\\Data\\Genomes\\E.coli.K12\\proteins\\fasta\\", "", "\\", "\\ananas\\", NULL};
#else
    const char* paths [] = {"/kokos/banan", "~/Encyclopedia/Data/Genomes/E.coli.K12/proteins/fasta/", "", "/", "/ananas/", NULL};
#endif
    const char** path = paths;
    for (; *path != NULL; path ++)
    {
        o_ << "Path " << *path << std::endl;
        StrVec comps = split_path (*path);
        o_ << "path " << *path << ", " << comps.size () << " components" << std::endl;
        StrVec::const_iterator i = comps.begin ();
        for (;i < comps.end (); i ++)
            o_ << "  '" << (*i).c_str () << "'" << std::endl;
        std::string rejoined = join_path (comps);
        o_ << "  Rejoined: " << rejoined.c_str () << std::endl;
    }

    std::string jp = join_path ("kokos", "banan", "ananas", "yabloko", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("", "kokos", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path ("kokos", NULL);
    o_ << jp.c_str () << std::endl;
    jp = join_path (NULL);
    o_ << jp.c_str () << std::endl;
    return true;
}
Esempio n. 17
0
void ParseBufVC(char* buf, const string& filter_modules, const string& filter_disabled, const string& filter_headers)
{
    static bool ignore_files=false;
    string line(buf);
    switch(BufState)
    {
    case 0: // expect filter start (set state to 1) or just a line (state =0)
    {
        if(line.find("<Filter")!=-1) BufState++;
        ProjLines.push_back(line);
        break;
    }
    case 1: // found filter, read the name and maybe start ignoring files, state++
    {
        int from=line.find("\"")+1;
        int to=line.find("\"",from);
        string name=line.substr(from,to-from);
        if(name==filter_modules || name==filter_headers || name==filter_disabled)
        {
            ProjAssoc[ProjLines.size()+4]=name;
            ignore_files=true;
        }
        BufState++;
        ProjLines.push_back(line);
        break;
    }
    case 2: // state++
    case 3: // state++
    case 4: // state++
    {
        BufState++;
        ProjLines.push_back(line);
        break;
    }
    case 5: // expect file or end of filter (back to 0, stop ignoring files)
    {
        // end of filter?
        if(line.find("</Filter>")!=-1)
        {
            BufState=0;
            ignore_files=false;
            ProjLines.push_back(line);
            break;
        }
        // file, pass
    }
    case 6: // state++
    case 7: // state++
    case 8: // state++
    {
        if(!ignore_files) ProjLines.push_back(line);
        BufState++;
        if(BufState>8) BufState=5;
        break;
    }
    default:
        ;
    }
}
Esempio n. 18
0
StrVec::StrVec(const StrVec &s)
{
	auto p = alloc.allocate(s.size());
	auto q = uninitialized_copy(s.cbegin(), s.cend(), p);
	free();
	begin_iter = p;
	end_iter = q;
	cap = q;
}
Esempio n. 19
0
int main()
{
	StrVec vec = { "aaa", "bbb", "ccc" };
	cout << vec.size() << " " << vec.capacity() << endl;
	vec.push_back("ddd");
	vec.print();
	system("pause");
	return 0;
}
Esempio n. 20
0
File: SLData.cpp Progetto: clagv/sl
 size_t Data::curIdx(bool required) const
 {
     // special case for single value - no need to call begin()
     if(1 == m_keys.size() && IdxInvalidPos == m_pos)
         return 1;
     if(!end())
         return m_pos;
     if(required)
         throw std::exception("Invalid sl::Data index");
     return IdxInvalidPos;
 }
Esempio n. 21
0
	// sort freq order
	void term(int lowerLimit = 3, double upperRateLimit = 0.98)
	{
		fprintf(stderr, "#doc=%d, #word=%d\n", docNum_, (int)df_.size());
		for (size_t i = 0, n = id2word_.size(); i < n; i++) {
			const int freq = df_[i];
			if (freq <= lowerLimit) continue;
			pv_.push_back(Pair(i, freq));
		}
		int pvNum = (int)(pv_.size() * upperRateLimit);
		fprintf(stderr, "shrink %d -> %d\n", (int)pv_.size(), pvNum);
		std::partial_sort(pv_.begin(), pv_.begin() + pvNum, pv_.end());
		pv_.resize(pvNum);
	}
Esempio n. 22
0
 void Console::update()
 {
     StrVec tmpLog = Logger::getLog();
     Logger::clearLog();
     if(!tmpLog.empty() && tmpLog.at(0) != "")
     {
         for(unsigned int i = 0; i < tmpLog.size(); i++)
         {
             while(tmpLog.at(i).find("\n") != std::string::npos)
                 tmpLog.at(i).erase(tmpLog.at(i).find("\n"), 1);
             addString(tmpLog.at(i));
         }
     }
 }
Esempio n. 23
0
	void append(const std::string& word)
	{
		std::string lower;
		cybozu::ToLower(lower, word);
		std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(lower, (int)id2word_.size()));
//printf("word=%s, id=%d, ret=%d\n", ret.first->first.c_str(), ret.first->second, ret.second);
		if (ret.second) {
			id2word_.push_back(lower);
			df_.resize(id2word_.size());
		}
		if (set_.insert(word).second) {
			df_[ret.first->second]++;
		}
	}
Esempio n. 24
0
int strsplit_slash(string& st, StrVec& vec)
{
    vec.clear();
    int last_pos=0;
    int pos=0;
    int max_pos=st.size();
    while(pos<max_pos)
    {
        last_pos=pos;
        while(st[pos]!='/' && pos<max_pos) pos++;
        vec.push_back(st.substr(last_pos,pos-last_pos));
        while(st[pos]=='/' && pos<max_pos) pos++;
    }
    return vec.size();
}
Esempio n. 25
0
int main(int argc, char const *argv[])
{
	StrVec svec1;
	std::ifstream ifs("in.txt");
	std::istream_iterator<std::string> beg(ifs), end;
	std::vector<std::string> src(beg, end);
	for (auto& s : src)
	{
		svec1.push_back(s);
	}
	svec1.resize(10, "illidan");
	StrVec svec = { "a", "b", "c", "d", "e" };
	display(svec);
	std::cout << svec.size() << std::endl;
	return 0;
}
Esempio n. 26
0
	bool loadKeywordFile(const std::string& keyFile)
	{
		std::ifstream ifs(keyFile.c_str(), std::ios::binary);
		if (!ifs) return false;
		std::string word;
		while (std::getline(ifs, word)) {
			size_t pos = word.find('\t');
			if (pos == std::string::npos) break;
			word.resize(pos);
			std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(word, (int)id2word_.size()));
			if (ret.second) {
				id2word_.push_back(word);
			} else {
				fprintf(stderr, "ERR already set %s\n", word.c_str());
			}
		}
		df_.resize(id2word_.size());
		fprintf(stderr, "#word = %d\n", (int)df_.size());
		return true;
	}
Esempio n. 27
0
void RedisClient::HDel(const std::string & hask_name, const StrVec & keys){
    if( keys.empty() ) {
        LOGE("HDEL warning : keys is empty vector");
        return ;
    }
    std::stringstream sm;
    sm << "HDEL "<< hask_name ;
    bool avaliad_param = false ;
    for( const auto & key : keys ) {
        if(key.empty()) 
            continue;
        sm<<" "<<key;
        avaliad_param = true ;

    }
    if( !avaliad_param ) {
        LOGE("HDEL warning :all key are empty string .keys has " <<keys.size());
        return ;
    }
    redisReply *redis_reply = RedoCommand(sm.str(),REDIS_REPLY_INTEGER);
    freeReplyObject_Safe(redis_reply);
}
Esempio n. 28
0
bool TestFileUtils :: process ()
{
    std::string fname = fixture_.dirname ();
    fname += path_separator ();
    fname += "*.txt";
    StrVec sv;
    expand_wildcards (fname.c_str (), sv);
    StrVec::iterator itr = sv.begin ();
    for (; itr != sv.end (); itr ++)
    {
        o_ << (*itr).c_str () << std::endl;
    }
    if (!sv.size ())
    {
        o_ << "No files to test reader" << std::endl;
        return false;
    }

    LineReader lr (sv.front ().c_str ());
    char* ln;
    int no = 0;
    int slen = 0;
    time_t st = time (NULL);
    while ((ln = lr.nextLine ()))
    {
        ++ no;
        slen += strlen (ln);
        //if (strlen (ln) > 100) o_ << ln;
        if (no % 100000 == 0)
        {
            int td = time (NULL) - st;
            double rd = double (slen) / (1024*1024);
            o_ << "\rline " << no << ", " << rd << " Mb, average speed " << rd / (td?td:1) << " Mb/s    " << std::flush;
        }
    }
    time_t et = time (NULL);
    lr.close ();
    return true;
}
Esempio n. 29
0
int main()
{
	string temp[] = {"one", "two", "three"};
	StrVec sv(temp, temp + sizeof(temp)/sizeof(*temp));

	// run the string empty funciton on the first element in sv
	if (!sv[0].empty()) 
		sv[0] = "None"; // assign a new value to the first string 

	// we'll call getVec a couple of times
	// and will read the same file each time
	ifstream in("data/storyDataFile");
	StrVec svec = getVec(in);
	print(svec);
	in.close();

	cout << "copy " << svec.size() << endl;
	StrVec svec2 = svec;
	print(svec2);

	cout << "assign" << endl;
	StrVec svec3;
	svec3 = svec2;
	print(svec3);

	StrVec v1, v2;
	v1 = v2;                   // v2 is an lvalue; copy assignment

	in.open("data/storyDataFile");
	v2 = getVec(in);          // getVec(in) is an rvalue; move assignment
	in.close();

	StrVec vec;  // empty StrVec
	string s = "some string or another";
	vec.push_back(s);      // calls push_back(const string&)
	vec.push_back("done"); // calls push_back(string&&)

	return 0;
}
Esempio n. 30
0
void MapDataLoader::parse()
{
	for (auto value : _mapVec)
	{
		if (value.first.compare("id"))
		{
			MapData data;

			StrVec vec = value.second;
			data._id = atoi(value.first.c_str());
			int lastIndex = 0;

			for (size_t i = 0; i < vec.size(); i++)
			{
				std::string value = vec.at(i);
				switch (i)
				{
				case 0: data._level = atoi(value.c_str()); break;
				case 1: data._stage = atoi(value.c_str()); break;
				case 2: data._width = atoi(value.c_str()); break;
				case 3: data._height = atoi(value.c_str()); break;
				case 4: data._bonus = stringToBonus(value); break;
				case 5: data._cheatName = value.c_str(); lastIndex = i + 1; break;
				default:
					int count = atoi(value.c_str());
					if (count != 0)
					{
						data._npcVec.push_back(std::make_pair(ID_NPC(i - lastIndex), count));
					}
					break;
				}
			}

			_maps.push_back(data);
		}
	}
}