-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.cpp
More file actions
31 lines (29 loc) · 828 Bytes
/
Copy pathcheck.cpp
File metadata and controls
31 lines (29 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <cmath>
#include "check.hpp"
bool consist_of(std::string str, std::string range){
// 判断str是否仅由range中的字符组成
for (int i = 0; i < str.length(); i++){
if (std::string::npos == range.find(str[i])){
return false;
}
}
return true;
}
std::string type_of (std::string value){
// 判断以字符串表示的value的类型,需要保证该值是有效的
if (consist_of(value, "+-1234567890.")){
// 数字组成
if (std::string::npos == value.find('.'))
return "integer";
else
return "real";
}
else if(3 == value.length() and '\'' == value[0] and '\'' == value[2] and isalpha(value[1])){
return "char";
}
else{
return "id";
}
}