当前位置:网站首页>Quelques fonctions d'outils couramment utilisées au travail
Quelques fonctions d'outils couramment utilisées au travail
2022-06-23 23:45:00 【Aloe ennuyeuse】
Du code source du client de la machine de chiffrement qu'il a écrit,Inclure la vérification du format heure - date,IPVérification,Conversion de taille,Recherche de fichiers, etc
#include"util.h"
#include<string>
#include"Language.h"
//Appuyez sur Entrée pour quitter
void GETCHAR()
{
cout<< Language::Instance()->GetContent(OutMessage::PressEnter) <<endl;
cin.ignore();//Parce qu'une fonction de rappel renvoie,Le contenu du tampon doit être ignoré
getchar();
}
//Non, non.getch()Implémenter l'entrée du mot de passe,Echo as*,Maximum inputable16Nombre de chiffres, Laissez le mot de passe*No de sortie
#define BACKSPACE 0x08 //Supprimer la cléasccllValeur du Code
char* InputCode(char *pass)
{
int i = 0;
system("stty -icanon"); //Mise en place d'une opération de lecture unique,C'est - à - dire:getchar()Vous pouvez obtenir des caractères sans rentrer
system("stty -echo"); //Désactiver Echo,C'est - à - dire qu'aucun caractère entré n'est affiché
while(i < 16)
{
pass[i]=getchar(); //Obtient la valeur du clavier dans le tableau
if(i == 0 && pass[i] == BACKSPACE)
{
i=0; // S'il n'y a pas de valeur au début ,Entrée Supprimer,Et, Pas de valeur
pass[i]='\0';
continue;
}
else if(pass[i] == BACKSPACE)
{
printf("\b \b"); //Si supprimé, Le curseur avance , Écraser l'espace d'entrée , Puis déplacez le curseur vers l'avant
pass[i]='\0';
i=i-1; // Retour à la valeur précédente continuer l'entrée
continue; //Fin du cycle actuel
}
else if(pass[i] == '\n') // Si vous appuyez sur Entrée ,Fin de l'entrée
{
pass[i]='\0';
break;
}
else
{
printf("*");
}
i++;
}
system("stty echo"); //Activer Echo
system("stty icanon"); // Fermer l'opération de lecture unique ,C'est - à - dire:getchar() Vous devez retourner pour obtenir des caractères
cout<<endl;
return pass; // Retour au résultat final
}
// Grande extrémité à petite extrémité
UINT reversebytes_UINT(UINT value)
{
return (value & 0x000000FFU) << 24 | (value & 0x0000FF00U) << 8 |
(value & 0x00FF0000U) >> 8 | (value & 0xFF000000U) >> 24;
}
//Entrée de jugementipEtmaskOui Non
bool IpValid(string str)
{
struct in_addr addr;
int ret;
ret = inet_pton(AF_INET, str.c_str(), &addr);
if( ret != 1 )
{
return false;
}
return true;
}
//Fonction de conversion du temps
long metis_strptime(char *str_time)
{
struct tm stm;
strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm);
long t = mktime(&stm);// Convertir le temps en 1970Année1Mois1 Le nombre de secondes écoulées depuis ,Retour en cas d'erreur-1.
return t;
}
// Conversion au niveau du Journal
string LogLevelConvert(BYTE level)
{
string strloglevel;
switch ((int)level)
{
case 0://
strloglevel = "Debug";
break;
case 1://
strloglevel = "Info";
break;
case 2://
strloglevel = "Warn";
break;
case 3://
strloglevel = "Error";
break;
case 4://
strloglevel = "Fatal";
break;
default:
cout << "LogLevelErreur d'entrée!" << endl;
break;
}
return strloglevel;
}
// Trouver des fichiers de mise à jour
int FindUpGradeFile(char *filename)
{
DIR *dir;
struct dirent *ptr;
string path = "./upgrade";
char *dirpath = (char*)(path.c_str());
char *filenames = (char*)".xml";
char *curfilename = NULL;
int findflag = 0;
if ((dir = opendir(dirpath)) == NULL)
{
perror("Open dir error...");
return -1;
}
while ((ptr = readdir(dir)) != NULL)// Lire à la fin du fichier catalogue renvoie NULL
{
curfilename = rindex(ptr->d_name, '.');
if (curfilename != NULL&& strcmp(curfilename, filenames) == 0)
{
//printf("find file name :%s\n", ptr->d_name); //ptr->d_name Pour le nom de fichier trouvé
findflag = 1;
break;
}
}
if (0 == findflag)
{
cout<< Language::Instance()->GetContent(OutMessage::NoUpgradeFile) <<endl;
return -1;
}
else
{
strcpy(filename, ptr->d_name);
//printf("Find the upgrade file is: %s\n", filename);
cout<< Language::Instance()->GetContent(OutMessage::FindUpgradeFile) << ptr->d_name <<endl;
}
closedir(dir);
return 0;
}
/* Sous - fonction de jugement du format temporel */
std::string trim(const std::string& str)
{
std::string::size_type pos = str.find_first_not_of(' ');
if (pos == std::string::npos) {
return str;
}
std::string::size_type pos2 = str.find_last_not_of(' ');
if (pos2 != std::string::npos) {
return str.substr(pos, pos2 - pos + 1);
}
return str.substr(pos);
}
void split(const std::string& str, std::vector<std::string>* ret_, std::string sep = ",")
{
if (str.empty()) {
return;
}
std::string tmp;
std::string::size_type pos_begin = str.find_first_not_of(sep);
std::string::size_type comma_pos = 0;
while (pos_begin != std::string::npos) {
comma_pos = str.find(sep, pos_begin);
if (comma_pos != std::string::npos) {
tmp = str.substr(pos_begin, comma_pos - pos_begin);
pos_begin = comma_pos + sep.length();
}
else {
tmp = str.substr(pos_begin);
pos_begin = comma_pos;
}
if (!tmp.empty()) {
ret_->push_back(tmp);
tmp.clear();
}
}
}
bool DateVerify(int year, int month, int day)
{
// L'année est limitée à 1970-2100,Peut être enlevé
if (year < 1970 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31)
{
return false;
}
switch (month) {
case 4:
case 6:
case 9:
case 11:
if (day > 30) {
// 4.6.9.11 Le nombre de jours par mois ne peut être supérieur à 30
return false;
}
break;
case 2:
{
bool bLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
if ((bLeapYear && day > 29) || (!bLeapYear && day > 28)) {
// Année bissextile2 Le mois ne peut pas être supérieur à 29Oh, mon Dieu.;Année civile2 Le mois ne peut pas être supérieur à 28Oh, mon Dieu.
return false;
}
}
break;
default:
break;
}
return true;
}
// Vérificationyyyy/mm/dd
bool CheckDateValid(const std::string& strDate)
{
std::string strPureDate = trim(strDate);
if (strPureDate.length() < 8 || strPureDate.length() > 10) {
return false;
}
std::vector<std::string> vecFields;
split(strPureDate, &vecFields, "-");
if (vecFields.size() != 3) {
return false;
}
// TODO: Il est préférable de déterminer si la conversion des caractères est réussie
int nYear = atoi(vecFields[0].c_str());
int nMonth = atoi(vecFields[1].c_str());
int nDay = atoi(vecFields[2].c_str());
return DateVerify(nYear, nMonth, nDay);
}
// VérificationHH:MM:SS
bool CheckTimeValid(const std::string& strTime)
{
std::string strPureTime = trim(strTime);
if (strPureTime.length() < 5 || strPureTime.length() > 8) {
return false;
}
std::vector<std::string> vecFields;
split(strPureTime, &vecFields, ":");
if (vecFields.size() != 3) {
return false;
}
int nHour = atoi(vecFields[0].c_str());
int nMinute = atoi(vecFields[1].c_str());
int nSecond = atoi(vecFields[2].c_str());
bool bValid = (nHour >= 0 && nHour <= 23);
bValid = bValid && (nMinute >= 0 && nMinute <= 59);
bValid = bValid && (nSecond >= 0 && nSecond <= 59);
return bValid;
}
// Le format de la date est: yyyy/mm/dd || yyyy/mm/dd HH:MM:SS yyyy-mm-dd HH:MM:SS
bool CheckDateTimeValid(const std::string& strDateTime)
{
std::string strPureDateTime = trim(strDateTime);
std::vector<std::string> vecFields;
split(strPureDateTime, &vecFields, " ");
if (vecFields.size() != 1 && vecFields.size() != 2) {
return false;
}
// Date seulement
if (vecFields.size() == 1) {
return CheckDateValid(vecFields[0]);
}
return CheckDateValid(vecFields[0]) && CheckTimeValid(vecFields[1]);
}
边栏推荐
- 6. STM32 - serial port data transceiver Foundation
- 在OpenCloudOS使用snap安装.NET 6
- AUTOCAD——总结CAD画圆角的三种方式
- Develop synergy and efficiently manage | community essay solicitation
- Androidkotlin comprehensive and detailed class usage grammar learning guide
- Bitmap加载内存分析
- 7、STM32——LCD
- HDLBits-&gt; Circuits-&gt; Arithmetic Circuitd-&gt; 3-bit binary adder
- iNFTnews | 创造者经济的未来在Web3世界中该去向何处?
- 网站如何在Google建立索引
猜你喜欢

