bool is_end(string str){
     transform(str.begin(),str.end(), str.begin(), ::toupper);
     if(str == "END")
            return true;
     return false;
}
Example #2
0
// This function looks at the hostname extracted from the url, and decides if we want to resolve the
// ip address explicitly or not, e.g., we do not attempt to resolve a hostname if it is already an ip address
// (which is actually the case when UA is run from within a job in DNAnexus)
// Note: The regexp for IP address we use is quite lenient, and matches some non-valid ips, but that's
//       fine for our purpose here, since:
//       1) Not resolving a hostname explicitly does not break anything (but the opposite can be dangerous),
//       2) The input received by this function is not arbitrary but rather something decided by apiserver
//          (i.e., output of /file-xxxx/upload call), so we know what to expect.
static bool attemptExplicitDNSResolve(const string &host) {
  static const boost::regex expression("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$", boost::regex::perl);
  boost::match_results<string::const_iterator> what;
  return !boost::regex_search(host.begin(), host.end(), what, expression, boost::match_default);
}
Example #3
0
void Grammar::stripLabel(string &label) 
{
    // we just want to strip the begin and end of label with a char "'"
    if (!label.empty() && label[0] == '\'')
        label.erase(remove(label.begin(), label.end(), '\''), label.end());
}   
Example #4
0
 int string::compare(size_t pos, size_t len, const string& str) const{
     return compare_aux(pos, len, str.begin(), 0, str.size());
 }
void cElementManager::processParamList (const string &params, list<string> &attlist,
    map<string, string> &attdefault)
{
  //this is similar to the parser in gotTag(), but it's a bit simpler...
  
  string name, value;
  char quote;
  paramParserState state = parNone;
  string::const_iterator it;
  for (it = params.begin(); it != params.end(); ++it)
  {
    char ch = *it;

    //process character
    switch (state) {
      case parNone: {
        if (ch != ' ')
        {
          state = parName;
          name += ch;
        }
        break;
      }
      case parName: {
        if (ch == '=')
          state = parValue;
        else if (ch == ' ')
        {
          //new parameter, no default value
          attlist.push_back (lcase (name));
          name = "";
          state = parNone;
        }
        else
          name += ch;
        break;
      }
      case parValue: {
        if (ch == ' ')
        {
          //new parameter, with default value
          attlist.push_back (lcase (name));
          attdefault[name] = value;
          name = "";
          value = "";
          state = parNone;
        }
        else if (value.empty() && ((ch == '\'') || (ch == '"')))
        {
          state = parQuotedValue;
          quote = ch;
        }
        else
          value += ch;
        break;
      }
      case parQuotedValue: {
        if (ch == quote)
        {
          //new parameter, with default value
          attlist.push_back (lcase (name));
          attdefault[name] = value;
          name = "";
          value = "";
          state = parNone;
        }
        else
          value += ch;
        break;
      }
    };
  }

  //last parameter...
  switch (state) {
    case parName: {
      //new parameter, no default value
      attlist.push_back (lcase (name));
    }
    break;
    case parValue: {
      //new parameter, with default value
      attlist.push_back (lcase (name));
      attdefault[name] = value;
      break;
    }
    case parQuotedValue:
      results->addToList (results->createWarning (
          "Received tag definition with unfinished quoted default parameter value!"));
      //new parameter, with default value (unfinished, but hey...)
      attlist.push_back (lcase (name));
      attdefault[name] = value;
    break;
  };
  
  //everything done...
}
Example #6
0
File: Nio.cpp Project: loki42/Carla
void Nio::setDefaultSink(string name)
{
    std::transform(name.begin(), name.end(), name.begin(), ::toupper);
    defaultSink = name;
}
Example #7
0
string tns::ucase( string str )
{
    transform( str.begin(), str.end(),str.begin(), ::toupper );
    return str;
}
Example #8
0
void ExperimentDialog::Decode(const string& input,string& output)
{
    output = input;
    std::replace(output.begin(), output.end(), '@', ' ');
}
Example #9
0
void buildSet(string inputString, set<char>& S) {
    for (string::iterator iter = inputString.begin(); iter != inputString.end(); iter++ ){
        S.insert(*iter);
    }
}
    int ans;
    ans = issubseq(i - 1, j, a, b);
    if (a[i] == b[j]) {
        ans = ans | issubseq(i - 1, j - 1, a, b);
    }
    cache[i][j] = ans;
    return cache[i][j];
}

