Skip to content

Commit 4e5abc6

Browse files
committed
Merge branch 'master' into WiFiOffAtBoot
2 parents 20020c0 + 5ac64ff commit 4e5abc6

File tree

19 files changed

+326
-263
lines changed

19 files changed

+326
-263
lines changed

cores/esp8266/HardwareSerial.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,31 @@ class HardwareSerial: public Stream
101101
return uart_get_rx_buffer_size(_uart);
102102
}
103103

104-
void swap()
104+
bool swap()
105105
{
106-
swap(1);
106+
return swap(1);
107107
}
108-
void swap(uint8_t tx_pin) //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX
108+
bool swap(uint8_t tx_pin) //toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX
109109
{
110-
uart_swap(_uart, tx_pin);
110+
return uart_swap(_uart, tx_pin);
111111
}
112112

113113
/*
114114
* Toggle between use of GPIO1 and GPIO2 as TX on UART 0.
115115
* Note: UART 1 can't be used if GPIO2 is used with UART 0!
116116
*/
117-
void set_tx(uint8_t tx_pin)
117+
bool set_tx(uint8_t tx_pin)
118118
{
119-
uart_set_tx(_uart, tx_pin);
119+
return uart_set_tx(_uart, tx_pin);
120120
}
121121

122122
/*
123123
* UART 0 possible options are (1, 3), (2, 3) or (15, 13)
124124
* UART 1 allows only TX on 2 if UART 0 is not (2, 3)
125125
*/
126-
void pins(uint8_t tx, uint8_t rx)
126+
bool pins(uint8_t tx, uint8_t rx)
127127
{
128-
uart_set_pins(_uart, tx, rx);
128+
return uart_set_pins(_uart, tx, rx);
129129
}
130130

131131
int available(void) override;

cores/esp8266/StreamDev.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ class StreamConstPtr: public StreamNull
179179

180180
virtual int read() override
181181
{
182-
return _peekPointer < _size ? _buffer[_peekPointer++] : -1;
182+
// valid with dram, iram and flash
183+
return _peekPointer < _size ? pgm_read_byte(&_buffer[_peekPointer++]) : -1;
183184
}
184185

185186
virtual int peek() override
186187
{
187-
return _peekPointer < _size ? _buffer[_peekPointer] : -1;
188+
// valid with dram, iram and flash
189+
return _peekPointer < _size ? pgm_read_byte(&_buffer[_peekPointer]) : -1;
188190
}
189191

190192
virtual size_t readBytes(char* buffer, size_t len) override

cores/esp8266/StreamString.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ class StreamString: public String, public S2Stream
236236
StreamString(const String& string): String(string), S2Stream(this) { }
237237
StreamString(const __FlashStringHelper *str): String(str), S2Stream(this) { }
238238
StreamString(String&& string): String(string), S2Stream(this) { }
239-
StreamString(StringSumHelper&& sum): String(sum), S2Stream(this) { }
240239

241240
explicit StreamString(char c): String(c), S2Stream(this) { }
242241
explicit StreamString(unsigned char c, unsigned char base = 10): String(c, base), S2Stream(this) { }
@@ -281,13 +280,6 @@ class StreamString: public String, public S2Stream
281280
resetpp();
282281
return *this;
283282
}
284-
285-
StreamString& operator= (StringSumHelper&& rval)
286-
{
287-
String::operator=(rval);
288-
resetpp();
289-
return *this;
290-
}
291283
};
292284

293285
#endif // __STREAMSTRING_H

cores/esp8266/WString.cpp

Lines changed: 65 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323

24-
#include <Arduino.h>
24+
#include "Arduino.h"
2525
#include "WString.h"
2626
#include "stdlib_noniso.h"
2727

@@ -56,11 +56,6 @@ String::String(String &&rval) noexcept {
5656
move(rval);
5757
}
5858

