-
Notifications
You must be signed in to change notification settings - Fork 24
/
JsonKey.cpp
81 lines (64 loc) · 1.07 KB
/
JsonKey.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
Project: 1Sheeld Library
File: JsonKey.cpp
Version: 1.4
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2015.1
*/
#include "JsonKey.h"
JsonKey::JsonKey(int key)
{
number=key;
isText=false;
}
/* Copy Constructor */
JsonKey::JsonKey(const JsonKey & old)
{
isText=old.isText;
if(isText)
{
int textSize=strlen(old.text);
text=(char *)malloc(sizeof(char)*(textSize+1));
for (int i = 0; i < textSize; i++)
{
text[i]=old.text[i];
}
text[textSize]='\0';
}
else
{
number=old.number;
}
}
JsonKey::JsonKey(const char * key)
{
int textSize=strlen(key);
text=(char *)malloc(sizeof(char)*(textSize+1));
for (int i = 0; i < textSize; i++)
{
text[i]=key[i];
}
text[textSize]='\0';
isText=true;
}
bool JsonKey::isString()
{
return isText;
}
bool JsonKey::isNumber()
{
return !isText;
}
const char * JsonKey::getString()
{
return text;
}
int JsonKey::getNumber()
{
return number;
}
JsonKey::~JsonKey()
{
if(isText)free(text);
}