void JucerDocument::setParentClasses (const String& classes)
{
    if (classes != parentClasses)
    {
        StringArray parentClassLines (getCleanedStringArray (StringArray::fromTokens (classes, ",", StringRef())));

        for (int i = parentClassLines.size(); --i >= 0;)
        {
            String s (parentClassLines[i]);
            String type;

            if (s.startsWith ("public ")
                || s.startsWith ("protected ")
                || s.startsWith ("private "))
            {
                type = s.upToFirstOccurrenceOf (" ", true, false);
                s = s.fromFirstOccurrenceOf (" ", false, false);

                if (s.trim().isEmpty())
                    type = s = String::empty;
            }

            s = type + CodeHelpers::makeValidIdentifier (s.trim(), false, false, true);

            parentClassLines.set (i, s);
        }

        parentClasses = parentClassLines.joinIntoString (", ");
        changed();
    }
}
Example #2
0
void loop()
{
  // print the string when a newline arrives:
  if (stringComplete) {
      Serial.println(inputString);
      // clear the string:
      inputString.trim();
      Serial.println(inputString.length());
      if(inputString == "x") {
          direction = FORWARD;
          blockingRunSpeedToPosition(direction,"x");
      } else if (inputString == "-x") {
          direction = BACKWORD;
          blockingRunSpeedToPosition(direction,"x");
      } else if (inputString =="y") {
          direction = FORWARD;
          blockingRunSpeedToPosition(direction,"y");
      } else if (inputString == "-y") {
          direction = BACKWORD;
          blockingRunSpeedToPosition(direction, "y");
      } else if(inputString == "z"){
          direction = FORWARD;
          blockingRunSpeedToPosition(direction, "z");
      }else if (inputString == "-z") {
          direction = BACKWORD;
          blockingRunSpeedToPosition(direction, "z");
      }

      inputString = "";
      stringComplete = false;

    }
}
Example #3
0
void HttpClient::parseHeaders(pbuf* buf, int headerEnd)
{
	int line, nextLine;
	line = NetUtils::pbufFindStr(buf, "\r\n", 0) + 2;
	do
	{
		nextLine = NetUtils::pbufFindStr(buf, "\r\n", line);
		if (nextLine - line > 2)
		{
			int delim = NetUtils::pbufFindStr(buf, ":", line);
			if (delim != -1)
			{
				String name = NetUtils::pbufStrCopy(buf, line, delim - line);
				//if (server->isHeaderProcessingEnabled(name))
				{
					String value = NetUtils::pbufStrCopy(buf, delim + 1,
							nextLine - (delim + 1));
					value.trim();
					responseHeaders[name] = value;
					debugf("%s === %s", name.c_str(), value.c_str());
				}
			}
		}
		line = nextLine + 2;
	} while (nextLine != -1 && nextLine < headerEnd);
}
Example #4
0
int main() {
	String a = "Hello ", b = "world!";
	String c = a.concat(b);

	a.print();
	b.print();
	c.print();

	c.upper();
	c.print();

	String d= c.first(3);
	d.print();

	String e = c.last(3);
	e.print();

	String f = c.substr(4, 3);
	f.print();

	String g = "   trim  ";
	g.print();
	g.trim().print();

	(a + b).print();

	getc(stdin);

	return 0;
}
Example #5
0
/**************************************************************
 *    obtenirStr
 *
 *    Convertie un tableau de symboles en String
 *
 *    Arguments: seq : la sequence a convertir
 *               longueur : la longueur du tableau
 *    Retour:    La chaine de texte contenant la sequence
 *
 **************************************************************/
String obtenirStr(const Symbole seq[], unsigned int longueur)
{
    String s = "";

    for (int i = 0; i < longueur; i++) {
        switch (seq[i]) {
            case X :
                s += String("X ");
                break;
            case O :
                s += String("O ");
                break;
            case CARRE :
                s += (String(SYMB_CARRE) + String(" "));
                break;
            case COEUR :
                s += String(SYMB_COEUR + String(" "));
                break;
            case ETOILE :
                s += String("* ");
                break;
            case PLUS :
                s += String("+ ");
                break;
            case RIEN :
            default :
                s += String("_ ");
        }
    }

    s.trim();    // Retire l'espace a la fin
    return s;
}
Example #6
0
//==============================================================================
bool Process::openDocument (const String& fileName, const String& parameters)
{
    String cmdString (fileName.replace (" ", "\\ ",false));
    cmdString << " " << parameters;

    if (URL::isProbablyAWebsiteURL (fileName)
         || cmdString.startsWithIgnoreCase ("file:")
         || URL::isProbablyAnEmailAddress (fileName))
    {
        // create a command that tries to launch a bunch of likely browsers
        const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };

        StringArray cmdLines;

        for (int i = 0; i < numElementsInArray (browserNames); ++i)
            cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());

        cmdString = cmdLines.joinIntoString (" || ");
    }

    const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };

    const int cpid = fork();

    if (cpid == 0)
    {
        setsid();

        // Child process
        execve (argv[0], (char**) argv, environ);
        exit (0);
    }

    return cpid >= 0;
}
Example #7
0
boolean BlueToothSerial::sendCommand(String command, sbyte retryTimes) {
  byte times;
  if(retryTimes == -1)
    retryTimes = retry;

    setupPrintln("Command", command);
  
  for(times = 0; times < retryTimes; times ++) {    
    stream->println(command); 
    stream->flush();
   
    String result = stream->readStringUntil('\n');
    if(result=="")
      result = "<TimeOut>";
      
    setupPrintln("Result", times, result);
    result.trim();
    if( result == "OK") {
      break;
    }
  }
  
  if(times == retryTimes) {
    setupPrint("Result: Failed\r\n\r\n");
    return false;
  }
  else {
    setupPrint("Result: Succeeded\r\n\r\n");
    return true;
  }
}
bool KeyValueStore::migrate() {
  if (!SPIFFS.exists(FILENAME_OLD)) {
    return true;
  }
  StaticJsonBuffer<300> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();

  File f = SPIFFS.open(FILENAME_OLD, "r");
  if (!f) {
    return false;
  }
  while(f.available()) {
    String line = f.readStringUntil('\n');
    int separator = line.indexOf("=");
    if (separator > -1) {
      String key = line.substring(0, separator);
      String value = line.substring(separator + 1);
      value.trim();
      root[key] = value;
    }
  }
  f.close();
  clear(FILENAME_JSON);
  File fJson = SPIFFS.open(FILENAME_JSON, "w");
  root.printTo(fJson);
  fJson.close();
  Serial.println("Migrated KeyValueStore to JSON:");
  root.prettyPrintTo(Serial);
  Serial.println();
  clear(FILENAME_OLD);
  return true;
}
Example #9
0
bool ESP8266WebServer::authenticate(const char * username, const char * password){
  if(hasHeader(AUTHORIZATION_HEADER)){
    String authReq = header(AUTHORIZATION_HEADER);
    if(authReq.startsWith("Basic")){
      authReq = authReq.substring(6);
      authReq.trim();
      char toencodeLen = strlen(username)+strlen(password)+1;
      char *toencode = new char[toencodeLen + 1];
      if(toencode == NULL){
        authReq = String();
        return false;
      }
      char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
      if(encoded == NULL){
        authReq = String();
        delete[] toencode;
        return false;
      }
      sprintf(toencode, "%s:%s", username, password);
      if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){
        authReq = String();
        delete[] toencode;
        delete[] encoded;
        return true;
      }
      delete[] toencode;
      delete[] encoded;
    }
    authReq = String();
  }
  return false;
}
Example #10
0
bool WebServer::authenticate(const char * username, const char * password)
{
  if(_autorization.length()>0)
  {
    String authReq = _autorization;
    if(authReq.startsWith("Basic")){
      authReq = authReq.substring(6);
      authReq.trim();
      char toencodeLen = strlen(username)+strlen(password)+1;
      char *toencode = new char[toencodeLen + 1];
      if(toencode == NULL){
        return false;
      }
      char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
      if(encoded == NULL){
        delete[] toencode;
        return false;
      }
      sprintf(toencode, "%s:%s", username, password);
      if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){
        delete[] toencode;
        delete[] encoded;
        return true;
      }
      delete[] toencode;
      delete[] encoded;
    }
  }
  return false;
}
Example #11
0
boolean TinyGSM::SMSreceived(){
	if (_serial->available()){
		_serial->setTimeout(200);
		String input = _serial->readStringUntil('"');
		input.trim();
		if (input.startsWith("+CMT:")) return true;
	}
	return false;
}
Example #12
0
	bool yl_messenger::get_request_result()
	{
		String temp;
		if (!recv_ln(temp))
		{
#ifdef YL_SERIAL_DEBUG
			Serial.println("recv error : 122");
#endif
			return false;
		}
		long start_index = temp.indexOf(' ');
		temp = temp.substring(start_index + 1);
		temp.trim();
		long end_index = temp.indexOf(' ');
		temp = temp.substring(0, end_index);
		temp.trim();
		return temp[0] == '2';
	}
static bool deviceListContains (AudioIODeviceType* type, bool isInput, const String& name)
{
    StringArray devices (type->getDeviceNames (isInput));

    for (int i = devices.size(); --i >= 0;)
        if (devices[i].trim().equalsIgnoreCase (name.trim()))
            return true;

    return false;
}
Example #14
0
boolean TinyGSM::isConnected(){
	print("AT+CREG?\r");
	delay(100);
	while(_serial->available()){
		String input = _serial->readStringUntil('\n');
		input.trim();
		if (input.equals("+CREG: 0,1") || input.equals("+CREG: 0,5")) return true;
	}
	return false;
}
void RingBuffer::prettyReadLine(String &lineToReturn){
    /*

    Return one line (terminated with \n) from the buffer, but in all uppercase
    with no leading or trailing whitespaces

    */
    readLine(lineToReturn);
    lineToReturn.trim();  // remove leading and trailing white space
    lineToReturn.toUpperCase();
}
Example #16
0
const String getGameGUIOptionsDescription(const String &options) {
	String res;

	for (int i = 0; g_gameOptions[i].desc; i++)
		if (options.contains(g_gameOptions[i].option[0]))
			res += String(g_gameOptions[i].desc) + " ";

	res.trim();

	return res;
}
Example #17
0
String XmlDocument::getFileContents (const String& filename) const
{
    if (inputSource != nullptr)
    {
        const ScopedPointer<InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));

        if (in != nullptr)
            return in->readEntireStreamAsString();
    }

    return String::empty;
}
void NewhavenDisplay::stringPadRight(String &str, const int length_total)
{
  str.trim();
  if (str.length() > length_total)
  {
    str = str.substring(0,length_total);
  }
  String padding = String(padding_char_);
  while (str.length() < length_total)
  {
    str += padding;
  }
}
Example #19
0
String ProjectExporter::getUniqueConfigName (String nm) const
{
    String nameRoot (nm);
    while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
        nameRoot = nameRoot.dropLastCharacters (1);

    nameRoot = nameRoot.trim();

    int suffix = 2;
    while (hasConfigurationNamed (name))
        nm = nameRoot + " " + String (suffix++);

    return nm;
}
Example #20
0
bool D2Container::parseFile(wchar_t const* path, D2Data* d2data)
{
  sub.clear();
  WIN32_FILE_ATTRIBUTE_DATA attr;
  if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr))
    return false;
  uint64 lastWrite = uint64(attr.ftLastWriteTime.dwLowDateTime) | (uint64(attr.ftLastWriteTime.dwHighDateTime) << 32);
  if (lastWrite <= lastUpdate)
    return false;
  lastUpdate = lastWrite;
  for (int i = 0; i < items.length(); i++)
    items[i]->release();
  items.clear();
  LocalPtr<File> file = File::wopen(path, File::READ);
  String line;
  String header(WideString::format(L"%s / %s", parent->name, name));
  while (file->gets(line))
  {
    line.trim();
    if (line.empty()) continue;
    LocalPtr<json::Value> value = json::Value::parse(TempFile(File::memfile(line.c_str(), line.length(), false)));
    if (value && value->type() == json::Value::tObject
              && value->hasProperty("itemColor", json::Value::tNumber)
              && value->hasProperty("image", json::Value::tString)
              && value->hasProperty("title", json::Value::tString)
              && value->hasProperty("description", json::Value::tString)
              && value->hasProperty("header", json::Value::tString)
              && value->hasProperty("sockets", json::Value::tArray))
    {
      D2Item* item = new D2Item(this);
      item->invColor = value->get("itemColor")->getInteger();
      item->image = value->get("image")->getString();
      item->title = value->get("title")->getString();
      item->description = value->get("description")->getString();
      item->header = value->get("header")->getString();
      if (!item->header.length())
        item->header = header;
      json::Value* sockets = value->get("sockets");
      for (uint32 i = 0; i < sockets->length(); i++)
      {
        json::Value* sock = sockets->at(i);
        if (sock->type() == json::Value::tString)
          item->sockets.push(sock->getString());
      }
      item->parse(d2data);
      items.push(item);
    }
  }
  return true;
}
Example #21
0
 StringList ListTable::getList()
 {
   String stringit;
   list_.clear();
   for (Int i = 0; i < count(); ++i)
   {
     stringit = item(i)->text();
     if (stringit != "")
     {
       stringit.trim();
     }
     list_.push_back(stringit);
   }
   return list_;
 }
Example #22
0
bool HttpRequest::extractParsingItemsList(pbuf* buf, int startPos, int endPos, char delimChar, char endChar,
													HashMap<String, String>* resultItems)
{
	bool continued = false;
	int delimItem, nextItem, startItem = startPos;
	while (startItem < endPos)
	{
		delimItem = NetUtils::pbufFindStr(buf, "=", startItem);
		if (delimItem == -1 || delimItem > endPos) break;
		nextItem = NetUtils::pbufFindChar(buf, delimChar, delimItem + 1);
		if (nextItem == -1)
			nextItem = NetUtils::pbufFindChar(buf, endChar, delimItem + 1);
		if (nextItem > endPos) break;

		if (nextItem == -1)
		{
			nextItem = endPos;
			continued = true;
		}

		String ItemName = NetUtils::pbufStrCopy(buf, startItem, delimItem - startItem);
		String ItemValue = NetUtils::pbufStrCopy(buf, delimItem + 1, nextItem - delimItem - 1);
		char* nam = uri_unescape(NULL, 0, ItemName.c_str(), -1);
		ItemName = nam;
		free(nam);
		char* val = uri_unescape(NULL, 0, ItemValue.c_str(), -1);
		ItemValue = val;
		free(val);
		ItemName.trim();
		if (!continued) ItemValue.trim();
		debugf("Item: Name = %s, Size = %d, Value = %s",ItemName.c_str(),ItemValue.length(),ItemValue.substring(0,80).c_str());
		(*resultItems)[ItemName] = ItemValue;
		startItem = nextItem + 1;
	}
	return continued;
}
Example #23
0
String XmlDocument::getParameterEntity (const String& entity)
{
    for (int i = 0; i < tokenisedDTD.size(); ++i)
    {
        if (tokenisedDTD[i] == entity
                && tokenisedDTD [i - 1] == "%"
                && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
        {
            const String ent (tokenisedDTD [i + 1].trimCharactersAtEnd (">"));

            if (ent.equalsIgnoreCase ("system"))
                return getFileContents (tokenisedDTD [i + 2].trimCharactersAtEnd (">"));

            return ent.trim().unquoted();
        }
    }

    return entity;
}
Example #24
0
void ParamView::addEditor(AudioProcessor* p)
{
  Array <PropertyComponent*> params;
  
  const int numParams = p->getNumParameters();
  int totalHeight = 0;
  
  for (int i = 0; i < numParams; ++i)
  {
    String name (p->getParameterName (i));
    if (name.trim().isEmpty())
      name = "Unnamed";
    
    ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, *p, i);
    params.add (pc);
    totalHeight += pc->getPreferredHeight();
  }
  
  panel.addSection (p->getName(), params, false);
}
Example #25
0
void parseFields(ParseState& state, StructInfo& info) {
    while (state.hasNext()) {
        String statement = state.takeUntil(';', 0);
        statement.trim();
        if (statement.contains("endFields")) {
            return;
        }
//        section.takeWhile(fnc(c != '='));
        Sequence<String> sections = statement.split(' ');
        if (sections.size() >= 2) {
            FieldInfo field;
            field.typeName = sections[0];
            field.name = sections[1];

            info.fields.add(field);
        } else {
            Noto::error("Malformed field in struct, full text\"{}\"", statement);
        }
    }
}
  void MassDecompositionAlgorithm::getDecompositions(vector<MassDecomposition> & decomps, double mass)
  {
    double tolerance((double) param_.getValue("tolerance"));
    ims::RealMassDecomposer::decompositions_type decompositions = decomposer_->getDecompositions(mass, tolerance);

    for (ims::RealMassDecomposer::decompositions_type::const_iterator pos = decompositions.begin(); pos != decompositions.end(); ++pos)
    {
      String d;
      for (ims::IMSAlphabet::size_type i = 0; i < alphabet_->size(); ++i)
      {
        if ((*pos)[i] > 0)
        {
          d += alphabet_->getName(i) + String((*pos)[i]) + " ";
        }
      }
      d.trim();
      MassDecomposition decomp(d);
      decomps.push_back(decomp);
    }

    return;
  }
Example #27
0
void ROTankWire::Receive(int bytes) {
    //!!DONT PUT SERIAL.PRINTS IN HERE IT WILL SCREW UP WIRE COMM!!

    _wireRequest = "";
    _cmd = "";
    _cmdData = "";
    if(bytes == _wireReqLength) {
        while (Wire.available() > 0) {
            char c = Wire.read();
            _wireRequest.concat(c);
        }
        //Serial.print("Wire Request: ");
        //Serial.println(_wireRequest);
        _wireRequest.trim();
        if(_wireRequest.startsWith("/")) {
            _cmd = _wireRequest;
            Serial.print(F("cmd: "));
            Serial.println(_cmd);
        }
        else {
            _cmdData = _wireRequest;
            Serial.print(F("cmdData: "));
            Serial.println(_cmdData);
            String var = SplitString(_cmdData, '=', 0);
            String val = SplitString(_cmdData, '=', 1);

            if(val == "-") { // means null value sent in, so do nothing with cmd.
                //Transmit("-");
                return;
            }

            handleCmd(var, val);
        }
    }
    else {
        Serial.print(F("Unexpected number of bytes received: "));
        Serial.println(bytes);
    }
}
  explicit HeaderInfo(const String& filename)
  {
    header_description = "-- empty --";
    TextFile tf;
    tf.load(filename);
    String content;
    content.concatenate(tf.begin(), tf.end(), ";");

    String search = "$$ Sample Description:";
    Size pos = content.find(search);
    if (pos != std::string::npos)
    {
      pos += search.size();
      Size pos_end = content.find("$$", pos);
      if (pos_end != std::string::npos)
      {
        String tmp = content.substr(pos, pos_end - pos - 1);
        if (!tmp.trim().empty()) header_description = tmp;
        //std::cerr << "Header info is: " << header_description << std::endl;
      }
    }
  }
bool ChildProcessSlave::initialiseFromCommandLine (const String& commandLine,
                                                   const String& commandLineUniqueID,
                                                   int timeoutMs)
{
    auto prefix = getCommandLinePrefix (commandLineUniqueID);

    if (commandLine.trim().startsWith (prefix))
    {
        auto pipeName = commandLine.fromFirstOccurrenceOf (prefix, false, false)
                                   .upToFirstOccurrenceOf (" ", false, false).trim();

        if (pipeName.isNotEmpty())
        {
            connection.reset (new Connection (*this, pipeName, timeoutMs <= 0 ? defaultTimeoutMs : timeoutMs));

            if (! connection->isConnected())
                connection.reset();
        }
    }

    return connection != nullptr;
}
bool ESP_MQTTLogger::_authenticate(){

  if(_server->hasHeader(MQTT_AUTHORIZATION_HEADER)) {
    String authReq = _server->header(MQTT_AUTHORIZATION_HEADER);

#ifdef MQTT_LOGGER_DEBUG
    DEBUG_OUTPUT.print("authReq: ");
    DEBUG_OUTPUT.println(authReq);
#endif

    if(authReq.startsWith("Token")){
      authReq = authReq.substring(6);
      authReq.trim();

      if (authReq.equals(_token)){
        return true;
      }
    }
  }

  return false;
}