int main() {
    cin >> s;
    cin >> t;
    string p, q;
    p = s, q = t;
    fill(&cache[0][0], &cache[110][0], -1);
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    if (issubseq(p.length() - 1, q.length() - 1, p, q) == 1) {
        fill(&cache[0][0], &cache[110][0], -1);
        if (s.length() == t.length())
            cout << "array";
        else if (issubseq(s.length() - 1, t.length() - 1, s, t) == 1)
            cout << "automaton";
        else
            cout << "both";

    } else {
        cout << "need tree";
    }
    return 0;
}
Example #11
0
void digitize(string const &s, vector<int> &v) {
    v.resize(s.size());
    transform(s.begin(), s.end(), v.begin(), [](char c) {
        return c - '0';
    });
}
CompressedBitset::CompressedBitset(const string &s) {
  bytes.reserve(s.size());
  for (string::const_iterator itr = s.begin(); itr != s.end(); ++itr) {
    bytes.push_back((unsigned char)(*itr));
  }
}
Example #13
0
string StrUtil::Trim(string s)
{
	s.erase(s.begin(), find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
	s.erase(find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
	return s;
}
Example #14
0
string StrUtil::ToLower(string s)
{
    transform(s.begin(), s.end(), s.begin(), static_cast<int(*)(int)>(std::tolower));
    return s;
}
Example #15
0
void ReplaceChar(string & input_output, char from, char to) {
	std::replace(input_output.begin(), input_output.end(), from, to);
}
Example #16
0
/// Our case insensitive less() function as required by UCI protocol
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {

  return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
         [](char c1, char c2) { return tolower(c1) < tolower(c2); });
}
Example #17
0
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
  return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
}
Example #18
0
void CONSOLE_Draw( )
{
	if( !gCurses )
		return;

	// draw main window

	if( gMainWindowChanged )
	{
		wclear( gMainWindow );
		wmove( gMainWindow, 0, 0 );

		for( vector<string> :: iterator i = gMainBuffer.begin( ); i != gMainBuffer.end( ); ++i )
		{
			for( string :: iterator j = (*i).begin( ); j != (*i).end( ); ++j )
				waddch( gMainWindow, *j );

			if( i != gMainBuffer.end( ) - 1 )
				waddch( gMainWindow, '\n' );
		}

		wrefresh( gMainWindow );
		gMainWindowChanged = false;
	}

	// draw input window

	if( gInputWindowChanged )
	{
		wclear( gInputWindow );
		wmove( gInputWindow, 0, 0 );

		for( string :: iterator i = gInputBuffer.begin( ); i != gInputBuffer.end( ); ++i )
			waddch( gInputWindow, *i );

		wrefresh( gInputWindow );
		gInputWindowChanged = false;
	}

	// draw channel window

	if( gChannelWindowChanged )
	{
		wclear( gChannelWindow );
		mvwaddnstr( gChannelWindow, 0, gCCBot->m_BNETs[0]->GetCurrentChannel( ).size( ) < 16 ? ( 16 - gCCBot->m_BNETs[0]->GetCurrentChannel( ).size( ) ) / 2 : 0, gCCBot->m_BNETs[0]->GetCurrentChannel( ).c_str( ), 16 );
		mvwhline( gChannelWindow, 1, 0, 0, 16 );
		int y = 2;

		// for( vector<string> :: iterator i = gChannelUsers.begin( ); i != gChannelUsers.end( ); ++i )
		
		for( vector<CUser *> :: iterator i = gCCBot->m_BNETs[0]->m_Channel.begin( ); i != gCCBot->m_BNETs[0]->m_Channel.end( ); ++i )
		{
			mvwaddnstr( gChannelWindow, y++, 0, (*i)->GetUser( ).c_str( ), 16 );

			if( y >= LINES - 3 )
				break;
		}

		wrefresh( gChannelWindow );
		gChannelWindowChanged = false;
	}
}
Example #19
0
string DCppTemplate::RemoveFlagTag(string tagStr, int tagSize)
{
    tagStr.erase(tagStr.begin(),tagStr.begin()+tagSize);
    tagStr.erase(tagStr.end()-tagSize,tagStr.end());
    return tagStr;
}
Example #20
0
string RCFile::getSetting(const string &line) const
{
	string setting = line.substr(0, distance(line.begin(), find_if(line.begin(), line.end(), ::isspace)));
	transform(setting.begin(), setting.end(), setting.begin(), tolower);
	return setting;
}
Example #21
0
 int string::compare(const string& str) const{
     return compare_aux(0, size(), str.begin(), 0, str.size());
 }
Example #22
0
void messageId::parse(const string& buffer, const string::size_type position,
	const string::size_type end, string::size_type* newPosition)
{
	const string::value_type* const pend = buffer.data() + end;
	const string::value_type* const pstart = buffer.data() + position;
	const string::value_type* p = pstart;

	m_left.clear();
	m_right.clear();

	unsigned int commentLevel = 0;
	bool escape = false;
	bool stop = false;

	for ( ; !stop && p < pend ; ++p)
	{
		if (escape)
		{
			// Ignore this character
		}
		else
		{
			switch (*p)
			{
			case '(': ++commentLevel; break;
			case ')': --commentLevel; break;
			case '\\': escape = true; break;
			case '<':
			{
				if (commentLevel == 0)
				{
					stop = true;
					break;
				}
			}

			}
		}
	}

	// Fix for message ids without angle brackets (invalid)
	bool hasBrackets = true;

	if (p == pend)  // no opening angle bracket found
	{
		hasBrackets = false;
		p = pstart;

		while (p < pend && parserHelpers::isSpace(*p))
			++p;
	}

	if (p < pend)
	{
		// Extract left part
		const string::size_type leftStart = position + (p - pstart);

		while (p < pend && *p != '@' && *p != '>') ++p;

		m_left = string(buffer.begin() + leftStart,
		                buffer.begin() + position + (p - pstart));

		if (p < pend)
		{
			// Skip '@'
			++p;

			// Extract right part
			const string::size_type rightStart = position + (p - pstart);

			while (p < pend && *p != '>' && (hasBrackets || !parserHelpers::isSpace(*p))) ++p;

			m_right = string(buffer.begin() + rightStart,
			                 buffer.begin() + position + (p - pstart));
		}
	}

	setParsedBounds(position, end);

	if (newPosition)
		*newPosition = end;
}
Example #23
0
 int string::compare(size_t pos, size_t len, const string& str, size_t subpos, size_t sublen) const{
     return compare_aux(pos, len, str.begin(), subpos, sublen);
 }
Example #24
0
 ChecksumImpl ChecksumImpl::generate( const string& value )
 {
     return generate( Bytes( value.begin( ), value.end( ) ) );
 }
