static int match_multi_number(unsigned long num, char c, const char *date, char *end, struct tm *tm, time_t now) { struct tm now_tm; struct tm *refuse_future; long num2, num3; num2 = strtol(end+1, &end, 10); num3 = -1; if (*end == c && isdigit(end[1])) num3 = strtol(end+1, &end, 10); /* Time? Date? */ switch (c) { case ':': if (num3 < 0) num3 = 0; if (num < 25 && num2 >= 0 && num2 < 60 && num3 >= 0 && num3 <= 60) { tm->tm_hour = num; tm->tm_min = num2; tm->tm_sec = num3; break; } return 0; case '-': case '/': case '.': if (!now) now = time(NULL); refuse_future = NULL; if (gmtime_r(&now, &now_tm)) refuse_future = &now_tm; if (num > 70) { /* yyyy-mm-dd? */ if (is_date(num, num2, num3, NULL, now, tm)) break; /* yyyy-dd-mm? */ if (is_date(num, num3, num2, NULL, now, tm)) break; } /* Our eastern European friends say dd.mm.yy[yy] * is the norm there, so giving precedence to * mm/dd/yy[yy] form only when separator is not '.' */ if (c != '.' && is_date(num3, num, num2, refuse_future, now, tm)) break; /* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */ if (is_date(num3, num2, num, refuse_future, now, tm)) break; /* Funny European mm.dd.yy */ if (c == '.' && is_date(num3, num, num2, refuse_future, now, tm)) break; return 0; } return end - date; }
dtype guess_type (char *buf) { int len; char *end; float x; dtype ret; len = strlen (buf); x = strtod (buf, &end); if (end != &buf[len]) { // Not parsable as a float // Could be a date or a factor if (is_date(buf) != -1) { // Its a date ret = Date; } else { // A factor ret = Factor; } } else { ret = Numeric; } return (ret); }
void test_cell_formatted_as_date2() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::datetime::today()); cell.value("testme"); xlnt_assert(!cell.is_date()); xlnt_assert(cell.value<std::string>() == "testme"); }
void test_cell_formatted_as_date3() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::datetime::today()); cell.value(true); xlnt_assert(!cell.is_date()); xlnt_assert(cell.value<bool>() == true); }
void test_cell_formatted_as_date1() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::datetime::today()); cell.clear_value(); xlnt_assert(!cell.is_date()); // disagree with openpyxl xlnt_assert(!cell.has_value()); }
int main(int argc,char** argv) { if(argc != 2){ printf("Use: ./lab11 <file.txt>\n"); } FILE* fp = fopen(argv[1],"r"); if(fp == NULL){ printf("Failed to open the selected file.\n"); return 0; } char buff[MAX_LINE+1]; while(fgets(buff,MAX_LINE,fp)){ if(buff[strlen(buff)-1] == '\n'){ buff[strlen(buff)-1] = '\0'; } char* token = strtok(buff," \n\r\t"); while(token != NULL){ if(is_phone_number(token)) { printf("\nPhone Number: %s",token); } else if(is_date(token)){ printf(" Date: %s",token); } else if(looks_like_name(token)){ char* nextName = strtok(NULL," \n\r\t"); if(looks_like_name(nextName)){ printf("Name:%s %s\n",nextName,token); } else token = nextName; } else if(is_email(token)){ printf("\nEmail: %s\n",token); } token = strtok(NULL," \n\r\t"); } } fclose(fp); return 0; }
void test_insert_time() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::time(1, 3)); xlnt_assert(cell.data_type() == xlnt::cell::type::number); xlnt_assert_delta(cell.value<long double>(), 0.04375L, 1E-9); xlnt_assert(cell.is_date()); xlnt_assert(cell.number_format().format_string() == "h:mm:ss"); }
void test_insert_date() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::date(2010, 7, 13)); xlnt_assert(cell.data_type() == xlnt::cell::type::number); xlnt_assert(cell.value<long double>() == 40372.L); xlnt_assert(cell.is_date()); xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd"); }
void test_timedelta() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::timedelta(1, 3, 0, 0, 0)); xlnt_assert(cell.value<long double>() == 1.125); xlnt_assert(cell.data_type() == xlnt::cell::type::number); xlnt_assert(!cell.is_date()); xlnt_assert(cell.number_format().format_string() == "[hh]:mm:ss"); }
void test_insert_datetime() { xlnt::workbook wb; auto ws = wb.active_sheet(); auto cell = ws.cell(xlnt::cell_reference(1, 1)); cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41)); xlnt_assert(cell.data_type() == xlnt::cell::type::number); xlnt_assert_delta(cell.value<long double>(), 40372.27616898148L, 1E-9); xlnt_assert(cell.is_date()); xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss"); }
Date::Date(int yy, Month mm, int dd) :y{yy},m{mm},d{dd} { if (!is_date(yy,mm,dd)) throw Invalid{}; }
bool DictInfo::save_ifo_file(void) const { if(ifo_file_name.empty()) { g_critical("Fail to save ifo file. ifo file name is not specified."); return false; } std::stringstream str; //str << UTF8_BOM; if(!is_infotype()) { g_critical("Fail to save ifo file. Dict info type is not specified."); return false; } const gchar *magic_data = NULL; if(infotype == DictInfoType_NormDict) magic_data = NORM_DICT_MAGIC_DATA; else if(infotype == DictInfoType_TreeDict) magic_data = TREE_DICT_MAGIC_DATA; else if(infotype == DictInfoType_ResDb) magic_data = RES_DB_MAGIC_DATA; else return false; str << magic_data << '\n'; if(!is_version()) { g_critical("Fail to save ifo file. version is not specified."); return false; } str << "version=" << version << '\n'; if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict) { if(!is_bookname()) { g_critical("Fail to save ifo file. bookname is not specified."); return false; } str << "bookname=" << bookname << '\n'; if(!is_wordcount()) { g_critical("Fail to save ifo file. wordcount is not specified."); return false; } str << "wordcount=" << wordcount << '\n'; } if(infotype == DictInfoType_NormDict) { if(is_synwordcount()) str << "synwordcount=" << synwordcount << '\n'; } if(infotype == DictInfoType_ResDb) { if(is_filecount()) str << "filecount=" << filecount << '\n'; } if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict || infotype == DictInfoType_ResDb) { if(!is_index_file_size()) { g_critical("Fail to save ifo file. index_file_size is not specified."); return false; } if(infotype == DictInfoType_NormDict) str << "idxfilesize=" << index_file_size << '\n'; if(infotype == DictInfoType_TreeDict) str << "tdxfilesize=" << index_file_size << '\n'; if(infotype == DictInfoType_ResDb) str << "ridxfilesize=" << index_file_size << '\n'; } if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict) { if(is_author()) str << "author=" << author << '\n'; if(is_email()) str << "email=" << email << '\n'; if(is_website()) str << "website=" << website << '\n'; if(is_description()) { std::string temp; encode_description(description.c_str(), description.length(), temp); str << "description=" << temp << '\n'; } if(is_date()) str << "date=" << date << '\n'; if(is_sametypesequence()) str << "sametypesequence=" << sametypesequence << '\n'; } if(infotype == DictInfoType_NormDict) { if(is_dicttype()) str << "dicttype=" << dicttype << '\n'; } if(!g_file_set_contents(ifo_file_name.c_str(), str.str().c_str(), -1, NULL)) { g_critical("Fail to save ifo file." open_write_file_err, ifo_file_name.c_str()); return false; } return true; }