Exemple #1
0
void CmdMngr::registerPrefix(const char* nn)
{
	if (*nn == 0) return;
	CmdPrefix** b = findPrefix(nn);
	
	if (*b) return;
	*b = new CmdPrefix(nn, this);
}
  void declareNamespace(const std::string& given_prefix, const std::string& namespaceURI, bool attr = false)
  {
    if(findPrefix(namespaceURI) != EMPTY_STRING)
      return;

    bool remap = (attr && given_prefix.empty()) || (given_prefix == "xmlns");

    std::string prefix = !remap ? given_prefix : autoNamespacePrefix();

    prefixStack_.back()[prefix] = namespaceURI;
    uriStack_.back()[namespaceURI] = prefix;
  } // declareNamespace
Exemple #3
0
bool CmdMngr::registerCmdPrefix(Command* cc)
{
	CmdPrefix** b = findPrefix(cc->getCommand());

	if (*b)
	{
		setCmdLink(&(*b)->list, cc, false);
		cc->prefix = (*b)->name.size();
		return true;
	}
	
	return false;
}
POIImageIdentificationTable::CodeType 
POIImageIdentificationTable::
encode( uint32 poiType, const ImageName& filename ) const {
   // strip the filename into code bits and try to find it
   ImageToCodeTable::const_iterator imageIt = 
      decomposeFindFirst( poiType, filename );
   if ( imageIt == m_images.end() ) {
      // did not find it; lets fallback to poi type default image
      return findPrefix( poiType );
   }

   return imageIt->getCode();
}
POIImageIdentificationTable::ImageName 
POIImageIdentificationTable::
getFullImageName( uint32 poiType, const ImageName& shortImageName ) const {
   // search for a matching image name
   ImageToCodeTable::const_iterator it = 
      decomposeFindFirst( poiType, shortImageName );
   if ( it == m_images.end() ) {
      // no image name found; lets fallback to poi type default image
      return findPrefix( poiType );
   }

   return it->getFullImageName();
}
 string replaceWords(vector<string>& dict, string sentence) {
     buildDict(dict);
     vector<string> words = split(sentence, ' ');
     string result;
     for (size_t i = 0; i < words.size(); ++i) {
         const string& word = words[i];
         result += findPrefix(word);
         result += " ";
     }
     if (!result.empty()) {
         result.pop_back();
     }
     return result;
 }
void BogglePlayer::allPrefix(TST &lex, unsigned int minimum_word_length, set<string>* words){
	list<Vertex*> wordList;
	string s;
	for (map<int, Vertex*>:: iterator itr=g.work.begin(); itr!=g.work.end(); itr++){
		wordList.push_back(itr->second);
		pair <TST::TSTNode*, bool> p=lex.isPrefix(wordList.front()->name);

		if (p.second==false){ // if the first vertex is not a prefix, jump to next vertex;
			wordList.pop_back();
			continue;
		}
		else if (p.second==true && p.first->value!=0 && p.first->mid==nullptr){ 
			Vertex::PreInfo* pre;
			//pushInfo(wordList, p.first, true);      //push the list in to the string vector of the vertex!!!
			s.clear();
			for (list<Vertex*>::iterator itr=wordList.begin(); itr!=wordList.end(); itr++)
	        	s.append((*itr)->name);
			words->insert(s);
			wordList.pop_back();             //pop the node out; go to next available candidate
			continue;
		}
		else{
			wordList.front()->visited=true;    // indicate next vertex is pushed into the list,   
			//pushInfo(wordList, p.first, p.first->value!=0);       //p.first->value!=0 means threre is no end bit;  
			if (p.first->value!=0& wordList.front()->name.length()>= minimum_word_length){
			    s.clear();
				for (list<Vertex*>::iterator itr=wordList.begin(); itr!=wordList.end(); itr++)
	        	    s.append((*itr)->name);
				words->insert(s);
			}
		    findPrefix(wordList, int(itr->second->name.length()), lex, p.first, minimum_word_length, words);
			wordList.front()->visited=false;
			wordList.clear();
		}
	}
}
void BogglePlayer::findPrefix(list<Vertex*> &path, int pathLength, TST &lex, unsigned int minimum_word_length, set<string>* words){
	Vertex* currV;
	Vertex* nextV;
	stack<Vertex*> adjCad;
	bool found;
	string key;
	string s;
	
	if (pathLength > longestWL){
	    return;
	}

	//Push the vertexs in adj list into a candidate stack
	currV=path.back();
	for(int i=0; i < currV->adj.size(); i++){
		if (!currV->adj.at(i)->visited)
			adjCad.push(currV->adj.at(i));
	}

	while (!adjCad.empty()){
		
		nextV=adjCad.top();
		adjCad.pop();
		path.push_back(nextV);
		key= listTostring(path);
		pair <TST::TSTNode*, bool> p=lex.isPrefix(key);

		if (p.second==false){ // if the next vertex doesn't form prefix,
			path.pop_back();  //If it is not the prefix, pop it out
			continue;         // go to next availabe candidate in adj of current vertex
		}
		// Find complete word and not the prefix of other word
		else if (p.second==true && p.first->value!=0 && p.first->mid==nullptr){
			//pushInfo(path, p.first, true); //push the list in to the string vector of the vertex!!!
			if (pathLength>=minimum_word_length){
			    s.clear();
				for (list<Vertex*>::iterator itr=path.begin(); itr!=path.end(); itr++)
	        	    s.append((*itr)->name);
				words->insert(s);
			}
			path.pop_back();               //pop the node out; go to next available candidate
			continue;
		}
		//The other situations are regards as prefix situation
		//include purely prefix and prefix (but a complete word)
		else{
	        pathLength+=nextV->name.length();           // if it is prefix, update length (used in termination of searching)
			nextV->visited=true;                        // indicate next vertex is pushed into the list,
			                                            // not aviable for searching          
			//pushInfo(path, p.first, p.first->value!=0); //push the list in to the list vector of the vertex!!! 
			                                            //p.first->value!=0 means threre is no end bit;
			if (p.first->value!=0 & pathLength>=minimum_word_length){
			    s.clear();
				for (list<Vertex*>::iterator itr=path.begin(); itr!=path.end(); itr++)
	        	    s.append((*itr)->name);
				words->insert(s);
			}
            findPrefix(path, pathLength, lex,  minimum_word_length, words);

			pathLength-=nextV->name.length();           // return from findPrefix means nextV is handled
			path.pop_back();                            // pop nextV out of path list
			nextV->visited=false;                       // means the nextV is not on the list, can be search again;
		}
	}
	//all the vertexs in the adj list are handled, return;
	return;
}