Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

String: compatibility with 64 bits scalars#7863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
earlephilhower merged 9 commits intoesp8266:masterfromd-a-v:StringLL
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
String: compatibility with 64 bits scalars
time_t is now 64 bits. Strig(time_t) was ambiguoustests added
  • Loading branch information
@d-a-v
d-a-v committedFeb 7, 2021
commitfa09a5079d67931c9f23a22b9caa1a78fbef19d1
36 changes: 36 additions & 0 deletionscores/esp8266/WString.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -98,6 +98,32 @@ String::String(unsigned long value, unsigned char base) {
*this = buf;
}

String::String(long long value) {
init();
char buf[2 + 8 * sizeof(long long)];
sprintf(buf, "%lld", value);
*this = buf;
}

String::String(long long value, unsigned char base) {
init();
char buf[2 + 8 * sizeof(long long)];
*this = lltoa(value, buf, sizeof(buf), base);
}

String::String(unsigned long long value) {
init();
char buf[1 + 8 * sizeof(unsigned long long)];
sprintf(buf, "%llu", value);
*this = buf;
}

String::String(unsigned long long value, unsigned char base) {
init();
char buf[1 + 8 * sizeof(unsigned long long)];
*this = ulltoa(value, buf, sizeof(buf), base);
}

String::String(float value, unsigned char decimalPlaces) {
init();
char buf[33];
Expand DownExpand Up@@ -313,6 +339,16 @@ unsigned char String::concat(unsigned long num) {
return concat(buf, strlen(buf));
}

unsigned char String::concat(long long num) {
char buf[2 + 3 * sizeof(long long)];
return concat(buf, sprintf(buf, "%lld", num));
}

unsigned char String::concat(unsigned long long num) {
char buf[1 + 3 * sizeof(unsigned long long)];
return concat(buf, sprintf(buf, "%llu", num));
}

unsigned char String::concat(float num) {
char buf[20];
char *string = dtostrf(num, 4, 2, buf);
Expand Down
22 changes: 22 additions & 0 deletionscores/esp8266/WString.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,6 +72,10 @@ class String {
explicit String(unsigned int, unsigned char base = 10);
explicit String(long, unsigned char base = 10);
explicit String(unsigned long, unsigned char base = 10);
explicit String(long long /* base 10 */);
explicit String(long long, unsigned char base);
explicit String(unsigned long long /* base 10 */);
explicit String(unsigned long long, unsigned char base);
explicit String(float, unsigned char decimalPlaces = 2);
explicit String(double, unsigned char decimalPlaces = 2);
~String() {
Expand DownExpand Up@@ -117,6 +121,8 @@ class String {
unsigned char concat(unsigned int num);
unsigned char concat(long num);
unsigned char concat(unsigned long num);
unsigned char concat(long long num);
unsigned char concat(unsigned long long num);
unsigned char concat(float num);
unsigned char concat(double num);
unsigned char concat(const __FlashStringHelper *str);
Expand DownExpand Up@@ -156,6 +162,14 @@ class String {
concat(num);
return *this;
}
String &operator +=(long long num) {
concat(num);
return *this;
}
String &operator +=(unsigned long long num) {
concat(num);
return *this;
}
String &operator +=(float num) {
concat(num);
return *this;
Expand All@@ -177,6 +191,8 @@ class String {
friend StringSumHelper &operator +(const StringSumHelper &lhs, unsigned int num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, long num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, unsigned long num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, long long num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, unsigned long long num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, float num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, double num);
friend StringSumHelper &operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);
Expand DownExpand Up@@ -375,6 +391,12 @@ class StringSumHelper: public String {
StringSumHelper(unsigned long num) :
String(num) {
}
StringSumHelper(long long num) :
String(num) {
}
StringSumHelper(unsigned long long num) :
String(num) {
}
StringSumHelper(float num) :
String(num) {
}
Expand Down
2 changes: 1 addition & 1 deletioncores/esp8266/debug.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols)
while (len > 0)
{
uint32_t linesize = cols > len ? len : cols;
os_printf("\n[%p] 0x%04x: ", src, src - (const char*)mem);
os_printf("\n[%p] 0x%04x: ", src,(int)(src - (const char*)mem));
for (uint32_t i = 0; i < linesize; i++)
{
os_printf("%02x ", *(src + i));
Expand Down
38 changes: 38 additions & 0 deletionscores/esp8266/stdlib_noniso.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@

#include "stdlib_noniso.h"

// fill backwards
char* ulltoa(unsigned long long val, char* str, size_t slen, uint_fast8_t radix)
{
str += --slen;
*str = 0;
do
{
auto n = val % radix;
val /= radix;
*--str = n + ((n > 9) ? ('a' - 10) : '0');
} while (--slen && val);
return val? nullptr: str;
}

char* lltoa (long long val, char* str, size_t slen, uint_fast8_t radix)
{
bool neg;
if (val < 0)
{
val = -val;
neg = true;
}
else
{
neg = false;
}
char* ret = ulltoa(val, str, slen, radix);
if (neg)
{
if (ret == str)
return nullptr;
*--ret = '-';
}
return ret;
}
8 changes: 7 additions & 1 deletioncores/esp8266/stdlib_noniso.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,8 @@
#ifndef STDLIB_NONISO_H
#define STDLIB_NONISO_H

#include <stdint.h>

#ifdef __cplusplus
extern "C"{
#endif
Expand All@@ -36,10 +38,14 @@ char* itoa (int val, char *s, int radix);

char* ltoa (long val, char *s, int radix);

char* lltoa (long long val, char* str, size_t slen, uint_fast8_t radix);

char* utoa (unsigned int val, char *s, int radix);

char* ultoa (unsigned long val, char *s, int radix);


char* ulltoa (unsigned long long val, char* str, size_t slen, uint_fast8_t radix);

char* dtostrf (double val, signed char width, unsigned char prec, char *s);

void reverse(char* begin, char* end);
Expand Down
1 change: 1 addition & 0 deletionstests/host/Makefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,6 +80,7 @@ CORE_CPP_FILES := \
Stream.cpp \
WString.cpp \
Print.cpp \
stdlib_noniso.cpp \
FS.cpp \
spiffs_api.cpp \
MD5Builder.cpp \
Expand Down
10 changes: 10 additions & 0 deletionstests/host/core/test_string.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -132,6 +132,16 @@ TEST_CASE("String concantenation", "[core][String]")
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.01");
str += (double)1.01;
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.011.01");
str += LLONG_MIN;
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.011.01-9223372036854775808");
str += String(LLONG_MIN, 10);
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.011.01-9223372036854775808-9223372036854775808");
str += LLONG_MAX;
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.011.01-9223372036854775808-92233720368547758089223372036854775807");
str += ULLONG_MAX;
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.011.01-9223372036854775808-9223372036854775808922337203685477580718446744073709551615");
str += String(ULLONG_MAX, 16);
REQUIRE(str == "abcdeabcde9872147483647-2147483648691969-123321-1.011.01-9223372036854775808-9223372036854775808922337203685477580718446744073709551615ffffffffffffffff");
str = "clean";
REQUIRE(str.concat(str) == true);
REQUIRE(str == "cleanclean");
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp