Example #1
0
 TEST_F(TestString, testLastIndexOf) {
     String s = "foobar";
     ASSERT_NO_THROW({
     EXPECT_EQ(3,s.lastIndexOf("b"));
     EXPECT_EQ(2,s.lastIndexOf("ob"));
     EXPECT_EQ(-1,s.lastIndexOf("zaz"));
     EXPECT_EQ(-1,s.lastIndexOf("z"));
     });
Example #2
0
bool loadFromSdCard(String path){
  String dataType = "text/plain";
  if(path.endsWith("/")) path += "index.htm";

  if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
  else if(path.endsWith(".htm")) dataType = "text/html";
  else if(path.endsWith(".css")) dataType = "text/css";
  else if(path.endsWith(".js")) dataType = "application/javascript";
  else if(path.endsWith(".png")) dataType = "image/png";
  else if(path.endsWith(".gif")) dataType = "image/gif";
  else if(path.endsWith(".jpg")) dataType = "image/jpeg";
  else if(path.endsWith(".ico")) dataType = "image/x-icon";
  else if(path.endsWith(".xml")) dataType = "text/xml";
  else if(path.endsWith(".pdf")) dataType = "application/pdf";
  else if(path.endsWith(".zip")) dataType = "application/zip";

  File dataFile = SD.open(path.c_str());
  if(dataFile.isDirectory()){
    path += "/index.htm";
    dataType = "text/html";
    dataFile = SD.open(path.c_str());
  }

  if (!dataFile)
    return false;

  if (server.hasArg("download")) dataType = "application/octet-stream";

  if (server.streamFile(dataFile, dataType) != dataFile.size()) {
    DBG_OUTPUT_PORT.println("Sent less data than expected!");
  }

  dataFile.close();
  return true;
}
Example #3
0
MusInputStream(CodecMus MusInputStream::codecmus, URL url, InputStream inputstream) 
{
        codec = codecmus;
        buffer = new byte[1];
        inputStream = inputstream;
        String s = url.getPath();
        s = s.substring(s.lastIndexOf("/") + 1);
        hash_00 = s.hashCode();
}
Example #4
0
bool ImageDesignManager::validatePalette(PaletteColorCustomizationVariable* palette, int value, int skillLevel) {
	String paletteFileName = palette->getPaletteFileName();
	int idx = paletteFileName.lastIndexOf("/");

	if (idx != -1) {
		String paletteName = paletteFileName.subString(idx + 1);
		paletteName = paletteName.subString(0, paletteName.indexOf("."));

		//info("palette name = " + paletteName, true);

		PaletteData* data = CustomizationIdManager::instance()->getPaletteData(paletteName);

		if (data == NULL) {
			//error("could not find palette data for " + paletteName);
		} else {
			int maxIndex;

			switch (skillLevel) {
			case -1:
				maxIndex = data->getCreationIndexes();
				break;
			case 0:
				maxIndex = data->getIdNoviceIndexes();
				break;
			case 1:
				maxIndex = data->getIdLevel1Indexes();
				break;
			case 2:
				maxIndex = data->getIdLevel2Indexes();
				break;
			case 3:
				maxIndex = data->getIdLevel3Indexes();
				break;
			case 4:
				maxIndex = data->getIdLevel4Indexes();
				break;
			case 5:
				maxIndex = data->getIdMasterIndexes();
				break;
			default:
				maxIndex = -1;
				break;
			}

			if (value >= maxIndex || value < 0) {
				instance()->error("value for " + paletteFileName + " value " + value + " outside bound " + String::valueOf(maxIndex));

				return false;
			} else {
				//info(name + " value " + String::valueOf(val) + " inside bound " + String::valueOf(maxIndex) + " for " + name , true);
			}
		}
	}

	return true;
}
Example #5
0
 int runInt(CppiaCtx *ctx)
 {
    String val = strVal->runString(ctx);
    BCR_CHECK;
    String s = sought->runString(ctx);
    BCR_CHECK;
    hx::Object *first = start->runObject(ctx);
    BCR_CHECK;
    if (LAST)
       return val.lastIndexOf(s,first);
    else
       return val.indexOf(s,first);
 }
Example #6
0
// Load in objects from standard input into the global variables: 
// gCtrlPoints, gCurves, gCurveNames, gSurfaces, gSurfaceNames.  If
// loading fails, this will exit the program.
void App::loadModel(const String& fileName)
{
    int end = fileName.lastIndexOf('.');
    String prefix = (end > 0) ? fileName.substring(0, end) : fileName;
    String skeletonFile = prefix + ".skel";
    String meshFile = prefix + ".obj";
    String attachmentsFile = prefix + ".attach";

    cout << "skeleton:   " << skeletonFile.getPtr() << endl;
    cout << "mesh:       " << meshFile.getPtr() << endl;
    cout << "attachment: " << attachmentsFile.getPtr() << endl;

    m_model.load(skeletonFile.getPtr(), meshFile.getPtr(), attachmentsFile.getPtr());
}
//Costum Function To Retrieve Date Time From Server
String thethingsiOClient_ti::readTime(String format) {
	int start;   
	int end; 
	String received = "";

    if (regular_client->connect(server, 80)) {
        GET(regular_client, "/v2/utils/date?thingToken=" + token + "&format=" + format);
        delay(1000);
        while (regular_client->available())
            received.concat((char)regular_client->read());
        regular_client->stop();
    }

//Retrieve the Time from Response
	String dummy = "value";
	dummy.concat('"');
	dummy.concat(':');
	start = received.lastIndexOf(dummy) + dummy.length();
	end	  = received.lastIndexOf("]") - 1;
	received = received.substring(start,end);

//
    return received;
}
//======================================================================================
String  VirtuinoEthernet_WebServer::checkNetworkCommand(String command){
  String returnedString="";
  
  int pos=command.lastIndexOf(COMMAND_END_CHAR);                      
  if (pos>5){                                          // check the size of command
      String command1= command.substring(0,pos+1);     // clear the command
      if (DEBUG) Serial.println("\r\nCommand = "+ command1);

       //------------------  get command password
       String commandPassword="";
       int k=command1.indexOf(COMMAND_START_CHAR);
       if (k>0) commandPassword = command1.substring(0,k);
       if (DEBUG) Serial.println("\r\nCommand password:"+commandPassword ); 
       
        
      if ((password.length()==0) || (commandPassword.equals(password))) {                       // check if password correct
           while (command1.indexOf(COMMAND_START_CHAR)>=0){
              int cStart=command1.indexOf(COMMAND_START_CHAR);
              int cEnd=command1.indexOf(COMMAND_END_CHAR);
              if (cEnd-cStart>5){
              String oneCommand = command1.substring(cStart+1,cEnd);                               // get one command
                char commandType = getCommandType(oneCommand);
                  if (commandType!='E') {
                     int pin= getCommandPin(oneCommand);
                     if (pin!=-1){
                        boolean returnInfo=false;
                        float value=0;
                        if (oneCommand.charAt(4)=='?') returnInfo=true;
                        else value = getCommandValue(oneCommand);
                        String commandResponce=executeReceivedCommand(commandType,pin , value,returnInfo);
                        returnedString += commandResponce;
                     } else  returnedString +=getErrorCommand(ERROR_PIN);  // response  error pin number   !E00=1$   
                  } else returnedString +=getErrorCommand(ERROR_TYPE);  // response  error type   !E00=3$   
          
              } else{
                returnedString +=getErrorCommand(ERROR_SIZE);  // response  error size of command   !E00=4$   
              }
              command1=command1.substring(cEnd+1);
           }  // while
      } else returnedString=getErrorCommand(ERROR_PASSWORD);     // the password is not correct
  }
  else  returnedString=getErrorCommand(ERROR_SIZE);         // the size of command is not correct
 
  return returnedString;
}
Example #9
0
bool HttpClient::downloadFile(String url, String saveFileName, HttpClientCompletedDelegate onCompleted /* = NULL */)
{
	if (isProcessing()) return false;
	URL uri = URL(url);

	String file;
	if (saveFileName.length() == 0)
	{
		file = uri.Path;
		int p = file.lastIndexOf('/');
		if (p != -1)
			file = file.substring(p + 1);
	}
	else
		file = saveFileName;

	saveFile = fileOpen(file.c_str(), eFO_CreateNewAlways | eFO_WriteOnly);
	debugf("Download file: %s %d", file.c_str(), saveFile);

	return startDownload(uri, eHCM_File, onCompleted);
}
void pspRoomConfigGUI::setSpeakerPosition(Slider* s){
    
    int speakerIndex;
    String aux;
    aux = s->getParentComponent()->getParentComponent()->getName();
    speakerIndex = aux.substring(aux.lastIndexOf(":") + 1).getIntValue();
    
    int coor;
    
    if(s->getParentComponent()->getName() == "x"){
        coor = 1;
    }
    else if(s->getParentComponent()->getName() == "y"){
        coor = 2;
    }
    else if(s->getParentComponent()->getName() == "z"){
        coor = 3;
    }
    
    myCr->setSpeakerPosition(speakerIndex, coor, s->getValue());
}
void FireworkObjectImplementation::fillAttributeList(AttributeListMessage* alm, CreatureObject* object) {
	TangibleObjectImplementation::fillAttributeList(alm, object);

	ManagedReference<FireworkObject*> firework = _this.getReferenceUnsafeStaticCast();

	if (firework == NULL)
		return;

	DataObjectComponent* data = firework->getDataObjectComponent()->get();

	if (data == NULL || !data->isFireworkShowData()) {
		String effect = "@firework_n:" + fireworkObject.subString(fireworkObject.lastIndexOf("/") + 1, fireworkObject.lastIndexOf("."));
		alm->insertAttribute("@obj_attr_n:pattern", effect);
	} else {
		FireworkShowDataComponent* fireworkShowData = cast<FireworkShowDataComponent*>(data);

		if (fireworkShowData == NULL)
			return;

		alm->insertAttribute("examine_hoppersize", firework->getCapacity());

		int totalFireworks = fireworkShowData->getTotalFireworkCount();
		alm->insertAttribute("blank_entry", "");
		alm->insertAttribute("length", "\\#pcontrast2 " + String::valueOf(totalFireworks) + " Fireworks");

		for (int i = 0; i < totalFireworks; i++) {
			ManagedReference<FireworkObject*> firework = fireworkShowData->getFirework(i);
			if (firework == NULL)
				continue;
			String fireworkObj = firework->getFireworkObjectPath();
			String effect = "@firework_n:" + fireworkObj.subString(fireworkObj.lastIndexOf("/") + 1, fireworkObj.lastIndexOf("."));
			alm->insertAttribute("pattern", effect);
		}

	}

}
Example #12
0
/*
 String chars0 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // 0 -> 33
 String chars1= "!\"#$%&'()*+,-./0123456789:;<=>?@"; // 33 -> 64
 String chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 65 -> 90
 String chars3 = "abcdefghijklmnopqrstuvwxyz"; // 97 -> 122
*/
byte Minitel::getCharByte(char c) {
  String characters = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]x_xabcdefghijklmnopqrstuvwxyz";
  return (byte) characters.lastIndexOf(c);
}
Example #13
0
void D2Item::parse(D2Data* data)
{
  int underscore = title.indexOf('_');
  if (underscore >= 0 && title.substr(0, underscore).isDigits())
    title.cut(0, underscore + 1);

  String desc = description;
  String gidInfo;
  int gidSep = desc.lastIndexOf('$');
  if (gidSep >= 0)
  {
    gidInfo = desc.substring(gidSep + 1);
    gid = atoi(gidInfo);
    desc.resize(gidSep);
  }
  Array<String> lines;
  desc.split(lines, "\\n");
  if (!lines.length())
    return;

  int ilvlSep = lines[0].lastIndexOf('(');
  if (ilvlSep >= 0)
  {
    itemLevel = atoi(lines[0].c_str() + ilvlSep + 1);
    lines[0].resize(ilvlSep);
    lines[0].trim();
  }
  while (!strncmp(lines[0], "\\xffc", 5))
  {
    colorCode = (lines[0][5] - '0');
    lines[0].cut(0, 6);
  }
  re::Prog remover("\\\\xffc[0-9:;<]");
  for (int i = 0; i < lines.length(); i++)
    lines[i] = remover.replace(lines[i], "");

  if (desc.find(data->getLocalizedString(5203)) >= 0)
    flags |= D2Item::fEthereal;
  if (desc.find(data->getLocalizedString(3455)) >= 0)
    flags |= D2Item::fUnidentified;

  if (!(flags & D2Item::fUnidentified) && (colorCode == 2 || colorCode == 4 || colorCode == 1))
    unique = data->getUniqueItem(lines[0]);
  if (!base && lines.length() > 1 && colorCode != 0 && colorCode != 3 && colorCode != 5)
    base = data->getBaseItem(lines[1]);
  if (!base && unique)
    base = unique->base;
  if (!base)
    base = data->getBaseItem(lines[0], true);
  if (!base)
    return;

  if (!unique && (flags & D2Item::fUnidentified))
  {
    unique = data->getUniqueByBase(base, colorCode);
    if (unique)
      title = String::format("[%s] %s", unique->name, base->name);
  }

  D2ItemType* info = base->type->getInfo();
  if (info)
  {
    type = info->type;
    subType = info->subType;
    quality = info->quality;
  }
  static int colorToQuality[] = {qNormal, qNormal, qSet, qMagic, qUnique, qNormal, 0, 0, qCrafted, qRare, 0, 0, 0};
  static int qualityToType[] = {tMisc, tWhite, tWhite, tWhite, tMagic, tSet, tRare, tUnique, tCrafted};
  if (quality < 0)
  {
    if (unique)
      quality = (unique->type == 6 ? qUnique : colorToQuality[unique->type]);
    else
      quality = colorToQuality[colorCode];
  }
  if (type == tAuto)
  {
    if (unique && unique->type == 6)
      type = tRuneword;
    else
      type = qualityToType[quality];
  }

  if (colorCode == 1)
  {
    if (unique)
      colorCode = (unique->type == 2 ? 2 : 4);
    // more broken detection?
  }

  if (!title.length())
  {
    title = lines[0];
    if (quality == D2Item::qSet || quality == D2Item::qRare ||
      quality == D2Item::qCrafted || quality == D2Item::qUnique)
      title = String::format("%s %s", lines[0], base->name);
  }

  if (!base || base->type->isType("rune") || base->type->isType("gem"))
    return;

  if (sockets.length())
  {
    Array<String> jewDesc;
    gidInfo.split(jewDesc, "\n\n");
    int curJew = 1;
    for (int sox = 0; sox < sockets.length(); sox++)
    {
      D2BaseItem* soxBase = data->getBaseByCode(sockets[sox]);
      if (!soxBase)
      {
        String tname(sockets[sox]);
        if (s_isdigit(tname[tname.length() - 1]))
        {
          tname.resize(tname.length() - 1);
          soxBase = data->getBaseByCode(tname);
        }
      }
      if (!soxBase)
        socketItems.push(NULL);
      else
      {
        D2Item* sock = new D2Item;
        sock->socketParent = this;
        sock->image = sockets[sox];
        sock->base = soxBase;
        if (soxBase->type->isType("jewl") && curJew < jewDesc.length())
          sock->description = jewDesc[curJew++];
        else
        {
          sock->title = soxBase->name;
          sock->description = soxBase->gemDesc;
        }
        sock->header = String::format("%s (Socketed)", header);
        sock->parse(data);
        socketItems.push(sock);
      }
    }
  }

  D2StatData* statData = data->getStatData();
  for (int i = 0; i < lines.length(); i++)
    statData->parse(stats, lines[i]);
  statText = statData->process(this);
}