-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCastString.cpp
More file actions
51 lines (40 loc) · 1019 Bytes
/
CastString.cpp
File metadata and controls
51 lines (40 loc) · 1019 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "CastString.h"
CastString::CastString(const String &str):
String(str) {
}
bool CastString::toBool(void) const {
if (equals("0") || equals("\0") || equalsIgnoreCase("false")) {
return false;
}
return true;
}
byte CastString::toByte(void) const {
if (buffer) return atoi(buffer);
return 0;
}
char CastString::toChar(void) const {
if (buffer) return buffer[0];
}
long CastString::toLong(void) const {
if (buffer) return atol(buffer);
return 0;
}
short CastString::toShort(void) const {
if (buffer) return (short)atoi(buffer);
return 0;
}
size_t CastString::toSize_t(void) const {
if (buffer) return (size_t)strtoul(buffer, NULL, 0);
}
unsigned char CastString::toUnsignedChar(void) const {
return (unsigned char)toChar();
}
unsigned int CastString::toUnsignedInt(void) const {
return (unsigned int)toInt();
}
unsigned long CastString::toUnsignedLong(void) const {
return (unsigned long)toLong();
}
word CastString::toWord(void) const {
return (word)toUnsignedInt();
}