Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
71455b69
Commit
71455b69
authored
6 years ago
by
Vincent Dupont
Browse files
Options
Downloads
Patches
Plain Diff
fmt: add fmt_to_lower()
parent
a542e954
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sys/fmt/fmt.c
+31
-0
31 additions, 0 deletions
sys/fmt/fmt.c
sys/include/fmt.h
+8
-0
8 additions, 0 deletions
sys/include/fmt.h
tests/unittests/tests-fmt/tests-fmt.c
+11
-0
11 additions, 0 deletions
tests/unittests/tests-fmt/tests-fmt.c
with
50 additions
and
0 deletions
sys/fmt/fmt.c
+
31
−
0
View file @
71455b69
...
@@ -53,6 +53,16 @@ static inline int _is_digit(char c)
...
@@ -53,6 +53,16 @@ static inline int _is_digit(char c)
return
(
c
>=
'0'
&&
c
<=
'9'
);
return
(
c
>=
'0'
&&
c
<=
'9'
);
}
}
static
inline
int
_is_upper
(
char
c
)
{
return
(
c
>=
'A'
&&
c
<=
'Z'
);
}
static
inline
char
_to_lower
(
char
c
)
{
return
'a'
+
(
c
-
'A'
);
}
size_t
fmt_byte_hex
(
char
*
out
,
uint8_t
byte
)
size_t
fmt_byte_hex
(
char
*
out
,
uint8_t
byte
)
{
{
if
(
out
)
{
if
(
out
)
{
...
@@ -405,6 +415,27 @@ size_t fmt_lpad(char *out, size_t in_len, size_t pad_len, char pad_char)
...
@@ -405,6 +415,27 @@ size_t fmt_lpad(char *out, size_t in_len, size_t pad_len, char pad_char)
return
pad_len
;
return
pad_len
;
}
}
{
size_t
fmt_to_lower
(
char
*
out
,
const
char
*
str
)
{
size_t
len
=
0
;
while
(
str
&&
*
str
)
{
if
(
_is_upper
(
*
str
))
{
if
(
out
)
{
*
out
++
=
_to_lower
(
*
str
);
}
}
else
if
(
out
)
{
*
out
++
=
*
str
;
}
str
++
;
len
++
;
}
return
len
;
}
uint32_t
scn_u32_dec
(
const
char
*
str
,
size_t
n
)
uint32_t
scn_u32_dec
(
const
char
*
str
,
size_t
n
)
{
{
uint32_t
res
=
0
;
uint32_t
res
=
0
;
...
...
This diff is collapsed.
Click to expand it.
sys/include/fmt.h
+
8
−
0
View file @
71455b69
...
@@ -343,6 +343,14 @@ size_t fmt_strnlen(const char *str, size_t maxlen);
...
@@ -343,6 +343,14 @@ size_t fmt_strnlen(const char *str, size_t maxlen);
*/
*/
size_t
fmt_str
(
char
*
out
,
const
char
*
str
);
size_t
fmt_str
(
char
*
out
,
const
char
*
str
);
/**
* @brief Copy null-terminated string to a lowercase string (excluding terminating \0)
*
* @param[out] out Pointer to output buffer, or NULL
* @param[in] str Pointer to null-terminated source string
*/
size_t
fmt_to_lower
(
char
*
out
,
const
char
*
str
);
/**
/**
* @brief Convert digits to uint32
* @brief Convert digits to uint32
*
*
...
...
This diff is collapsed.
Click to expand it.
tests/unittests/tests-fmt/tests-fmt.c
+
11
−
0
View file @
71455b69
...
@@ -749,6 +749,16 @@ static void test_fmt_str(void)
...
@@ -749,6 +749,16 @@ static void test_fmt_str(void)
TEST_ASSERT_EQUAL_STRING
(
string1
,
&
string2
[
0
]);
TEST_ASSERT_EQUAL_STRING
(
string1
,
&
string2
[
0
]);
}
}
static
void
test_fmt_to_lower
(
void
)
{
const
char
string_up
[]
=
"AbCdeFGHijkLM"
;
char
string
[]
=
"zzzzzzzzzzzzzzz"
;
TEST_ASSERT_EQUAL_INT
(
fmt_strlen
(
string_up
),
fmt_to_lower
(
string
,
string_up
));
string
[
fmt_strlen
(
string_up
)]
=
'\0'
;
TEST_ASSERT_EQUAL_STRING
(
"abcdefghijklm"
,
&
string
[
0
]);
}
static
void
test_scn_u32_dec
(
void
)
static
void
test_scn_u32_dec
(
void
)
{
{
const
char
*
string1
=
"123456789"
;
const
char
*
string1
=
"123456789"
;
...
@@ -817,6 +827,7 @@ Test *tests_fmt_tests(void)
...
@@ -817,6 +827,7 @@ Test *tests_fmt_tests(void)
new_TestFixture
(
test_fmt_strlen
),
new_TestFixture
(
test_fmt_strlen
),
new_TestFixture
(
test_fmt_strnlen
),
new_TestFixture
(
test_fmt_strnlen
),
new_TestFixture
(
test_fmt_str
),
new_TestFixture
(
test_fmt_str
),
new_TestFixture
(
test_fmt_to_lower
),
new_TestFixture
(
test_scn_u32_dec
),
new_TestFixture
(
test_scn_u32_dec
),
new_TestFixture
(
test_fmt_lpad
),
new_TestFixture
(
test_fmt_lpad
),
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment