mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Move some code to flash and fix prototypes
This commit is contained in:
parent
ea599139d5
commit
160f99c31c
@ -61,7 +61,7 @@ struct uart_
|
|||||||
|
|
||||||
#define UART_TX_FIFO_SIZE 0x7f
|
#define UART_TX_FIFO_SIZE 0x7f
|
||||||
|
|
||||||
void uart0_rx_handler(uart_t* uart)
|
void ICACHE_FLASH_ATTR uart0_rx_handler(uart_t* uart)
|
||||||
{
|
{
|
||||||
if (READ_PERI_REG(UART_INT_ST(0)) & UART_RXFIFO_FULL_INT_ST)
|
if (READ_PERI_REG(UART_INT_ST(0)) & UART_RXFIFO_FULL_INT_ST)
|
||||||
{
|
{
|
||||||
@ -81,7 +81,7 @@ void uart0_rx_handler(uart_t* uart)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_wait_for_tx_fifo(size_t size_needed)
|
void ICACHE_FLASH_ATTR uart0_wait_for_tx_fifo(size_t size_needed)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -91,17 +91,17 @@ void uart0_wait_for_tx_fifo(size_t size_needed)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_wait_for_transmit(uart_t* uart)
|
void ICACHE_FLASH_ATTR uart0_wait_for_transmit(uart_t* uart)
|
||||||
{
|
{
|
||||||
uart0_wait_for_tx_fifo(UART_TX_FIFO_SIZE);
|
uart0_wait_for_tx_fifo(UART_TX_FIFO_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_transmit_char(uart_t* uart, char c)
|
void ICACHE_FLASH_ATTR uart0_transmit_char(uart_t* uart, char c)
|
||||||
{
|
{
|
||||||
WRITE_PERI_REG(UART_FIFO(0), c);
|
WRITE_PERI_REG(UART_FIFO(0), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_transmit(uart_t* uart, const char* buf, size_t size)
|
void ICACHE_FLASH_ATTR uart0_transmit(uart_t* uart, const char* buf, size_t size)
|
||||||
{
|
{
|
||||||
while (size)
|
while (size)
|
||||||
{
|
{
|
||||||
@ -114,13 +114,13 @@ void uart0_transmit(uart_t* uart, const char* buf, size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_flush(uart_t* uart)
|
void ICACHE_FLASH_ATTR uart0_flush(uart_t* uart)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
SET_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||||
CLEAR_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
CLEAR_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_interrupt_enable(uart_t* uart)
|
void ICACHE_FLASH_ATTR uart0_interrupt_enable(uart_t* uart)
|
||||||
{
|
{
|
||||||
WRITE_PERI_REG(UART_INT_CLR(0), 0x1ff);
|
WRITE_PERI_REG(UART_INT_CLR(0), 0x1ff);
|
||||||
ETS_UART_INTR_ATTACH(&uart0_rx_handler, uart);
|
ETS_UART_INTR_ATTACH(&uart0_rx_handler, uart);
|
||||||
@ -128,24 +128,24 @@ void uart0_interrupt_enable(uart_t* uart)
|
|||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_interrupt_disable(uart_t* uart)
|
void ICACHE_FLASH_ATTR uart0_interrupt_disable(uart_t* uart)
|
||||||
{
|
{
|
||||||
SET_PERI_REG_MASK(UART_INT_ENA(0), 0);
|
SET_PERI_REG_MASK(UART_INT_ENA(0), 0);
|
||||||
ETS_UART_INTR_DISABLE();
|
ETS_UART_INTR_DISABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_set_baudrate(uart_t* uart, int baud_rate)
|
void ICACHE_FLASH_ATTR uart0_set_baudrate(uart_t* uart, int baud_rate)
|
||||||
{
|
{
|
||||||
uart->baud_rate = baud_rate;
|
uart->baud_rate = baud_rate;
|
||||||
uart_div_modify(0, UART_CLK_FREQ / (uart->baud_rate));
|
uart_div_modify(0, UART_CLK_FREQ / (uart->baud_rate));
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart0_get_baudrate(uart_t* uart)
|
int ICACHE_FLASH_ATTR uart0_get_baudrate(uart_t* uart)
|
||||||
{
|
{
|
||||||
return uart->baud_rate;
|
return uart->baud_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
uart_t* uart0_init(int baudrate, uart_rx_handler_t rx_handler)
|
uart_t* ICACHE_FLASH_ATTR uart0_init(int baudrate, uart_rx_handler_t rx_handler)
|
||||||
{
|
{
|
||||||
uart_t* uart = (uart_t*) os_malloc(sizeof(uart_t));
|
uart_t* uart = (uart_t*) os_malloc(sizeof(uart_t));
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ uart_t* uart0_init(int baudrate, uart_rx_handler_t rx_handler)
|
|||||||
return uart;
|
return uart;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart0_uninit(uart_t* uart)
|
void ICACHE_FLASH_ATTR uart0_uninit(uart_t* uart)
|
||||||
{
|
{
|
||||||
uart0_interrupt_disable(uart);
|
uart0_interrupt_disable(uart);
|
||||||
// TODO: revert pin functions
|
// TODO: revert pin functions
|
||||||
@ -173,12 +173,12 @@ void uart0_uninit(uart_t* uart)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void ICACHE_FLASH_ATTR
|
||||||
uart_ignore_char(char c)
|
uart_ignore_char(char c)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void ICACHE_FLASH_ATTR
|
||||||
uart_write_char(char c)
|
uart_write_char(char c)
|
||||||
{
|
{
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
@ -188,7 +188,7 @@ uart_write_char(char c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int s_uart_debug_enabled = 1;
|
int s_uart_debug_enabled = 1;
|
||||||
void uart_set_debug(int enabled)
|
void ICACHE_FLASH_ATTR uart_set_debug(int enabled)
|
||||||
{
|
{
|
||||||
s_uart_debug_enabled = enabled;
|
s_uart_debug_enabled = enabled;
|
||||||
if (enabled)
|
if (enabled)
|
||||||
@ -197,44 +197,44 @@ void uart_set_debug(int enabled)
|
|||||||
ets_install_putc1((void *)&uart_ignore_char);
|
ets_install_putc1((void *)&uart_ignore_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_get_debug()
|
int ICACHE_FLASH_ATTR uart_get_debug()
|
||||||
{
|
{
|
||||||
return s_uart_debug_enabled;
|
return s_uart_debug_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
HardwareSerial Serial;
|
HardwareSerial Serial;
|
||||||
|
|
||||||
void serial_rx_handler(char c)
|
void ICACHE_FLASH_ATTR serial_rx_handler(char c)
|
||||||
{
|
{
|
||||||
Serial._rx_complete_irq(c);
|
Serial._rx_complete_irq(c);
|
||||||
}
|
}
|
||||||
extern "C" size_t ets_printf(const char*, ...);
|
extern "C" size_t ets_printf(const char*, ...);
|
||||||
|
|
||||||
HardwareSerial::HardwareSerial() :
|
ICACHE_FLASH_ATTR HardwareSerial::HardwareSerial() :
|
||||||
_rx_buffer_head(0), _rx_buffer_tail(0),
|
_rx_buffer_head(0), _rx_buffer_tail(0),
|
||||||
_tx_buffer_head(0), _tx_buffer_tail(0),
|
_tx_buffer_head(0), _tx_buffer_tail(0),
|
||||||
_uart(0)
|
_uart(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::begin(unsigned long baud, byte config)
|
void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config)
|
||||||
{
|
{
|
||||||
_uart = uart0_init(baud, &serial_rx_handler);
|
_uart = uart0_init(baud, &serial_rx_handler);
|
||||||
_written = false;
|
_written = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::end()
|
void ICACHE_FLASH_ATTR HardwareSerial::end()
|
||||||
{
|
{
|
||||||
uart0_uninit(_uart);
|
uart0_uninit(_uart);
|
||||||
_uart = 0;
|
_uart = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardwareSerial::available(void)
|
int ICACHE_FLASH_ATTR HardwareSerial::available(void)
|
||||||
{
|
{
|
||||||
return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
|
return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardwareSerial::peek(void)
|
int ICACHE_FLASH_ATTR HardwareSerial::peek(void)
|
||||||
{
|
{
|
||||||
if (_rx_buffer_head == _rx_buffer_tail) {
|
if (_rx_buffer_head == _rx_buffer_tail) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -243,7 +243,7 @@ int HardwareSerial::peek(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardwareSerial::read(void)
|
int ICACHE_FLASH_ATTR HardwareSerial::read(void)
|
||||||
{
|
{
|
||||||
// if the head isn't ahead of the tail, we don't have any characters
|
// if the head isn't ahead of the tail, we don't have any characters
|
||||||
if (_rx_buffer_head == _rx_buffer_tail) {
|
if (_rx_buffer_head == _rx_buffer_tail) {
|
||||||
@ -255,7 +255,7 @@ int HardwareSerial::read(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HardwareSerial::availableForWrite(void)
|
int ICACHE_FLASH_ATTR HardwareSerial::availableForWrite(void)
|
||||||
{
|
{
|
||||||
tx_buffer_index_t head = _tx_buffer_head;
|
tx_buffer_index_t head = _tx_buffer_head;
|
||||||
tx_buffer_index_t tail = _tx_buffer_tail;
|
tx_buffer_index_t tail = _tx_buffer_tail;
|
||||||
@ -264,14 +264,14 @@ int HardwareSerial::availableForWrite(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HardwareSerial::flush()
|
void ICACHE_FLASH_ATTR HardwareSerial::flush()
|
||||||
{
|
{
|
||||||
if (!_written)
|
if (!_written)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t HardwareSerial::write(uint8_t c)
|
size_t ICACHE_FLASH_ATTR HardwareSerial::write(uint8_t c)
|
||||||
{
|
{
|
||||||
uart0_transmit_char(_uart, c);
|
uart0_transmit_char(_uart, c);
|
||||||
// // If the buffer and the data register is empty, just write the byte
|
// // If the buffer and the data register is empty, just write the byte
|
||||||
@ -309,7 +309,7 @@ size_t HardwareSerial::write(uint8_t c)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareSerial::_rx_complete_irq(char c)
|
void ICACHE_FLASH_ATTR HardwareSerial::_rx_complete_irq(char c)
|
||||||
{
|
{
|
||||||
rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
|
rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
|
||||||
|
|
||||||
|
@ -26,14 +26,14 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
extern "C" {
|
||||||
|
#include "c_types.h"
|
||||||
|
}
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/* default implementation: may be overridden */
|
/* default implementation: may be overridden */
|
||||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
size_t ICACHE_FLASH_ATTR Print::write(const uint8_t *buffer, size_t size)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
@ -42,37 +42,37 @@ size_t Print::write(const uint8_t *buffer, size_t size)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const String &s)
|
size_t ICACHE_FLASH_ATTR Print::print(const String &s)
|
||||||
{
|
{
|
||||||
return write(s.c_str(), s.length());
|
return write(s.c_str(), s.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const char str[])
|
size_t ICACHE_FLASH_ATTR Print::print(const char str[])
|
||||||
{
|
{
|
||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(char c)
|
size_t ICACHE_FLASH_ATTR Print::print(char c)
|
||||||
{
|
{
|
||||||
return write(c);
|
return write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned char b, int base)
|
size_t ICACHE_FLASH_ATTR Print::print(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
return print((unsigned long) b, base);
|
return print((unsigned long) b, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(int n, int base)
|
size_t ICACHE_FLASH_ATTR Print::print(int n, int base)
|
||||||
{
|
{
|
||||||
return print((long) n, base);
|
return print((long) n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned int n, int base)
|
size_t ICACHE_FLASH_ATTR Print::print(unsigned int n, int base)
|
||||||
{
|
{
|
||||||
return print((unsigned long) n, base);
|
return print((unsigned long) n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(long n, int base)
|
size_t ICACHE_FLASH_ATTR Print::print(long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
return write(n);
|
return write(n);
|
||||||
@ -88,93 +88,92 @@ size_t Print::print(long n, int base)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(unsigned long n, int base)
|
size_t ICACHE_FLASH_ATTR Print::print(unsigned long n, int base)
|
||||||
{
|
{
|
||||||
if (base == 0) return write(n);
|
if (base == 0) return write(n);
|
||||||
else return printNumber(n, base);
|
else return printNumber(n, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(double n, int digits)
|
size_t ICACHE_FLASH_ATTR Print::print(double n, int digits)
|
||||||
{
|
{
|
||||||
return printFloat(n, digits);
|
return printFloat(n, digits);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::print(const Printable& x)
|
size_t ICACHE_FLASH_ATTR Print::print(const Printable& x)
|
||||||
{
|
{
|
||||||
return x.printTo(*this);
|
return x.printTo(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(void)
|
size_t ICACHE_FLASH_ATTR Print::println(void)
|
||||||
{
|
{
|
||||||
size_t n = print('\r');
|
size_t n = print("\r\n");
|
||||||
n += print('\n');
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const String &s)
|
size_t ICACHE_FLASH_ATTR Print::println(const String &s)
|
||||||
{
|
{
|
||||||
size_t n = print(s);
|
size_t n = print(s);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const char c[])
|
size_t ICACHE_FLASH_ATTR Print::println(const char c[])
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(char c)
|
size_t ICACHE_FLASH_ATTR Print::println(char c)
|
||||||
{
|
{
|
||||||
size_t n = print(c);
|
size_t n = print(c);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned char b, int base)
|
size_t ICACHE_FLASH_ATTR Print::println(unsigned char b, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(b, base);
|
size_t n = print(b, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(int num, int base)
|
size_t ICACHE_FLASH_ATTR Print::println(int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned int num, int base)
|
size_t ICACHE_FLASH_ATTR Print::println(unsigned int num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(long num, int base)
|
size_t ICACHE_FLASH_ATTR Print::println(long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(unsigned long num, int base)
|
size_t ICACHE_FLASH_ATTR Print::println(unsigned long num, int base)
|
||||||
{
|
{
|
||||||
size_t n = print(num, base);
|
size_t n = print(num, base);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(double num, int digits)
|
size_t ICACHE_FLASH_ATTR Print::println(double num, int digits)
|
||||||
{
|
{
|
||||||
size_t n = print(num, digits);
|
size_t n = print(num, digits);
|
||||||
n += println();
|
n += println();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::println(const Printable& x)
|
size_t ICACHE_FLASH_ATTR Print::println(const Printable& x)
|
||||||
{
|
{
|
||||||
size_t n = print(x);
|
size_t n = print(x);
|
||||||
n += println();
|
n += println();
|
||||||
@ -183,7 +182,7 @@ size_t Print::println(const Printable& x)
|
|||||||
|
|
||||||
// Private Methods /////////////////////////////////////////////////////////////
|
// Private Methods /////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t Print::printNumber(unsigned long n, uint8_t base) {
|
size_t ICACHE_FLASH_ATTR Print::printNumber(unsigned long n, uint8_t base) {
|
||||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||||
char *str = &buf[sizeof(buf) - 1];
|
char *str = &buf[sizeof(buf) - 1];
|
||||||
|
|
||||||
@ -202,7 +201,7 @@ size_t Print::printNumber(unsigned long n, uint8_t base) {
|
|||||||
return write(str);
|
return write(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Print::printFloat(double number, uint8_t digits)
|
size_t ICACHE_FLASH_ATTR Print::printFloat(double number, uint8_t digits)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
|
@ -22,12 +22,14 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "Stream.h"
|
#include "Stream.h"
|
||||||
|
extern "C"{
|
||||||
|
#include "c_types.h"
|
||||||
|
}
|
||||||
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
|
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
|
||||||
#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field
|
#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field
|
||||||
|
|
||||||
// private method to read stream with timeout
|
// private method to read stream with timeout
|
||||||
int Stream::timedRead()
|
int ICACHE_FLASH_ATTR Stream::timedRead()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
_startMillis = millis();
|
_startMillis = millis();
|
||||||
@ -39,7 +41,7 @@ int Stream::timedRead()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// private method to peek stream with timeout
|
// private method to peek stream with timeout
|
||||||
int Stream::timedPeek()
|
int ICACHE_FLASH_ATTR Stream::timedPeek()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
_startMillis = millis();
|
_startMillis = millis();
|
||||||
@ -52,7 +54,7 @@ int Stream::timedPeek()
|
|||||||
|
|
||||||
// returns peek of the next digit in the stream or -1 if timeout
|
// returns peek of the next digit in the stream or -1 if timeout
|
||||||
// discards non-numeric characters
|
// discards non-numeric characters
|
||||||
int Stream::peekNextDigit()
|
int ICACHE_FLASH_ATTR Stream::peekNextDigit()
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -67,26 +69,26 @@ int Stream::peekNextDigit()
|
|||||||
// Public Methods
|
// Public Methods
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
void ICACHE_FLASH_ATTR Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
|
||||||
{
|
{
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find returns true if the target string is found
|
// find returns true if the target string is found
|
||||||
bool Stream::find(char *target)
|
bool ICACHE_FLASH_ATTR Stream::find(const char *target)
|
||||||
{
|
{
|
||||||
return findUntil(target, (char*)"");
|
return findUntil(target, (char*)"");
|
||||||
}
|
}
|
||||||
|
|
||||||
// reads data from the stream until the target string of given length is found
|
// reads data from the stream until the target string of given length is found
|
||||||
// returns true if target string is found, false if timed out
|
// returns true if target string is found, false if timed out
|
||||||
bool Stream::find(char *target, size_t length)
|
bool ICACHE_FLASH_ATTR Stream::find(const char *target, size_t length)
|
||||||
{
|
{
|
||||||
return findUntil(target, length, NULL, 0);
|
return findUntil(target, length, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// as find but search ends if the terminator string is found
|
// as find but search ends if the terminator string is found
|
||||||
bool Stream::findUntil(char *target, char *terminator)
|
bool ICACHE_FLASH_ATTR Stream::findUntil(const char *target, const char *terminator)
|
||||||
{
|
{
|
||||||
return findUntil(target, strlen(target), terminator, strlen(terminator));
|
return findUntil(target, strlen(target), terminator, strlen(terminator));
|
||||||
}
|
}
|
||||||
@ -94,7 +96,7 @@ bool Stream::findUntil(char *target, char *terminator)
|
|||||||
// reads data from the stream until the target string of the given length is found
|
// reads data from the stream until the target string of the given length is found
|
||||||
// search terminated if the terminator string is found
|
// search terminated if the terminator string is found
|
||||||
// returns true if target string is found, false if terminated or timed out
|
// returns true if target string is found, false if terminated or timed out
|
||||||
bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
|
bool ICACHE_FLASH_ATTR Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
||||||
{
|
{
|
||||||
size_t index = 0; // maximum target string length is 64k bytes!
|
size_t index = 0; // maximum target string length is 64k bytes!
|
||||||
size_t termIndex = 0;
|
size_t termIndex = 0;
|
||||||
@ -128,14 +130,14 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t
|
|||||||
// returns the first valid (long) integer value from the current position.
|
// returns the first valid (long) integer value from the current position.
|
||||||
// initial characters that are not digits (or the minus sign) are skipped
|
// initial characters that are not digits (or the minus sign) are skipped
|
||||||
// function is terminated by the first character that is not a digit.
|
// function is terminated by the first character that is not a digit.
|
||||||
long Stream::parseInt()
|
long ICACHE_FLASH_ATTR Stream::parseInt()
|
||||||
{
|
{
|
||||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// as above but a given skipChar is ignored
|
// as above but a given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
long Stream::parseInt(char skipChar)
|
long ICACHE_FLASH_ATTR Stream::parseInt(char skipChar)
|
||||||
{
|
{
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
@ -165,14 +167,14 @@ long Stream::parseInt(char skipChar)
|
|||||||
|
|
||||||
|
|
||||||
// as parseInt but returns a floating point value
|
// as parseInt but returns a floating point value
|
||||||
float Stream::parseFloat()
|
float ICACHE_FLASH_ATTR Stream::parseFloat()
|
||||||
{
|
{
|
||||||
return parseFloat(NO_SKIP_CHAR);
|
return parseFloat(NO_SKIP_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// as above but the given skipChar is ignored
|
// as above but the given skipChar is ignored
|
||||||
// this allows format characters (typically commas) in values to be ignored
|
// this allows format characters (typically commas) in values to be ignored
|
||||||
float Stream::parseFloat(char skipChar){
|
float ICACHE_FLASH_ATTR Stream::parseFloat(char skipChar){
|
||||||
boolean isNegative = false;
|
boolean isNegative = false;
|
||||||
boolean isFraction = false;
|
boolean isFraction = false;
|
||||||
long value = 0;
|
long value = 0;
|
||||||
@ -214,7 +216,7 @@ float Stream::parseFloat(char skipChar){
|
|||||||
// returns the number of characters placed in the buffer
|
// returns the number of characters placed in the buffer
|
||||||
// the buffer is NOT null terminated.
|
// the buffer is NOT null terminated.
|
||||||
//
|
//
|
||||||
size_t Stream::readBytes(char *buffer, size_t length)
|
size_t ICACHE_FLASH_ATTR Stream::readBytes(char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
while (count < length) {
|
while (count < length) {
|
||||||
@ -231,7 +233,7 @@ size_t Stream::readBytes(char *buffer, size_t length)
|
|||||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||||
|
|
||||||
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
size_t ICACHE_FLASH_ATTR Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
if (length < 1) return 0;
|
if (length < 1) return 0;
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
@ -244,7 +246,7 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
|||||||
return index; // return number of characters, not including null terminator
|
return index; // return number of characters, not including null terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
String Stream::readString()
|
String ICACHE_FLASH_ATTR Stream::readString()
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
@ -256,7 +258,7 @@ String Stream::readString()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
String Stream::readStringUntil(char terminator)
|
String ICACHE_FLASH_ATTR Stream::readStringUntil(char terminator)
|
||||||
{
|
{
|
||||||
String ret;
|
String ret;
|
||||||
int c = timedRead();
|
int c = timedRead();
|
||||||
|
@ -56,19 +56,19 @@ class Stream : public Print
|
|||||||
|
|
||||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||||
|
|
||||||
bool find(char *target); // reads data from the stream until the target string is found
|
bool find(const char *target); // reads data from the stream until the target string is found
|
||||||
bool find(uint8_t *target) { return find ((char *)target); }
|
bool find(uint8_t *target) { return find ((char *)target); }
|
||||||
// returns true if target string is found, false if timed out (see setTimeout)
|
// returns true if target string is found, false if timed out (see setTimeout)
|
||||||
|
|
||||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||||
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
|
bool find(const uint8_t *target, size_t length) { return find ((char *)target, length); }
|
||||||
// returns true if target string is found, false if timed out
|
// returns true if target string is found, false if timed out
|
||||||
|
|
||||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found
|
||||||
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
|
bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((char *)target, terminator); }
|
||||||
|
|
||||||
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
|
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
|
||||||
|
|
||||||
|
|
||||||
long parseInt(); // returns the first valid (long) integer value from the current position.
|
long parseInt(); // returns the first valid (long) integer value from the current position.
|
||||||
|
@ -25,38 +25,39 @@ extern "C" {
|
|||||||
#include "osapi.h"
|
#include "osapi.h"
|
||||||
#include "ets_sys.h"
|
#include "ets_sys.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "c_types.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
|
|
||||||
String::String(const char *cstr)
|
ICACHE_FLASH_ATTR String::String(const char *cstr)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
if (cstr) copy(cstr, strlen(cstr));
|
if (cstr) copy(cstr, strlen(cstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(const String &value)
|
ICACHE_FLASH_ATTR String::String(const String &value)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
*this = value;
|
*this = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
String::String(String &&rval)
|
ICACHE_FLASH_ATTR String::String(String &&rval)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
move(rval);
|
move(rval);
|
||||||
}
|
}
|
||||||
String::String(StringSumHelper &&rval)
|
ICACHE_FLASH_ATTR String::String(StringSumHelper &&rval)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
move(rval);
|
move(rval);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String::String(char c)
|
ICACHE_FLASH_ATTR String::String(char c)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[2];
|
char buf[2];
|
||||||
@ -65,7 +66,7 @@ String::String(char c)
|
|||||||
*this = buf;
|
*this = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(unsigned char value, unsigned char base)
|
ICACHE_FLASH_ATTR String::String(unsigned char value, unsigned char base)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[1 + 8 * sizeof(unsigned char)];
|
char buf[1 + 8 * sizeof(unsigned char)];
|
||||||
@ -73,7 +74,7 @@ String::String(unsigned char value, unsigned char base)
|
|||||||
*this = buf;
|
*this = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(int value, unsigned char base)
|
ICACHE_FLASH_ATTR String::String(int value, unsigned char base)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[2 + 8 * sizeof(int)];
|
char buf[2 + 8 * sizeof(int)];
|
||||||
@ -81,7 +82,7 @@ String::String(int value, unsigned char base)
|
|||||||
*this = buf;
|
*this = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(unsigned int value, unsigned char base)
|
ICACHE_FLASH_ATTR String::String(unsigned int value, unsigned char base)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[1 + 8 * sizeof(unsigned int)];
|
char buf[1 + 8 * sizeof(unsigned int)];
|
||||||
@ -89,7 +90,7 @@ String::String(unsigned int value, unsigned char base)
|
|||||||
*this = buf;
|
*this = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(long value, unsigned char base)
|
ICACHE_FLASH_ATTR String::String(long value, unsigned char base)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[2 + 8 * sizeof(long)];
|
char buf[2 + 8 * sizeof(long)];
|
||||||
@ -97,7 +98,7 @@ String::String(long value, unsigned char base)
|
|||||||
*this = buf;
|
*this = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(unsigned long value, unsigned char base)
|
ICACHE_FLASH_ATTR String::String(unsigned long value, unsigned char base)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[1 + 8 * sizeof(unsigned long)];
|
char buf[1 + 8 * sizeof(unsigned long)];
|
||||||
@ -105,28 +106,28 @@ String::String(unsigned long value, unsigned char base)
|
|||||||
*this = buf;
|
*this = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(float value, unsigned char decimalPlaces)
|
ICACHE_FLASH_ATTR String::String(float value, unsigned char decimalPlaces)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[33];
|
char buf[33];
|
||||||
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
String::String(double value, unsigned char decimalPlaces)
|
ICACHE_FLASH_ATTR String::String(double value, unsigned char decimalPlaces)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
char buf[33];
|
char buf[33];
|
||||||
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
String::~String()
|
ICACHE_FLASH_ATTR String::~String()
|
||||||
{
|
{
|
||||||
free(buffer);
|
os_free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Memory Management */
|
// /* Memory Management */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
inline void String::init(void)
|
inline void String::init(void)
|
||||||
{
|
{
|
||||||
@ -135,14 +136,14 @@ inline void String::init(void)
|
|||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::invalidate(void)
|
void ICACHE_FLASH_ATTR String::invalidate(void)
|
||||||
{
|
{
|
||||||
if (buffer) free(buffer);
|
if (buffer) os_free(buffer);
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
capacity = len = 0;
|
capacity = len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::reserve(unsigned int size)
|
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size)
|
||||||
{
|
{
|
||||||
if (buffer && capacity >= size) return 1;
|
if (buffer && capacity >= size) return 1;
|
||||||
if (changeBuffer(size)) {
|
if (changeBuffer(size)) {
|
||||||
@ -152,9 +153,9 @@ unsigned char String::reserve(unsigned int size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::changeBuffer(unsigned int maxStrLen)
|
unsigned char ICACHE_FLASH_ATTR String::changeBuffer(unsigned int maxStrLen)
|
||||||
{
|
{
|
||||||
char *newbuffer = (char *)realloc(buffer, maxStrLen + 1);
|
char *newbuffer = (char *)os_realloc(buffer, maxStrLen + 1);
|
||||||
if (newbuffer) {
|
if (newbuffer) {
|
||||||
buffer = newbuffer;
|
buffer = newbuffer;
|
||||||
capacity = maxStrLen;
|
capacity = maxStrLen;
|
||||||
@ -163,11 +164,11 @@ unsigned char String::changeBuffer(unsigned int maxStrLen)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Copy and Move */
|
// /* Copy and Move */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
String & String::copy(const char *cstr, unsigned int length)
|
String & ICACHE_FLASH_ATTR String::copy(const char *cstr, unsigned int length)
|
||||||
{
|
{
|
||||||
if (!reserve(length)) {
|
if (!reserve(length)) {
|
||||||
invalidate();
|
invalidate();
|
||||||
@ -180,7 +181,7 @@ String & String::copy(const char *cstr, unsigned int length)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
void String::move(String &rhs)
|
void ICACHE_FLASH_ATTR String::move(String &rhs)
|
||||||
{
|
{
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
if (capacity >= rhs.len) {
|
if (capacity >= rhs.len) {
|
||||||
@ -189,7 +190,7 @@ void String::move(String &rhs)
|
|||||||
rhs.len = 0;
|
rhs.len = 0;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
free(buffer);
|
os_free(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer = rhs.buffer;
|
buffer = rhs.buffer;
|
||||||
@ -201,7 +202,7 @@ void String::move(String &rhs)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String & String::operator = (const String &rhs)
|
String & ICACHE_FLASH_ATTR String::operator = (const String &rhs)
|
||||||
{
|
{
|
||||||
if (this == &rhs) return *this;
|
if (this == &rhs) return *this;
|
||||||
|
|
||||||
@ -212,20 +213,20 @@ String & String::operator = (const String &rhs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
String & String::operator = (String &&rval)
|
String & ICACHE_FLASH_ATTR String::operator = (String &&rval)
|
||||||
{
|
{
|
||||||
if (this != &rval) move(rval);
|
if (this != &rval) move(rval);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String & String::operator = (StringSumHelper &&rval)
|
String & ICACHE_FLASH_ATTR String::operator = (StringSumHelper &&rval)
|
||||||
{
|
{
|
||||||
if (this != &rval) move(rval);
|
if (this != &rval) move(rval);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String & String::operator = (const char *cstr)
|
String & ICACHE_FLASH_ATTR String::operator = (const char *cstr)
|
||||||
{
|
{
|
||||||
if (cstr) copy(cstr, strlen(cstr));
|
if (cstr) copy(cstr, strlen(cstr));
|
||||||
else invalidate();
|
else invalidate();
|
||||||
@ -234,16 +235,16 @@ String & String::operator = (const char *cstr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* concat */
|
// /* concat */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
unsigned char String::concat(const String &s)
|
unsigned char ICACHE_FLASH_ATTR String::concat(const String &s)
|
||||||
{
|
{
|
||||||
return concat(s.buffer, s.len);
|
return concat(s.buffer, s.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(const char *cstr, unsigned int length)
|
unsigned char ICACHE_FLASH_ATTR String::concat(const char *cstr, unsigned int length)
|
||||||
{
|
{
|
||||||
unsigned int newlen = len + length;
|
unsigned int newlen = len + length;
|
||||||
if (!cstr) return 0;
|
if (!cstr) return 0;
|
||||||
@ -254,13 +255,13 @@ unsigned char String::concat(const char *cstr, unsigned int length)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(const char *cstr)
|
unsigned char ICACHE_FLASH_ATTR String::concat(const char *cstr)
|
||||||
{
|
{
|
||||||
if (!cstr) return 0;
|
if (!cstr) return 0;
|
||||||
return concat(cstr, strlen(cstr));
|
return concat(cstr, strlen(cstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(char c)
|
unsigned char ICACHE_FLASH_ATTR String::concat(char c)
|
||||||
{
|
{
|
||||||
char buf[2];
|
char buf[2];
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
@ -268,49 +269,49 @@ unsigned char String::concat(char c)
|
|||||||
return concat(buf, 1);
|
return concat(buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(unsigned char num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned char num)
|
||||||
{
|
{
|
||||||
char buf[1 + 3 * sizeof(unsigned char)];
|
char buf[1 + 3 * sizeof(unsigned char)];
|
||||||
itoa(num, buf, 10);
|
itoa(num, buf, 10);
|
||||||
return concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(int num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(int num)
|
||||||
{
|
{
|
||||||
char buf[2 + 3 * sizeof(int)];
|
char buf[2 + 3 * sizeof(int)];
|
||||||
itoa(num, buf, 10);
|
itoa(num, buf, 10);
|
||||||
return concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(unsigned int num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned int num)
|
||||||
{
|
{
|
||||||
char buf[1 + 3 * sizeof(unsigned int)];
|
char buf[1 + 3 * sizeof(unsigned int)];
|
||||||
utoa(num, buf, 10);
|
utoa(num, buf, 10);
|
||||||
return concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(long num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(long num)
|
||||||
{
|
{
|
||||||
char buf[2 + 3 * sizeof(long)];
|
char buf[2 + 3 * sizeof(long)];
|
||||||
ltoa(num, buf, 10);
|
ltoa(num, buf, 10);
|
||||||
return concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(unsigned long num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned long num)
|
||||||
{
|
{
|
||||||
char buf[1 + 3 * sizeof(unsigned long)];
|
char buf[1 + 3 * sizeof(unsigned long)];
|
||||||
ultoa(num, buf, 10);
|
ultoa(num, buf, 10);
|
||||||
return concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(float num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(float num)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
char* string = dtostrf(num, 4, 2, buf);
|
char* string = dtostrf(num, 4, 2, buf);
|
||||||
return concat(string, strlen(string));
|
return concat(string, strlen(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::concat(double num)
|
unsigned char ICACHE_FLASH_ATTR String::concat(double num)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
char* string = dtostrf(num, 4, 2, buf);
|
char* string = dtostrf(num, 4, 2, buf);
|
||||||
@ -321,70 +322,70 @@ unsigned char String::concat(double num)
|
|||||||
/* Concatenate */
|
/* Concatenate */
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, const String &rhs)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(rhs.buffer, rhs.len)) a.invalidate();
|
if (!a.concat(rhs.buffer, rhs.len)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, const char *cstr)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
|
if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, char c)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, char c)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(c)) a.invalidate();
|
if (!a.concat(c)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, unsigned char num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, int num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, int num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, unsigned int num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, long num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, long num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, unsigned long num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, float num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, float num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSumHelper & operator + (const StringSumHelper &lhs, double num)
|
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, double num)
|
||||||
{
|
{
|
||||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||||
if (!a.concat(num)) a.invalidate();
|
if (!a.concat(num)) a.invalidate();
|
||||||
@ -392,11 +393,11 @@ StringSumHelper & operator + (const StringSumHelper &lhs, double num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Comparison */
|
// /* Comparison */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
int String::compareTo(const String &s) const
|
int ICACHE_FLASH_ATTR String::compareTo(const String &s) const
|
||||||
{
|
{
|
||||||
if (!buffer || !s.buffer) {
|
if (!buffer || !s.buffer) {
|
||||||
if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer;
|
if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer;
|
||||||
@ -406,39 +407,39 @@ int String::compareTo(const String &s) const
|
|||||||
return strcmp(buffer, s.buffer);
|
return strcmp(buffer, s.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::equals(const String &s2) const
|
unsigned char ICACHE_FLASH_ATTR String::equals(const String &s2) const
|
||||||
{
|
{
|
||||||
return (len == s2.len && compareTo(s2) == 0);
|
return (len == s2.len && compareTo(s2) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::equals(const char *cstr) const
|
unsigned char ICACHE_FLASH_ATTR String::equals(const char *cstr) const
|
||||||
{
|
{
|
||||||
if (len == 0) return (cstr == NULL || *cstr == 0);
|
if (len == 0) return (cstr == NULL || *cstr == 0);
|
||||||
if (cstr == NULL) return buffer[0] == 0;
|
if (cstr == NULL) return buffer[0] == 0;
|
||||||
return strcmp(buffer, cstr) == 0;
|
return strcmp(buffer, cstr) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::operator<(const String &rhs) const
|
unsigned char ICACHE_FLASH_ATTR String::operator<(const String &rhs) const
|
||||||
{
|
{
|
||||||
return compareTo(rhs) < 0;
|
return compareTo(rhs) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::operator>(const String &rhs) const
|
unsigned char ICACHE_FLASH_ATTR String::operator>(const String &rhs) const
|
||||||
{
|
{
|
||||||
return compareTo(rhs) > 0;
|
return compareTo(rhs) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::operator<=(const String &rhs) const
|
unsigned char ICACHE_FLASH_ATTR String::operator<=(const String &rhs) const
|
||||||
{
|
{
|
||||||
return compareTo(rhs) <= 0;
|
return compareTo(rhs) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::operator>=(const String &rhs) const
|
unsigned char ICACHE_FLASH_ATTR String::operator>=(const String &rhs) const
|
||||||
{
|
{
|
||||||
return compareTo(rhs) >= 0;
|
return compareTo(rhs) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::equalsIgnoreCase( const String &s2 ) const
|
unsigned char ICACHE_FLASH_ATTR String::equalsIgnoreCase( const String &s2 ) const
|
||||||
{
|
{
|
||||||
if (this == &s2) return 1;
|
if (this == &s2) return 1;
|
||||||
if (len != s2.len) return 0;
|
if (len != s2.len) return 0;
|
||||||
@ -451,39 +452,39 @@ unsigned char String::equalsIgnoreCase( const String &s2 ) const
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::startsWith( const String &s2 ) const
|
unsigned char ICACHE_FLASH_ATTR String::startsWith( const String &s2 ) const
|
||||||
{
|
{
|
||||||
if (len < s2.len) return 0;
|
if (len < s2.len) return 0;
|
||||||
return startsWith(s2, 0);
|
return startsWith(s2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::startsWith( const String &s2, unsigned int offset ) const
|
unsigned char ICACHE_FLASH_ATTR String::startsWith( const String &s2, unsigned int offset ) const
|
||||||
{
|
{
|
||||||
if (offset > len - s2.len || !buffer || !s2.buffer) return 0;
|
if (offset > len - s2.len || !buffer || !s2.buffer) return 0;
|
||||||
return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0;
|
return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char String::endsWith( const String &s2 ) const
|
unsigned char ICACHE_FLASH_ATTR String::endsWith( const String &s2 ) const
|
||||||
{
|
{
|
||||||
if ( len < s2.len || !buffer || !s2.buffer) return 0;
|
if ( len < s2.len || !buffer || !s2.buffer) return 0;
|
||||||
return strcmp(&buffer[len - s2.len], s2.buffer) == 0;
|
return strcmp(&buffer[len - s2.len], s2.buffer) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Character Access */
|
// /* Character Access */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
char String::charAt(unsigned int loc) const
|
char ICACHE_FLASH_ATTR String::charAt(unsigned int loc) const
|
||||||
{
|
{
|
||||||
return operator[](loc);
|
return operator[](loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::setCharAt(unsigned int loc, char c)
|
void ICACHE_FLASH_ATTR String::setCharAt(unsigned int loc, char c)
|
||||||
{
|
{
|
||||||
if (loc < len) buffer[loc] = c;
|
if (loc < len) buffer[loc] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
char & String::operator[](unsigned int index)
|
char & ICACHE_FLASH_ATTR String::operator[](unsigned int index)
|
||||||
{
|
{
|
||||||
static char dummy_writable_char;
|
static char dummy_writable_char;
|
||||||
if (index >= len || !buffer) {
|
if (index >= len || !buffer) {
|
||||||
@ -493,13 +494,13 @@ char & String::operator[](unsigned int index)
|
|||||||
return buffer[index];
|
return buffer[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
char String::operator[]( unsigned int index ) const
|
char ICACHE_FLASH_ATTR String::operator[]( unsigned int index ) const
|
||||||
{
|
{
|
||||||
if (index >= len || !buffer) return 0;
|
if (index >= len || !buffer) return 0;
|
||||||
return buffer[index];
|
return buffer[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const
|
void ICACHE_FLASH_ATTR String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const
|
||||||
{
|
{
|
||||||
if (!bufsize || !buf) return;
|
if (!bufsize || !buf) return;
|
||||||
if (index >= len) {
|
if (index >= len) {
|
||||||
@ -512,16 +513,17 @@ void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int ind
|
|||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Search */
|
// /* Search */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
ICACHE_FLASH_ATTR ICACHE_FLASH_ATTR
|
||||||
|
|
||||||
int String::indexOf(char c) const
|
int ICACHE_FLASH_ATTR String::indexOf(char c) const
|
||||||
{
|
{
|
||||||
return indexOf(c, 0);
|
return indexOf(c, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::indexOf( char ch, unsigned int fromIndex ) const
|
int ICACHE_FLASH_ATTR String::indexOf( char ch, unsigned int fromIndex ) const
|
||||||
{
|
{
|
||||||
if (fromIndex >= len) return -1;
|
if (fromIndex >= len) return -1;
|
||||||
const char* temp = strchr(buffer + fromIndex, ch);
|
const char* temp = strchr(buffer + fromIndex, ch);
|
||||||
@ -529,12 +531,12 @@ int String::indexOf( char ch, unsigned int fromIndex ) const
|
|||||||
return temp - buffer;
|
return temp - buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::indexOf(const String &s2) const
|
int ICACHE_FLASH_ATTR String::indexOf(const String &s2) const
|
||||||
{
|
{
|
||||||
return indexOf(s2, 0);
|
return indexOf(s2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::indexOf(const String &s2, unsigned int fromIndex) const
|
int ICACHE_FLASH_ATTR String::indexOf(const String &s2, unsigned int fromIndex) const
|
||||||
{
|
{
|
||||||
if (fromIndex >= len) return -1;
|
if (fromIndex >= len) return -1;
|
||||||
const char *found = strstr(buffer + fromIndex, s2.buffer);
|
const char *found = strstr(buffer + fromIndex, s2.buffer);
|
||||||
@ -542,12 +544,12 @@ int String::indexOf(const String &s2, unsigned int fromIndex) const
|
|||||||
return found - buffer;
|
return found - buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::lastIndexOf( char theChar ) const
|
int ICACHE_FLASH_ATTR String::lastIndexOf( char theChar ) const
|
||||||
{
|
{
|
||||||
return lastIndexOf(theChar, len - 1);
|
return lastIndexOf(theChar, len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::lastIndexOf(char ch, unsigned int fromIndex) const
|
int ICACHE_FLASH_ATTR String::lastIndexOf(char ch, unsigned int fromIndex) const
|
||||||
{
|
{
|
||||||
if (fromIndex >= len) return -1;
|
if (fromIndex >= len) return -1;
|
||||||
char tempchar = buffer[fromIndex + 1];
|
char tempchar = buffer[fromIndex + 1];
|
||||||
@ -558,12 +560,12 @@ int String::lastIndexOf(char ch, unsigned int fromIndex) const
|
|||||||
return temp - buffer;
|
return temp - buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::lastIndexOf(const String &s2) const
|
int ICACHE_FLASH_ATTR String::lastIndexOf(const String &s2) const
|
||||||
{
|
{
|
||||||
return lastIndexOf(s2, len - s2.len);
|
return lastIndexOf(s2, len - s2.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::lastIndexOf(const String &s2, unsigned int fromIndex) const
|
int ICACHE_FLASH_ATTR String::lastIndexOf(const String &s2, unsigned int fromIndex) const
|
||||||
{
|
{
|
||||||
if (s2.len == 0 || len == 0 || s2.len > len) return -1;
|
if (s2.len == 0 || len == 0 || s2.len > len) return -1;
|
||||||
if (fromIndex >= len) fromIndex = len - 1;
|
if (fromIndex >= len) fromIndex = len - 1;
|
||||||
@ -576,7 +578,7 @@ int String::lastIndexOf(const String &s2, unsigned int fromIndex) const
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::substring(unsigned int left, unsigned int right) const
|
String ICACHE_FLASH_ATTR String::substring(unsigned int left, unsigned int right) const
|
||||||
{
|
{
|
||||||
if (left > right) {
|
if (left > right) {
|
||||||
unsigned int temp = right;
|
unsigned int temp = right;
|
||||||
@ -593,11 +595,11 @@ String String::substring(unsigned int left, unsigned int right) const
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Modification */
|
// /* Modification */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
void String::replace(char find, char replace)
|
void ICACHE_FLASH_ATTR String::replace(char find, char replace)
|
||||||
{
|
{
|
||||||
if (!buffer) return;
|
if (!buffer) return;
|
||||||
for (char *p = buffer; *p; p++) {
|
for (char *p = buffer; *p; p++) {
|
||||||
@ -605,7 +607,7 @@ void String::replace(char find, char replace)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::replace(const String& find, const String& replace)
|
void ICACHE_FLASH_ATTR String::replace(const String& find, const String& replace)
|
||||||
{
|
{
|
||||||
if (len == 0 || find.len == 0) return;
|
if (len == 0 || find.len == 0) return;
|
||||||
int diff = replace.len - find.len;
|
int diff = replace.len - find.len;
|
||||||
@ -648,14 +650,14 @@ void String::replace(const String& find, const String& replace)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::remove(unsigned int index){
|
void ICACHE_FLASH_ATTR String::remove(unsigned int index){
|
||||||
// Pass the biggest integer as the count. The remove method
|
// Pass the biggest integer as the count. The remove method
|
||||||
// below will take care of truncating it at the end of the
|
// below will take care of truncating it at the end of the
|
||||||
// string.
|
// string.
|
||||||
remove(index, (unsigned int)-1);
|
remove(index, (unsigned int)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::remove(unsigned int index, unsigned int count){
|
void ICACHE_FLASH_ATTR String::remove(unsigned int index, unsigned int count){
|
||||||
if (index >= len) { return; }
|
if (index >= len) { return; }
|
||||||
if (count <= 0) { return; }
|
if (count <= 0) { return; }
|
||||||
if (count > len - index) { count = len - index; }
|
if (count > len - index) { count = len - index; }
|
||||||
@ -665,7 +667,7 @@ void String::remove(unsigned int index, unsigned int count){
|
|||||||
buffer[len] = 0;
|
buffer[len] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::toLowerCase(void)
|
void ICACHE_FLASH_ATTR String::toLowerCase(void)
|
||||||
{
|
{
|
||||||
if (!buffer) return;
|
if (!buffer) return;
|
||||||
for (char *p = buffer; *p; p++) {
|
for (char *p = buffer; *p; p++) {
|
||||||
@ -673,7 +675,7 @@ void String::toLowerCase(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::toUpperCase(void)
|
void ICACHE_FLASH_ATTR String::toUpperCase(void)
|
||||||
{
|
{
|
||||||
if (!buffer) return;
|
if (!buffer) return;
|
||||||
for (char *p = buffer; *p; p++) {
|
for (char *p = buffer; *p; p++) {
|
||||||
@ -681,7 +683,7 @@ void String::toUpperCase(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::trim(void)
|
void ICACHE_FLASH_ATTR String::trim(void)
|
||||||
{
|
{
|
||||||
if (!buffer || len == 0) return;
|
if (!buffer || len == 0) return;
|
||||||
char *begin = buffer;
|
char *begin = buffer;
|
||||||
@ -693,18 +695,18 @@ void String::trim(void)
|
|||||||
buffer[len] = 0;
|
buffer[len] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
/* Parsing / Conversion */
|
// /* Parsing / Conversion */
|
||||||
/*********************************************/
|
// /*********************************************/
|
||||||
|
|
||||||
long String::toInt(void) const
|
long ICACHE_FLASH_ATTR String::toInt(void) const
|
||||||
{
|
{
|
||||||
if (buffer) return atol(buffer);
|
if (buffer) return atol_internal(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float String::toFloat(void) const
|
float ICACHE_FLASH_ATTR String::toFloat(void) const
|
||||||
{
|
{
|
||||||
if (buffer) return float(atof(buffer));
|
if (buffer) return float(atof_internal(buffer));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user