-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
31 lines (25 loc) · 803 Bytes
/
utils.h
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
//===========================================================
// utils.h
//-----------------------------------------------------------
//===========================================================
#ifndef __utils_h__
#define __utils_h__
class Utils {
public:
static char* strconvert(char* s, int (*fp)(int)) { // strconvert(s, toupper); // strconvert(s, tolower);
char* p = s;
while (*p != '\0') { *p = fp(*p); ++p; }
return s;
}
static char* strstrip(char* s) { // "1, 2, 3, 4" ==> // "1 2 3 4"
char* p = s;
while (*p != '\0') {
if ((isalnum(*p) || isspace(*p)) && !ispunct(*p)) { *s++ = *p++; }
else { ++p; }
}
*s = '\0';
return s;
}
static const char* yes_or_no(bool condition) { return (condition? "YES" : "no"); }
};
#endif