void cElementManager::gotTag (const string &tag)
{
  string tagname;
  list<sParam> params;
  sParam param;
  param.flag = false;
  char quote;
  tagParserState pstate = tagBegin;
  string::const_iterator it;
  for (it = tag.begin(); it != tag.end(); ++it)
  {
    char ch = *it;

    //process character
    switch (pstate) {
      case tagBegin: {
        if (ch != ' ')
        {
          pstate = tagName;
          tagname += ch;
        }
        break;
      }
      case tagName: {
        if (ch == ' ')
          pstate = tagBetweenParams;
        else
          tagname += ch;
        break;
      }
      case tagParam: {
        if (ch == '=')
          pstate = tagParamValue;
        else if (ch == ' ')
        {
          //one parameter, value only (it could also be a flag, we'll check that later)
          param.value = param.name;
          param.name = "";
          //add a new parameter :-)
          params.push_back (param);
          param.value = "";
          pstate = tagBetweenParams;
        }
        else
          param.name += ch;
        break;
      }
      case tagParamValue: {
        if (ch == ' ')
        {
          //add a new parameter :-)
          params.push_back (param);
          param.name = "";
          param.value = "";
          pstate = tagBetweenParams;
        }
        else if (param.value.empty() && ((ch == '\'') || (ch == '"')))
        {
          pstate = tagQuotedParam;
          quote = ch;
        }
        else
          param.value += ch;
        break;
      }
      case tagQuotedParam: {
        if (ch == quote)
        {
          //add a new parameter :-)
          params.push_back (param);
          param.name = "";
          param.value = "";
          pstate = tagAfterQuotedParam;
        }
        else
          param.value += ch;
        break;
      }
      case tagAfterQuotedParam: {
        if (ch == ' ')    //ignore everything up to some space...
          pstate = tagBetweenParams;
        break;
      }
      case tagBetweenParams: {
        if (ch != ' ')
        {
          if ((ch == '\'') || (ch == '"'))
          {
            pstate = tagQuotedParam;
            param.name = "";
            quote = ch;
          }
          else
          {
            pstate = tagParam;
            param.name += ch;
          }
        }
        break;
      }
    };
  }

  //last parameter...
  switch (pstate) {
    case tagBegin:
      results->addToList (results->createError ("Received a tag with no body!"));
      break;
    case tagParam: {
      param.value = param.name;
      param.name = "";
      params.push_back (param);
      }
      break;
    case tagParamValue:
      params.push_back (param);
      break;
    case tagQuotedParam:
      results->addToList (results->createError ("Received tag " + tagname +
          " with unfinished quoted parameter!"));
      break;
  };

  //nothing more to do if the tag has no contents...
  if (pstate == tagBegin) return;
  
  //convert tag name to lowercase
  tagname = lcase (tagname);
  
  //handle closing tag...
  if (tagname[0] == '/')
  {
    if (!params.empty())
      results->addToList (results->createError ("Received closing tag " + tagname +
          " with parametrs!"));
    //remove that '/'
    tagname.erase (tagname.begin());
    //and call closing tag processing
    handleClosingTag (tagname);
    return;
  }
  
  //convert all parameter names to lower-case
  list<sParam>::iterator parit;
  for (parit = params.begin(); parit != params.end(); ++parit)
    (*parit).name = lcase ((*parit).name);
  
  //now we check the type of the tag and act accordingly
  if (!elementDefined (tagname))
  {
    params.clear();
    results->addToList (results->createError ("Received undefined tag " + tagname + "!"));
    return;
  }

  mxpMode m = state->getMXPMode ();
  //mode can be open or secure; locked mode is not possible here (or we're in a bug)
  if (m == openMode)
    //open mode - only open tags allowed
    if (!openElement (tagname))
    {
    params.clear();
      results->addToList (results->createError ("Received secure tag " + tagname +
          " in open mode!"));
      return;
    }

  if (internalElement (tagname))
  {
    //if the name is an alias for another tag, change the name
    if (aliases.count (tagname))
      tagname = aliases[tagname];
    //the <support> tag has to be handled separately :(
    if (tagname == "support")
    {
      processSupport (params);
      return;
    }
    //identify all flags in the tag
    identifyFlags (ielements[tagname]->attdefault, params);
    //correctly identify all parameters (assign names where necessary)
    handleParams (tagname, params, ielements[tagname]->attlist, ielements[tagname]->attdefault);
    //separate out all the flags (flags are only valid for internal tags)
    list<string> flags;
    parit = params.begin();
    while (parit != params.end())
    {
      if ((*parit).flag)
      {
        flags.push_back ((*parit).name);
        parit = params.erase (parit);
      }
      else
        ++parit;
    }
    //okay, parsing done - send the tag for further processing
    processInternalTag (tagname, params, flags);
  }
  else
  {
    handleParams (tagname, params, elements[tagname]->attlist, elements[tagname]->attdefault);
    processCustomTag (tagname, params);
  }
  
  params.clear ();
}
Example #26
0
	void Capitalize(string& s)
	{
		transform(s.begin(), s.end(), s.begin(), rkj::my_toupper);
	}
