aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-04-11 12:22:51 +0200
committerMarco Paland <marco@paland.com>2018-04-19 16:12:04 +0200
commit8c3713c4b605d83bd47722d5e9ac5efb2e2471f8 (patch)
treef21f078d0942ab6076100093935f0041ccf4a92b
parent6f249a28141b386a085afc245b147869f82a61e4 (diff)
downloadprintf-8c3713c4b605d83bd47722d5e9ac5efb2e2471f8.tar.gz
printf-8c3713c4b605d83bd47722d5e9ac5efb2e2471f8.tar.bz2
printf-8c3713c4b605d83bd47722d5e9ac5efb2e2471f8.zip
refactor(printf): improved _strlen() function
-rw-r--r--printf.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/printf.c b/printf.c
index 3cc7aa2..21d5620 100644
--- a/printf.c
+++ b/printf.c
@@ -70,22 +70,21 @@
// \return The length of the string (excluding the terminating 0)
static inline size_t _strlen(const char* str)
{
- size_t len = 0U;
- while (str[len] != (char)0) {
- len++;
- }
- return len;
+ const char* s;
+ for (s = str; *s; ++s);
+ return (size_t)(s - str);
}
-// returns true if char is a digit
+// internal test if char is a digit (0-9)
+// \return true if char is a digit
static inline bool _is_digit(char ch)
{
return (ch >= '0') && (ch <= '9');
}
-// internal ASCII to unsigned int conversion
+// internal ASCII string to unsigned int conversion
static inline unsigned int _atoi(const char** str)
{
unsigned int i = 0U;