【Xilinx AX7103 MicroBalze学习笔记6】MicroBlaze 自定义 IP 核封装实验

腾讯会议号设计的几种猜测

Image segmentation - data annotation

Can the characteristics of different network structures be compared? Ant & meituan & NTU & Ali proposed a cross architecture self supervised video representation learning method CaCl, performance SOTA

VS QT VTK 左下角显示同步小坐标轴

《德阳市餐饮服务业油烟污染防治管理办法(征求意见稿)》之创新油烟监管

6. STM32 - serial port data transceiver Foundation

Autofac详解

A cartoon reading app highly imitating Tencent comics

老龄化下背景下,综合能效管理平台为医院保驾护航
随机推荐
Math. Max() method obtains the maximum value in the array and returns Nan problem analysis
这个高仿小米商城项目太惊艳了
接私活必备的 6 个开源项目
Stm32----- timer
The lower left corner of vs QT VTK displays the synchronized minor coordinate axis
ORB_ Slam3 environment setup and demo demonstration
2018/GAN:Self-Attention Generative Adversarial Networks自我注意生成对抗网络
日化用品行业集团采购管理系统改变传统采购模式,降低采购成本
Solve the problem that slf4j logs are not printed
Le roman du drapeau de l'imitation haute version flutter, apprenez - le
Kotlin coroutine asynchronous flow
6. STM32 - serial port data transceiver Foundation
高仿书旗小说 Flutter 版,学起来
A person even ran a Weibo app
产线工控安全有什么好的解决方案
Kotlin 协程 异步 异步流
Loop caused by add of sublist in list
2022 Shandong Health Expo, Jinan International Health Industry Expo, China Nutrition and Health Exhibition
再来一个高仿开眼的短视频APP
Postman return value Chinese garbled????