Example #27
0
bool ftpMisc::ftpExecuteCommand( string command, vector<string> &responses ) {
	ftpConnection		*ftp = 0;
	bool				 actResult = false;
	string				 argument;
	size_t				 pos;
	
	pos = command.find(" ");

	if( pos != string::npos ) {
		argument = command.substr( pos + 1 );
		command  = command.substr(0, pos);
	}

	transform( command.begin(), command.end(), command.begin(), ::tolower );
	
	ftp = ftpConnect();
	if(!ftp || ftp->failed()) {
		string fail = string( "Connection Failed. " );
		
		if(ftp) {
			fail.append( ftp->errorGet() );
			_ftpConnections->ftpDone( ftp->ftpIDGet() );
		}

		responses.push_back( fail );
		return false;
	}
	try {

		if(command == "list") {
			// No path? use root
			if(!argument.size())
				argument = "/";

			ftpEntry *entry = new ftpEntry(0, _serverConnection, argument, 0, (serverDetail()->_ftpType == ftpTypeRAIDEN) ? true : false );

			if( ftp->directoryChange(argument, true) == false)
				responses = *ftp->ResponsesGet();

			else {
				size_t count = 0;

				// Read/Process directorys
				responses = ftp->directoryRead( entry, true );
				entry->entryProcess( responses, false );

				actResult = !ftp->failed();
				responses.clear();

				// add all folders/files into responses
				vector<ftpEntry*>::iterator entryIT;
				for( entryIT = entry->entrysDirectorysGet()->begin(); entryIT != entry->entrysDirectorysGet()->end(); ++entryIT, count++ ) {
					responses.push_back( (*entryIT)->pathGet() );
					if(count > 19)
						break;
				}
				
				for( entryIT = entry->entrysFilesGet()->begin(); entryIT != entry->entrysFilesGet()->end(); ++entryIT, count++ ) {
					responses.push_back( (*entryIT)->entryNameGet() );
					if(count > 19)
						break;
				}

			}
		} else if(command == "site") {			// Site Commands
			string argumentCmd, param;

			pos = argument.find(" ");
			if(pos != string::npos) {
				argumentCmd = argument.substr(0, pos);
				param = argument.substr(pos+1);
			} else
				argumentCmd = argument;


			if( argumentCmd.substr(0, 10) == "extractrar" ) {
				string target;
				if(param.substr( param.size()-1, 1 ) == "/")
					param.erase( param.size()-1, 1);

				pos = param.find_last_of("/" );
				if(pos != string::npos) {
					target = param.substr( pos + 1 );
				

					if(ftp->directoryChange(param))
						ftp->siteCommand("extractrar", target);
				}

				vector<string>				*str = ftp->ResponsesGet();
				vector<string>::iterator	 strIT;

				for( strIT = str->begin(); strIT != str->end(); ++strIT) {
					responses.push_back( *strIT );
				}

			} else {
	
				//actResult	 = ftp->command(command, argument);
				//responses = *ftp->ResponsesGet();
				responses.push_back("all commands except list disabled");
			}
		}

	} catch(...) {

	}
	_ftpConnections->ftpDone( ftp->ftpIDGet() );

	return actResult;
}
Example #28
0
	void UnCapitalize(string& s)
	{
		transform(s.begin(), s.end(), s.begin(), rkj::my_tolower);
	}
Example #29
0
bool PropertyBag::loadMergeFromString(const string &data) {
	enum eElanPropBagReadState {
		SearchingForOpenTag,
		ReadingOpenTag,
		ReadingTagContents
	} curstate = SearchingForOpenTag;
	
	string tagname;
	string tagvalue;
	string closetag;
	
	unsigned char previous=0;
	string possibleClosingTag;
	bool isPossibleClosingTag=false;
	
	for (string::const_iterator iter = data.begin(); iter != data.end(); ++iter) {
		const unsigned char b = (unsigned char)(*iter);
		
		switch (curstate) {
		case SearchingForOpenTag: {
			if (b == '<') {
				// we've found our open tag!
				curstate = ReadingOpenTag;
			}
		}
		break;
		
		case ReadingOpenTag: {
			if (b == '>') {
				// end of tag
				curstate = ReadingTagContents;
				closetag = "</" + tagname + ">";
			} else {
				// add the character to the name of the tag
				tagname += b;
			}
		}
		break;
		
		case ReadingTagContents: {
			// Add the character to the contents of the tag
			tagvalue += b;
			
			// If we are possibly reading the closing tag now
			if (isPossibleClosingTag) {
				// Build the string for what may be the closing tag
				possibleClosingTag += b;
				
				// Otherwise, search for the real closing tag
				if (possibleClosingTag == closetag) {
					// Remove that closing tag from the tag contents
					tagvalue = replace(tagvalue, closetag, "");
					
					// Put the completed tag into the bag here
					insertTag(tagname, tagvalue);
					
					// Reset the state
					curstate = SearchingForOpenTag;
					tagname = "";
					tagvalue = "";
				}
				
				// Has it become impossible that this is the closing tag?
				if (b == '>') {
					isPossibleClosingTag = false;
				}
			}
			
			// Have we begun to encounter what may be the closing tag?
			if (previous == '<' && b == '/') {
				isPossibleClosingTag = true;
				possibleClosingTag = "</";
			}
		}
		break;
		}
		; // end switch
		
		previous = b;
	}
	
	return(true);
}
bool operator == (number_t const & a, number_t const & b) {
    ppiipii key = { to_pair(a), to_pair(b) };
    if (memo_eq.count(key)) return memo_eq[key];
    return memo_eq[key] =
        digits_of(a) == digits_of(b) and equal(S.begin() + a.l, S.begin() + a.r, S.begin() + b.l);
}