Пример #1
0
string Token::caseNotDigit(string str) {
	vector<string> v;
	size_t t = 0;
	split(v, str, separators_text);
	if (v.size() > 1) {
		str = "";
		while (t < v.size()) {
			candidates.push_back(v[t]);
			if (v.size() <= 4)
				str += v[t];
			t++;
		}
	}
	str = trim_right_copy(str, numbers);
	if (whatIsIt(str) == GARBAGE)
		str = "";
	return str;
}
Пример #2
0
 bool FAT::int_dirent(
     uint32_t  sector,
     const void* data, 
     dirvec_t dirents)
 {
     auto* root = (cl_dir*) data;
     bool  found_last = false;
     
     for (int i = 0; i < 16; i++)
     {
       if (unlikely(root[i].shortname[0] == 0x0))
       {
         //printf("end of dir\n");
         found_last = true;
         // end of directory
         break;
       }
       else if (unlikely(root[i].shortname[0] == 0xE5))
       {
         // unused index
       }
       else
       {
           // traverse long names, then final cluster
           // to read all the relevant info
           
           if (likely(root[i].is_longname()))
           {
             auto* L = (cl_long*) &root[i];
             // the last long index is part of a chain of entries
             if (L->is_last())
             {
               // buffer for long filename
               char final_name[256];
               int  final_count = 0;
               
               int  total = L->long_index();
               // go to the last entry and work backwards
               i += total-1;
               L += total-1;
               
               for (int idx = total; idx > 0; idx--)
               {
                 uint16_t longname[13];
                 memcpy(longname+ 0, L->first, 10);
                 memcpy(longname+ 5, L->second, 12);
                 memcpy(longname+11, L->third, 4);
                 
                 for (int j = 0; j < 13; j++)
                 {
                   // 0xFFFF indicates end of name
                   if (unlikely(longname[j] == 0xFFFF)) break;
                   // sometimes, invalid stuff are snuck into filenames
                   if (unlikely(longname[j] == 0x0)) break;
                   
                   final_name[final_count] = longname[j] & 0xFF;
                   final_count++;
                 }
                 L--;
                 
                 if (unlikely(final_count > 240))
                 {
                   debug("Suspicious long name length, breaking...\n");
                   break;
                 }
               }
               
               final_name[final_count] = 0;
               debug("Long name: %s\n", final_name);
               
               i++; // skip over the long version
               // to the short version for the stats and cluster
               auto* D = &root[i];
               std::string dirname(final_name, final_count);
               dirname = trim_right_copy(dirname);
               
               dirents->emplace_back(
                 D->type(), 
                 dirname, 
                 D->dir_cluster(root_cluster), 
                 sector, // parent block
                 D->size(), 
                 D->attrib);
             }
           }
           else
           {
             auto* D = &root[i];
             debug("Short name: %.11s\n", D->shortname);
             
             std::string dirname((char*) D->shortname, 11);
             dirname = trim_right_copy(dirname);
             
             dirents->emplace_back(
               D->type(), 
               dirname, 
               D->dir_cluster(root_cluster), 
               sector, // parent block
               D->size(), 
               D->attrib);
           }
       }
     } // directory list
     
     return found_last;
 }
Пример #3
0
string trim_copy(
        const string& s,
        const string& delimiters = " \f\n\r\t\v" )
{
    return trim_left_copy( trim_right_copy( s, delimiters ), delimiters );
}