File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * util.cpp
3
+ *
4
+ * Created on: Dec 17, 2017
5
+ * Author: frank
6
+ */
7
+
8
+
9
+ #include " util.hpp"
10
+
11
+ namespace httpsserver {
12
+
13
+ int parseInt (std::string s) {
14
+ int i = 0 ; // value
15
+ int m = 1 ; // multiplier
16
+
17
+ // Check sign
18
+ size_t x = 0 ;
19
+ if (s[0 ]==' -' ) {
20
+
21
+ x = 1 ;
22
+ } else if (s[0 ]==' +' ) {
23
+ x = 1 ;
24
+ }
25
+
26
+ // Convert by base 10
27
+ for (; x < s.size (); x++) {
28
+ char c = s[x];
29
+ if (c >= ' 0' && c<=' 9' ) {
30
+ i = i*10 + (c-' 0' );
31
+ } else {
32
+ break ;
33
+ }
34
+ }
35
+
36
+ // Combine both.
37
+ return m*i;
38
+ }
39
+
40
+ std::string intToString (int i) {
41
+ // We need this much digits
42
+ int digits = ceil (log10 (i));
43
+ char c[digits+1 ];
44
+ c[digits] = ' \0 ' ;
45
+
46
+ for (int x = digits-1 ; x >= 0 ; x--) {
47
+ char v = (i%10 );
48
+ c[x] = ' 0' + v;
49
+ i = (i-v)/10 ;
50
+ }
51
+
52
+ return std::string (c);
53
+ }
54
+
55
+
56
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * util.h
3
+ *
4
+ * Created on: Dec 17, 2017
5
+ * Author: frank
6
+ */
7
+
8
+ #ifndef HTTPS_UTIL_HPP_
9
+ #define HTTPS_UTIL_HPP_
10
+
11
+ #include < Arduino.h>
12
+
13
+ #include < cmath>
14
+ #include < string>
15
+
16
+ namespace httpsserver {
17
+
18
+ int parseInt (std::string s);
19
+
20
+ std::string intToString (int i);
21
+
22
+ }
23
+
24
+ #endif /* HTTPS_UTIL_HPP_ */
You can’t perform that action at this time.
0 commit comments