Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
722c4641
Unverified
Commit
722c4641
authored
May 18, 2022
by
Rodrigo Garcia
Committed by
GitHub
May 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extends String to print 64-bit integers (#6768)
parent
ba6e82c3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
0 deletions
+115
-0
cores/esp32/WString.cpp
cores/esp32/WString.cpp
+43
-0
cores/esp32/WString.h
cores/esp32/WString.h
+20
-0
cores/esp32/stdlib_noniso.c
cores/esp32/stdlib_noniso.c
+48
-0
cores/esp32/stdlib_noniso.h
cores/esp32/stdlib_noniso.h
+4
-0
No files found.
cores/esp32/WString.cpp
View file @
722c4641
...
...
@@ -137,6 +137,24 @@ String::String(double value, unsigned int decimalPlaces) {
}
}
String
::
String
(
long
long
value
,
unsigned
char
base
)
{
init
();
char
buf
[
2
+
8
*
sizeof
(
long
long
)];
if
(
base
==
10
)
{
sprintf
(
buf
,
"%lld"
,
value
);
// NOT SURE - NewLib Nano ... does it support %lld?
}
else
{
lltoa
(
value
,
buf
,
base
);
}
*
this
=
buf
;
}
String
::
String
(
unsigned
long
long
value
,
unsigned
char
base
)
{
init
();
char
buf
[
1
+
8
*
sizeof
(
unsigned
long
long
)];
ulltoa
(
value
,
buf
,
base
);
*
this
=
buf
;
}
String
::~
String
()
{
invalidate
();
}
...
...
@@ -408,6 +426,17 @@ unsigned char String::concat(double num) {
return
concat
(
string
,
strlen
(
string
));
}
unsigned
char
String
::
concat
(
long
long
num
)
{
char
buf
[
2
+
3
*
sizeof
(
long
long
)];
return
concat
(
buf
,
sprintf
(
buf
,
"%lld"
,
num
));
// NOT SURE - NewLib Nano ... does it support %lld?
}
unsigned
char
String
::
concat
(
unsigned
long
long
num
)
{
char
buf
[
1
+
3
*
sizeof
(
unsigned
long
long
)];
ulltoa
(
num
,
buf
,
10
);
return
concat
(
buf
,
strlen
(
buf
));
}
unsigned
char
String
::
concat
(
const
__FlashStringHelper
*
str
)
{
if
(
!
str
)
return
0
;
int
length
=
strlen_P
((
PGM_P
)
str
);
...
...
@@ -493,6 +522,20 @@ StringSumHelper & operator +(const StringSumHelper &lhs, double num) {
return
a
;
}
StringSumHelper
&
operator
+
(
const
StringSumHelper
&
lhs
,
long
long
num
)
{
StringSumHelper
&
a
=
const_cast
<
StringSumHelper
&>
(
lhs
);
if
(
!
a
.
concat
(
num
))
a
.
invalidate
();
return
a
;
}
StringSumHelper
&
operator
+
(
const
StringSumHelper
&
lhs
,
unsigned
long
long
num
)
{
StringSumHelper
&
a
=
const_cast
<
StringSumHelper
&>
(
lhs
);
if
(
!
a
.
concat
(
num
))
a
.
invalidate
();
return
a
;
}
StringSumHelper
&
operator
+
(
const
StringSumHelper
&
lhs
,
const
__FlashStringHelper
*
rhs
)
{
StringSumHelper
&
a
=
const_cast
<
StringSumHelper
&>
(
lhs
);
...
...
cores/esp32/WString.h
View file @
722c4641
...
...
@@ -73,6 +73,8 @@ class String {
explicit
String
(
unsigned
long
,
unsigned
char
base
=
10
);
explicit
String
(
float
,
unsigned
int
decimalPlaces
=
2
);
explicit
String
(
double
,
unsigned
int
decimalPlaces
=
2
);
explicit
String
(
long
long
,
unsigned
char
base
=
10
);
explicit
String
(
unsigned
long
long
,
unsigned
char
base
=
10
);
~
String
(
void
);
// memory management
...
...
@@ -122,6 +124,8 @@ class String {
unsigned
char
concat
(
unsigned
long
num
);
unsigned
char
concat
(
float
num
);
unsigned
char
concat
(
double
num
);
unsigned
char
concat
(
long
long
num
);
unsigned
char
concat
(
unsigned
long
long
num
);
unsigned
char
concat
(
const
__FlashStringHelper
*
str
);
// if there's not enough memory for the concatenated value, the string
...
...
@@ -166,6 +170,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
+=
(
const
__FlashStringHelper
*
str
){
concat
(
str
);
return
(
*
this
);
...
...
@@ -182,6 +194,8 @@ class String {
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
);
friend
StringSumHelper
&
operator
+
(
const
StringSumHelper
&
lhs
,
long
long
num
);
friend
StringSumHelper
&
operator
+
(
const
StringSumHelper
&
lhs
,
unsigned
long
long
num
);
// comparison (only works w/ Strings and "strings")
operator
StringIfHelperType
()
const
{
...
...
@@ -373,6 +387,12 @@ class StringSumHelper: public String {
StringSumHelper
(
double
num
)
:
String
(
num
)
{
}
StringSumHelper
(
long
long
num
)
:
String
(
num
)
{
}
StringSumHelper
(
unsigned
long
long
num
)
:
String
(
num
)
{
}
};
extern
const
String
emptyString
;
...
...
cores/esp32/stdlib_noniso.c
View file @
722c4641
...
...
@@ -67,6 +67,31 @@ char* ltoa(long value, char* result, int base) {
return
result
;
}
char
*
lltoa
(
long
long
val
,
char
*
result
,
int
base
)
{
if
(
base
<
2
||
base
>
16
)
{
*
result
=
0
;
return
result
;
}
char
*
out
=
result
;
long
long
quotient
=
val
>
0
?
val
:
-
val
;
do
{
const
long
long
tmp
=
quotient
/
base
;
*
out
=
"0123456789abcdef"
[
quotient
-
(
tmp
*
base
)];
++
out
;
quotient
=
tmp
;
}
while
(
quotient
);
// Apply negative sign
if
(
val
<
0
)
*
out
++
=
'-'
;
reverse
(
result
,
out
);
*
out
=
0
;
return
result
;
}
char
*
ultoa
(
unsigned
long
value
,
char
*
result
,
int
base
)
{
if
(
base
<
2
||
base
>
16
)
{
*
result
=
0
;
...
...
@@ -88,6 +113,27 @@ char* ultoa(unsigned long value, char* result, int base) {
return
result
;
}
char
*
ulltoa
(
unsigned
long
long
val
,
char
*
result
,
int
base
)
{
if
(
base
<
2
||
base
>
16
)
{
*
result
=
0
;
return
result
;
}
char
*
out
=
result
;
unsigned
long
long
quotient
=
val
;
do
{
const
unsigned
long
long
tmp
=
quotient
/
base
;
*
out
=
"0123456789abcdef"
[
quotient
-
(
tmp
*
base
)];
++
out
;
quotient
=
tmp
;
}
while
(
quotient
);
reverse
(
result
,
out
);
*
out
=
0
;
return
result
;
}
char
*
dtostrf
(
double
number
,
signed
int
width
,
unsigned
int
prec
,
char
*
s
)
{
bool
negative
=
false
;
...
...
@@ -160,3 +206,5 @@ char * dtostrf(double number, signed int width, unsigned int prec, char *s) {
*
out
=
0
;
return
s
;
}
cores/esp32/stdlib_noniso.h
View file @
722c4641
...
...
@@ -35,10 +35,14 @@ char* itoa (int val, char *s, int radix);
char
*
ltoa
(
long
val
,
char
*
s
,
int
radix
);
char
*
lltoa
(
long
long
val
,
char
*
s
,
int
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
*
s
,
int
radix
);
char
*
dtostrf
(
double
val
,
signed
int
width
,
unsigned
int
prec
,
char
*
s
);
#ifdef __cplusplus
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment