Skip to content

Commit 1dc1ccd

Browse files
committed
Merge pull request FirebaseExtended#169 from ed7coyne/remove-arduino-string
Drop Arduino strings on our internal libraries.
2 parents 74a963a + 1b418d7 commit 1dc1ccd

24 files changed

+205
-167
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
PUSH /seria/push_test "this is a test string \ "
1+
PUSH /serial/push_test "this is a test string \ "

src/Firebase.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
using std::unique_ptr;
1919

2020
namespace {
21-
String makeFirebaseURL(const String& path, const String& auth) {
22-
String url;
21+
std::string makeFirebaseURL(const std::string& path, const std::string& auth) {
22+
std::string url;
2323
if (path[0] != '/') {
2424
url = "/";
2525
}
@@ -32,71 +32,71 @@ String makeFirebaseURL(const String& path, const String& auth) {
3232

3333
} // namespace
3434

35-
Firebase::Firebase(const String& host, const String& auth) : host_(host), auth_(auth) {
35+
Firebase::Firebase(const std::string& host, const std::string& auth) : host_(host), auth_(auth) {
3636
http_.reset(FirebaseHttpClient::create());
3737
http_->setReuseConnection(true);
3838
}
3939

40-
const String& Firebase::auth() const {
40+
const std::string& Firebase::auth() const {
4141
return auth_;
4242
}
4343

44-
FirebaseGet Firebase::get(const String& path) {
44+
FirebaseGet Firebase::get(const std::string& path) {
4545
return FirebaseGet(host_, auth_, path, http_.get());
4646
}
4747

48-
unique_ptr<FirebaseGet> Firebase::getPtr(const String& path) {
48+
unique_ptr<FirebaseGet> Firebase::getPtr(const std::string& path) {
4949
return unique_ptr<FirebaseGet>(new FirebaseGet(host_, auth_, path, http_.get()));
5050
}
5151

52-
FirebaseSet Firebase::set(const String& path, const String& value) {
52+
FirebaseSet Firebase::set(const std::string& path, const std::string& value) {
5353
return FirebaseSet(host_, auth_, path, value, http_.get());
5454
}
5555

56-
unique_ptr<FirebaseSet> Firebase::setPtr(const String& path,
57-
const String& value) {
56+
unique_ptr<FirebaseSet> Firebase::setPtr(const std::string& path,
57+
const std::string& value) {
5858
return unique_ptr<FirebaseSet>(
5959
new FirebaseSet(host_, auth_, path, value, http_.get()));
6060
}
6161

62-
FirebasePush Firebase::push(const String& path, const String& value) {
62+
FirebasePush Firebase::push(const std::string& path, const std::string& value) {
6363
return FirebasePush(host_, auth_, path, value, http_.get());
6464
}
65-
unique_ptr<FirebasePush> Firebase::pushPtr(const String& path, const String& value) {
65+
unique_ptr<FirebasePush> Firebase::pushPtr(const std::string& path, const std::string& value) {
6666
return unique_ptr<FirebasePush>(
6767
new FirebasePush(host_, auth_, path, value, http_.get()));
6868
}
6969

70-
FirebaseRemove Firebase::remove(const String& path) {
70+
FirebaseRemove Firebase::remove(const std::string& path) {
7171
return FirebaseRemove(host_, auth_, path, http_.get());
7272
}
7373

74-
unique_ptr<FirebaseRemove> Firebase::removePtr(const String& path) {
74+
unique_ptr<FirebaseRemove> Firebase::removePtr(const std::string& path) {
7575
return unique_ptr<FirebaseRemove>(
7676
new FirebaseRemove(host_, auth_, path, http_.get()));
7777
}
7878

79-
FirebaseStream Firebase::stream(const String& path) {
79+
FirebaseStream Firebase::stream(const std::string& path) {
8080
// TODO: create new client dedicated to stream.
8181
return FirebaseStream(host_, auth_, path, http_.get());
8282
}
8383

84-
unique_ptr<FirebaseStream> Firebase::streamPtr(const String& path) {
84+
unique_ptr<FirebaseStream> Firebase::streamPtr(const std::string& path) {
8585
// TODO: create new client dedicated to stream.
8686
return unique_ptr<FirebaseStream>(
8787
new FirebaseStream(host_, auth_, path, http_.get()));
8888
}
8989

9090
// FirebaseCall
91-
FirebaseCall::FirebaseCall(const String& host, const String& auth,
92-
const char* method, const String& path,
93-
const String& data, FirebaseHttpClient* http) : http_(http) {
94-
String path_with_auth = makeFirebaseURL(path, auth);
91+
FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth,
92+
const char* method, const std::string& path,
93+
const std::string& data, FirebaseHttpClient* http) : http_(http) {
94+
std::string path_with_auth = makeFirebaseURL(path, auth);
9595
http_->setReuseConnection(true);
9696
http_->begin(host, path_with_auth);
9797

9898
bool followRedirect = false;
99-
if (String(method) == "STREAM") {
99+
if (std::string(method) == "STREAM") {
100100
method = "GET";
101101
http_->addHeader("Accept", "text/event-stream");
102102
followRedirect = true;
@@ -112,18 +112,18 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
112112
// TODO: Add a max redirect check
113113
if (followRedirect) {
114114
while (status == HttpStatus::TEMPORARY_REDIRECT) {
115-
String location = http_->header("Location");
115+
std::string location = http_->header("Location");
116116
http_->setReuseConnection(false);
117117
http_->end();
118118
http_->setReuseConnection(true);
119119
http_->begin(location);
120-
status = http_->sendRequest("GET", String());
120+
status = http_->sendRequest("GET", std::string());
121121
}
122122
}
123123

124124
if (status != 200) {
125125
error_ = FirebaseError(status,
126-
String(method) + " " + path_with_auth +
126+
std::string(method) + " " + path_with_auth +
127127
": " + http_->errorToString(status));
128128
}
129129

@@ -137,19 +137,19 @@ const JsonObject& FirebaseCall::json() {
137137
//TODO(edcoyne): This is not efficient, we should do something smarter with
138138
//the buffers.
139139
buffer_ = DynamicJsonBuffer();
140-
return buffer_.parseObject(response());
140+
return buffer_.parseObject(response().c_str());
141141
}
142142

143143
// FirebaseGet
144-
FirebaseGet::FirebaseGet(const String& host, const String& auth,
145-
const String& path,
144+
FirebaseGet::FirebaseGet(const std::string& host, const std::string& auth,
145+
const std::string& path,
146146
FirebaseHttpClient* http)
147147
: FirebaseCall(host, auth, "GET", path, "", http) {
148148
}
149149

150150
// FirebaseSet
151-
FirebaseSet::FirebaseSet(const String& host, const String& auth,
152-
const String& path, const String& value,
151+
FirebaseSet::FirebaseSet(const std::string& host, const std::string& auth,
152+
const std::string& path, const std::string& value,
153153
FirebaseHttpClient* http)
154154
: FirebaseCall(host, auth, "PUT", path, value, http) {
155155
if (!error()) {
@@ -158,8 +158,8 @@ FirebaseSet::FirebaseSet(const String& host, const String& auth,
158158
}
159159
}
160160
// FirebasePush
161-
FirebasePush::FirebasePush(const String& host, const String& auth,
162-
const String& path, const String& value,
161+
FirebasePush::FirebasePush(const std::string& host, const std::string& auth,
162+
const std::string& path, const std::string& value,
163163
FirebaseHttpClient* http)
164164
: FirebaseCall(host, auth, "POST", path, value, http) {
165165
if (!error()) {
@@ -168,15 +168,15 @@ FirebasePush::FirebasePush(const String& host, const String& auth,
168168
}
169169

170170
// FirebasePush
171-
FirebaseRemove::FirebaseRemove(const String& host, const String& auth,
172-
const String& path,
171+
FirebaseRemove::FirebaseRemove(const std::string& host, const std::string& auth,
172+
const std::string& path,
173173
FirebaseHttpClient* http)
174174
: FirebaseCall(host, auth, "DELETE", path, "", http) {
175175
}
176176

177177
// FirebaseStream
178-
FirebaseStream::FirebaseStream(const String& host, const String& auth,
179-
const String& path,
178+
FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth,
179+
const std::string& path,
180180
FirebaseHttpClient* http)
181181
: FirebaseCall(host, auth, "STREAM", path, "", http) {
182182
}
@@ -185,18 +185,18 @@ bool FirebaseStream::available() {
185185
return http_->getStreamPtr()->available();
186186
}
187187

188-
FirebaseStream::Event FirebaseStream::read(String& event) {
188+
FirebaseStream::Event FirebaseStream::read(std::string& event) {
189189
auto client = http_->getStreamPtr();
190190
Event type;
191-
String typeStr = client->readStringUntil('\n').substring(7);
191+
std::string typeStr = client->readStringUntil('\n').substring(7).c_str();
192192
if (typeStr == "put") {
193193
type = Event::PUT;
194194
} else if (typeStr == "patch") {
195195
type = Event::PATCH;
196196
} else {
197197
type = Event::UNKNOWN;
198198
}
199-
event = client->readStringUntil('\n').substring(6);
199+
event = client->readStringUntil('\n').substring(6).c_str();
200200
client->readStringUntil('\n'); // consume separator
201201
return type;
202202
}

src/Firebase.h

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,67 +37,67 @@ class FirebaseStream;
3737
// Firebase REST API client.
3838
class Firebase {
3939
public:
40-
Firebase(const String& host, const String& auth = "");
40+
Firebase(const std::string& host, const std::string& auth = "");
4141

42-
const String& auth() const;
42+
const std::string& auth() const;
4343

4444
// Fetch json encoded `value` at `path`.
45-
FirebaseGet get(const String& path);
46-
virtual std::unique_ptr<FirebaseGet> getPtr(const String& path);
45+
FirebaseGet get(const std::string& path);
46+
virtual std::unique_ptr<FirebaseGet> getPtr(const std::string& path);
4747

4848
// Set json encoded `value` at `path`.
49-
FirebaseSet set(const String& path, const String& json);
50-
virtual std::unique_ptr<FirebaseSet> setPtr(const String& path, const String& json);
49+
FirebaseSet set(const std::string& path, const std::string& json);
50+
virtual std::unique_ptr<FirebaseSet> setPtr(const std::string& path, const std::string& json);
5151

5252
// Add new json encoded `value` to list at `path`.
53-
FirebasePush push(const String& path, const String& json);
54-
virtual std::unique_ptr<FirebasePush> pushPtr(const String& path, const String& json);
53+
FirebasePush push(const std::string& path, const std::string& json);
54+
virtual std::unique_ptr<FirebasePush> pushPtr(const std::string& path, const std::string& json);
5555

5656
// Delete value at `path`.
57-
FirebaseRemove remove(const String& path);
58-
virtual std::unique_ptr<FirebaseRemove> removePtr(const String& path);
57+
FirebaseRemove remove(const std::string& path);
58+
virtual std::unique_ptr<FirebaseRemove> removePtr(const std::string& path);
5959

6060
// Start a stream of events that affect value at `path`.
61-
FirebaseStream stream(const String& path);
62-
virtual std::unique_ptr<FirebaseStream> streamPtr(const String& path);
61+
FirebaseStream stream(const std::string& path);
62+
virtual std::unique_ptr<FirebaseStream> streamPtr(const std::string& path);
6363

6464
protected:
6565
// Used for testing.
6666
Firebase() {}
6767

6868
private:
6969
std::unique_ptr<FirebaseHttpClient> http_;
70-
String host_;
71-
String auth_;
70+
std::string host_;
71+
std::string auth_;
7272
};
7373

7474
class FirebaseError {
7575
public:
7676
FirebaseError() {}
77-
FirebaseError(int code, const String& message) : code_(code), message_(message) {
77+
FirebaseError(int code, const std::string& message) : code_(code), message_(message) {
7878
}
7979
operator bool() const { return code_ != 0; }
8080
int code() const { return code_; }
81-
const String& message() const { return message_; }
81+
const std::string& message() const { return message_; }
8282
private:
8383
int code_ = 0;
84-
String message_ = "";
84+
std::string message_ = "";
8585
};
8686

8787
class FirebaseCall {
8888
public:
8989
FirebaseCall() {}
90-
FirebaseCall(const String& host, const String& auth,
91-
const char* method, const String& path,
92-
const String& data = "",
90+
FirebaseCall(const std::string& host, const std::string& auth,
91+
const char* method, const std::string& path,
92+
const std::string& data = "",
9393
FirebaseHttpClient* http = NULL);
9494
virtual ~FirebaseCall() {}
9595

9696
virtual const FirebaseError& error() const {
9797
return error_;
9898
}
9999

100-
virtual const String& response() const {
100+
virtual const std::string& response() const {
101101
return response_;
102102
}
103103

@@ -106,59 +106,59 @@ class FirebaseCall {
106106
protected:
107107
FirebaseHttpClient* http_;
108108
FirebaseError error_;
109-
String response_;
109+
std::string response_;
110110
DynamicJsonBuffer buffer_;
111111
};
112112

113113
class FirebaseGet : public FirebaseCall {
114114
public:
115115
FirebaseGet() {}
116-
FirebaseGet(const String& host, const String& auth,
117-
const String& path, FirebaseHttpClient* http = NULL);
116+
FirebaseGet(const std::string& host, const std::string& auth,
117+
const std::string& path, FirebaseHttpClient* http = NULL);
118118

119119
private:
120-
String json_;
120+
std::string json_;
121121
};
122122

123123
class FirebaseSet: public FirebaseCall {
124124
public:
125125
FirebaseSet() {}
126-
FirebaseSet(const String& host, const String& auth,
127-
const String& path, const String& value, FirebaseHttpClient* http = NULL);
126+
FirebaseSet(const std::string& host, const std::string& auth,
127+
const std::string& path, const std::string& value, FirebaseHttpClient* http = NULL);
128128

129129

130130
private:
131-
String json_;
131+
std::string json_;
132132
};
133133

134134
class FirebasePush : public FirebaseCall {
135135
public:
136136
FirebasePush() {}
137-
FirebasePush(const String& host, const String& auth,
138-
const String& path, const String& value, FirebaseHttpClient* http = NULL);
137+
FirebasePush(const std::string& host, const std::string& auth,
138+
const std::string& path, const std::string& value, FirebaseHttpClient* http = NULL);
139139
virtual ~FirebasePush() {}
140140

141-
virtual const String& name() const {
141+
virtual const std::string& name() const {
142142
return name_;
143143
}
144144

145145
private:
146-
String name_;
146+
std::string name_;
147147
};
148148

149149
class FirebaseRemove : public FirebaseCall {
150150
public:
151151
FirebaseRemove() {}
152-
FirebaseRemove(const String& host, const String& auth,
153-
const String& path, FirebaseHttpClient* http = NULL);
152+
FirebaseRemove(const std::string& host, const std::string& auth,
153+
const std::string& path, FirebaseHttpClient* http = NULL);
154154
};
155155

156156

157157
class FirebaseStream : public FirebaseCall {
158158
public:
159159
FirebaseStream() {}
160-
FirebaseStream(const String& host, const String& auth,
161-
const String& path, FirebaseHttpClient* http = NULL);
160+
FirebaseStream(const std::string& host, const std::string& auth,
161+
const std::string& path, FirebaseHttpClient* http = NULL);
162162
virtual ~FirebaseStream() {}
163163

164164
// Return if there is any event available to read.
@@ -171,7 +171,7 @@ class FirebaseStream : public FirebaseCall {
171171
PATCH
172172
};
173173

174-
static inline String EventToName(Event event) {
174+
static inline std::string EventToName(Event event) {
175175
switch(event) {
176176
case UNKNOWN:
177177
return "UNKNOWN";
@@ -185,7 +185,7 @@ class FirebaseStream : public FirebaseCall {
185185
}
186186

187187
// Read next json encoded `event` from stream.
188-
virtual Event read(String& event);
188+
virtual Event read(std::string& event);
189189

190190
const FirebaseError& error() const {
191191
return _error;

0 commit comments

Comments
 (0)