59-
String::String(StringSumHelper &&rval) noexcept {
60-
init();
61-
move(rval);
62-
}
63-
6459
String::String(unsigned char value, unsigned char base) {
6560
init();
6661
char buf[1 + 8 * sizeof(unsigned char)];
@@ -390,98 +385,92 @@ unsigned char String::concat(const __FlashStringHelper *str) {
390385
}
391386

392387
/*********************************************/
393-
/* Concatenate */
388+
/* Insert */
394389
/*********************************************/
395390

396-
StringSumHelper &operator +(const StringSumHelper &lhs, const String &rhs) {
397-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
398-
if (!a.concat(rhs.buffer(), rhs.len()))
399-
a.invalidate();
400-
return a;
401-
}
391+
String &String::insert(size_t position, const char *other, size_t other_length) {
392+
if (position > length())
393+
return *this;
402394

403-
StringSumHelper &operator +(const StringSumHelper &lhs, const char *cstr) {
404-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
405-
if (!cstr || !a.concat(cstr, strlen(cstr)))
406-
a.invalidate();
407-
return a;
408-
}
395+
auto len = length();
396+
auto total = len + other_length;
397+
if (!reserve(total))
398+
return *this;
409399

410-
StringSumHelper &operator +(const StringSumHelper &lhs, char c) {
411-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
412-
if (!a.concat(c))
413-
a.invalidate();
414-
return a;
415-
}
400+
auto left = len - position;
401+
setLen(total);
416402

417-
StringSumHelper &operator +(const StringSumHelper &lhs, unsigned char num) {
418-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
419-
if (!a.concat(num))
420-
a.invalidate();
421-
return a;
422-
}
403+
auto *start = wbuffer() + position;
404+
memmove(start + other_length, start, left);
405+
memmove_P(start, other, other_length);
406+
wbuffer()[total] = '\0';
423407

424-
StringSumHelper &operator +(const StringSumHelper &lhs, int num) {
425-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
426-
if (!a.concat(num))
427-
a.invalidate();
428-
return a;
408+
return *this;
429409
}
430410

431-
StringSumHelper &operator +(const StringSumHelper &lhs, unsigned int num) {
432-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
433-
if (!a.concat(num))
434-
a.invalidate();
435-
return a;
411+
String &String::insert(size_t position, const __FlashStringHelper *other) {
412+
auto *p = reinterpret_cast<const char*>(other);
413+
return insert(position, p, strlen_P(p));
436414
}
437415

438-
StringSumHelper &operator +(const StringSumHelper &lhs, long num) {
439-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
440-
if (!a.concat(num))
441-
a.invalidate();
442-
return a;
416+
String &String::insert(size_t position, char other) {
417+
char tmp[2] { other, '\0' };
418+
return insert(position, tmp, 1);
443419
}
444420

445-
StringSumHelper &operator +(const StringSumHelper &lhs, unsigned long num) {
446-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
447-
if (!a.concat(num))
448-
a.invalidate();
449-
return a;
421+
String &String::insert(size_t position, const char *other) {
422+
return insert(position, other, strlen(other));
450423
}
451424

452-
StringSumHelper &operator +(const StringSumHelper &lhs, long long num) {
453-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
454-
if (!a.concat(num))
455-
a.invalidate();
456-
return a;
425+
String &String::insert(size_t position, const String &other) {
426+
return insert(position, other.c_str(), other.length());
457427
}
458428

459-
StringSumHelper &operator +(const StringSumHelper &lhs, unsigned long long num) {
460-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
461-
if (!a.concat(num))
462-
a.invalidate();
463-
return a;
429+
String operator +(const String &lhs, String &&rhs) {
430+
String res;
431+
auto total = lhs.length() + rhs.length();
432+
if (rhs.capacity() > total) {
433+
rhs.insert(0, lhs);
434+
res = std::move(rhs);
435+
} else {
436+
res.reserve(total);
437+
res += lhs;
438+
res += rhs;
439+
rhs.invalidate();
440+
}
441+
442+
return res;
464443
}
465444

466-
StringSumHelper &operator +(const StringSumHelper &lhs, float num) {
467-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
468-
if (!a.concat(num))
469-
a.invalidate();
470-
return a;
445+
String operator +(String &&lhs, String &&rhs) {
446+
String res;
447+
auto total = lhs.length() + rhs.length();
448+
if ((total > lhs.capacity()) && (total < rhs.capacity())) {
449+
rhs.insert(0, lhs);
450+
res = std::move(rhs);
451+
} else {
452+
lhs += rhs;
453+
rhs.invalidate();
454+
res = std::move(lhs);
455+
}
456+
457+
return res;
471458
}
472459

473-
StringSumHelper &operator +(const StringSumHelper &lhs, double num) {
474-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
475-
if (!a.concat(num))
476-
a.invalidate();
477-
return a;
460+
String operator +(char lhs, const String &rhs) {
461+
String res;
462+
res.reserve(rhs.length() + 1);
463+
res += lhs;
464+
res += rhs;
465+
return res;
478466
}
479467

480-
StringSumHelper &operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs) {
481-
StringSumHelper &a = const_cast<StringSumHelper &>(lhs);
482-
if (!a.concat(rhs))
483-
a.invalidate();
484-
return a;
468+
String operator +(const char *lhs, const String &rhs) {
469+
String res;
470+
res.reserve(strlen_P(lhs) + rhs.length());
471+
res += lhs;
472+
res += rhs;
473+
return res;
485474
}
486475

487476
/*********************************************/

0 commit comments

Comments
 (0)