Exemple #1
0
char *
execute_get_external_cmd_opts_from_config (const char *command, const vfs_path_t * filename_vpath,
                                           long start_line)
{
    char *str_from_config, *return_str;
    char *parameter;

    if (filename_vpath == NULL)
        return g_strdup ("");

    parameter = g_shell_quote (vfs_path_get_last_path_str (filename_vpath));

    if (start_line <= 0)
        return parameter;

    str_from_config = execute_get_opts_from_cfg (command, "%filename");

    return_str = str_replace_all (str_from_config, "%filename", parameter);
    g_free (parameter);
    g_free (str_from_config);
    str_from_config = return_str;

    parameter = g_strdup_printf ("%ld", start_line);
    return_str = str_replace_all (str_from_config, "%lineno", parameter);
    g_free (parameter);
    g_free (str_from_config);

    return return_str;
}
Exemple #2
0
///////////////////////////////////////////////////////////////////////////////
/// @fn time_t str_to_time(string date)
/// @brief returns a time_t object made from the passed in string
/// @param date is a string in the format MM/DD/YYYY to turn into a time_t
/// @ret time_t ojbect made from the passed in date
///////////////////////////////////////////////////////////////////////////////
time_t validate::str_to_time(string date) {

  // Storage for what we return.
  time_t return_time;

  // Store the current time, too.
  time_t now;
  time(&now);

  // Current tm, too.
  tm now_tm;
  // Yeah, I'm dereferencing a function.
  now_tm = *localtime(&now);

  // tm structure for easier storage.
  // Initialize to "now" for day/month/year, if any are missing.
  tm date_tm(now_tm);

  // We don't need these three values.
  date_tm.tm_hour = 0;
  date_tm.tm_min = 0;
  date_tm.tm_sec = 0;

  // Clear out any ambiguity.
  date = str_strip(date, " ", true, true, true);
  date = str_replace_all(date, "-", "/");
  date = str_replace_all(date, ".", "/");
  date = str_replace_all(date, "\\", "/");
  date = str_replace_all(date, "|", "/");
  date = str_replace_all(date, "_", "/");

  vector<string> values = str_find_lines(date, "/", false);

  if (values.size() >= 1) {

    // tm stores months as 0-11
    date_tm.tm_mon = str_to_int(values[0]) - 1;

  }

  if (values.size() >= 2) {

    date_tm.tm_mday = str_to_int(values[1]);

  }

  if (values.size() >= 3) {

    // tm stores years as the distance from 1900
    date_tm.tm_year = str_to_int(values[2]) - 1900;

  }

  return_time = mktime(&date_tm);

  return return_time;

}
bool Classifier::addVocab( const vector<Document>& docs, 
                           map<string, unsigned int>& vocab ) {
  // Construct list of tokens to ignore.
  vector<string> tokensToIgnore;
  try {
    if ( useIgnoreList == true ) {
      string tokenFileLoc = ignoreFileLoc;
      #ifdef WINDOWS
        tokenFileLoc = str_replace_all( tokenFileLoc, "/", "\\", ':' );
      #endif
      string line;
      ifstream tokenFile( tokenFileLoc.c_str() );
      
      while ( tokenFile.good() ) {
        getline( tokenFile, line );
        if ( line != "" ) {
          tokensToIgnore.push_back( line );
        }
      }
      tokenFile.close();
    }
    if ( useStopWordsList == true ) {
      string tokenFileLoc = stopFileLoc;
      #ifdef WINDOWS
        tokenFileLoc = str_replace_all( tokenFileLoc, "/", "\\", ':' );
      #endif
      string line;
      ifstream tokenFile( tokenFileLoc.c_str() );
      
      while ( tokenFile.good() ) {
        getline( tokenFile, line );
        if ( line != "" ) {
          tokensToIgnore.push_back( line );
        }
      }
      tokenFile.close();
    }
  }

  catch ( exception& e ) {
    cout << e.what() << endl;
    return false;
  }
  
  for ( unsigned int i = 0; i < docs.size(); i++ ) {
    vector<string> tokens;
    tokenizeDocument( docs[i], vocabDelimiters, tokensToIgnore, minTokenSize, tokens );

    for ( unsigned int j = 0; j < tokens.size(); j++ ) {
      vocab[tokens[j]]++;
    }
  }

  return true;
}
int main (void){
	char a[] = "hello";
	char b[] = "goodbye";
	char c[] = "world";
	printf("%d\n",str_all_alphabets(a)==1);
	printf("%d\n",str_all_alphabets(b)==1);
	printf("%d\n",str_all_alphabets(c)==1);
	printf("%d\n",str_has_alphabet(a)==1);
	printf("%d\n",str_has_alphabet(b)==1);
	printf("%d\n",str_has_alphabet(c)==1);
	printf("%d\n",str_replace_all(a, 'e', 'q')==1);
	printf("%d\n",str_replace_all(b,'e', 'q')==1);
	printf("%d\n",str_replace_all(c, 'r', 'q')==1);
	printf("%d\n",str_replace_first(a, 'o', 'f')==1);
	printf("%d\n",str_replace_first(b,'o', 'f')==1);
	printf("%d\n",str_replace_first(c, 'o', 'f')==1);
	printf("%d\n",str_replace_last(a, 'l', 'f')==1);
	printf("%d\n",str_replace_last(b, 'o', 'f')==1);
	printf("%d\n",str_replace_last(c, 'd', 'f')==1);
	return 0;
}
Exemple #5
0
string get_tool_path(int tool, ConfigSection* tools) {
	string path(tools->getOptionString(tool));
	string::size_type pos = path.find(',');
	if (pos != string::npos) {
		path.erase(pos);
	}
	pos = path.find(';');
	if (pos != string::npos) {
		path.erase(pos);
	}
	str_replace_all(path, "$EXELOC", GLE_BIN_DIR.c_str());
	return GLEExpandEnvironmentVariables(path);
}
int main(void){
	int *m;
	size_t n = 5,j=0;
	int a[]={3,2,2,3,2};
	char x[]={"hello"};
	char *b;
	
	m=arr_last_max(a,n);
	j=str_replace_all(x,'l','f');
	b=str_find_last(x,'o');
	
	printf("%d\n",*m);
	printf("%d\n",j);
	printf("%c\n",*b);
	return 0;
}
Exemple #7
0
char* hotkeyTextToMacModifiers( char* keydesc )
{
    keydesc = copy( keydesc );
    keydesc = str_replace_all( keydesc, "Ctl", "⌘", 1 );
    keydesc = str_replace_all( keydesc, "Command", "⌘", 1 );
    keydesc = str_replace_all( keydesc, "Cmd", "⌘", 1 );
    keydesc = str_replace_all( keydesc, "Shft", "⇧", 1 );
    keydesc = str_replace_all( keydesc, "Alt", "⎇", 1 );
    keydesc = str_replace_all( keydesc, "+", "", 1 );
    return keydesc;
}
//////////////////////////////////////////////////////////////////////
/// @fn string str_replace_all()
/// @brief -- Overload of the all-string version
//////////////////////////////////////////////////////////////////////
string str_replace_all(string str, char to_replace, char replace_with, char ignore_following) {

  return str_replace_all(str, char_to_str(to_replace), char_to_str(replace_with), ignore_following);

}