Beispiel #1
0
/*! Optimizes the number (\a num) for output to a text file and returns it as a string (\a str). */
char* emb_optOut(double num, char* str)
{
    /* Convert the number to a string */
    sprintf(str, "%.10f", num);
    /* Remove trailing zeroes */
    rTrim(str, '0');
    /* Remove the decimal point if it happens to be an integer */
    rTrim(str, '.');
    return str;
}
void CommonTestsSuite::test_rtrim() {
	string str;

	str = "";
	rTrim(str);
	TS_ASSERT(str == "");

	str = " ";
	rTrim(str);
	TS_ASSERT(str == "");

	str = " b";
	rTrim(str);
	TS_ASSERT(str == " b");

	str = " bb";
	rTrim(str);
	TS_ASSERT(str == " bb");

	str = " bb ";
	rTrim(str);
	TS_ASSERT(str == " bb");

	str = " bb b";
	rTrim(str);
	TS_ASSERT(str == " bb b");

	str = " bb b ";
	rTrim(str);
	TS_ASSERT(str == " bb b");
}
char* trimSpace(char String[])
{
	rTrim(String);
	lTrim(String);
	/* Trim Space all */		
	char *ptr = strstr(String, "  ");
	while (ptr != NULL)
	{
		strcpy (ptr, ptr+1);
		ptr = strstr(String, "  ");
	}	
	return String;
}
Beispiel #4
0
char* trim(char* szX)
{
	szX = lTrim(szX);
	szX = rTrim(szX);
	return szX;
}
Beispiel #5
0
char* trim(char* string){
	return lTrim(rTrim(string));
}
gboolean ChangeDirectory(const char* d) {
  
  Log(DEBUGGING, "ChangeDirectory \"%s\"", d);
  char data[LIBUSB_PATH_MAX];
  int c;
  char directory_p[LIBUSB_PATH_MAX], *directory;
  directory = directory_p;
  strncpy(directory, d, LIBUSB_PATH_MAX - 1);
  
  //the following breaks the CD into seperate directory paths...
  //I found the complex path support in the camcorder a bit flakey.
  if((strlen(directory) > 1) && (directory[0] == '/')) {
    if(ChangeDirectory("/")==FALSE)
      return FALSE;
    //directory=directory.Mid(1,LIBUSB_PATH_MAX); //strip off leading /
    directory++;
    rTrim(directory, '/');
    
    //    directory.TrimRight("/"); //strip off trailing /
  }
  

  while( strlen(directory)>1 && directory[0]=='/' ) { //FIXME
    char temp[LIBUSB_PATH_MAX];
    strncpy(temp, directory, LIBUSB_PATH_MAX - 1);
    if (directory[0]=='/')
      directory[0] = '\0';    
    
    if(ChangeDirectory(temp)==FALSE) {
      Log(ERROR, "failed to change directory to parent directory %s",temp);
      return FALSE;
    }

    strncpy(temp, directory, LIBUSB_PATH_MAX - 1);
    directory = temp + 1;
    //ptemp[strlen(ptemp) - 1] = '\0';
    rTrim(directory, '/');
    //    directory=directory.Mid(directory.Find('/')+1,LIBUSB_PATH_MAX);
    //    directory.TrimRight("/");
  }
  
  //We're at a single level directory at this point... lets validate it
  if(strlen(directory) == 0)
    return TRUE;
  c=directory[0];
  if(! ( ((c>='a')&&(c<='z')) ||  ((c>='A')&&(c<='Z'))  || 
	 ((c>='0')&&(c<='9')) || (c=='_') || c=='/') ) {
    Log(ERROR, "//not liking the first character of this directory!");
    //the camcorder's CD command created directories if they're not
    //there... best to be prudent and assume it's some kind of error.
    return FALSE;
  }
  
  //validation is done... we can procede with the actual command stuff.
  memset(&data,0x00,LIBUSB_PATH_MAX);
  strcpy(data,directory);
  
  if(ControlMessageWrite(0xb800,data, strlen(data)+1,TIMEOUT)==TRUE) {
    return TRUE;
  }
  Log(ERROR, "change directory to %s failed", directory);
  return FALSE;
}
Beispiel #7
0
std::string StringUtil::trim(const std::string& str,const std::string& spaces)
{
	return lTrim(rTrim(str,spaces),spaces);
}