From 861efcd159e9ba5478a3553a38d69134c9a48741 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 18 Jan 2022 12:44:55 +0500 Subject: [PATCH] Remove func kernaux_itoa --- include/kernaux/itoa.h | 3 --- src/itoa.c | 41 ----------------------------------------- tests/test_itoa.c | 24 ------------------------ 3 files changed, 68 deletions(-) diff --git a/include/kernaux/itoa.h b/include/kernaux/itoa.h index b9eddd2..def7dbe 100644 --- a/include/kernaux/itoa.h +++ b/include/kernaux/itoa.h @@ -10,9 +10,6 @@ extern "C" { // uint64_t: "18446744073709551615" #define KERNAUX_ITOA_BUFFER_SIZE 21 -// TODO: remove this -void kernaux_itoa(int d, char *buf, int base); - void kernaux_utoa10(uint64_t value, char *buffer); #ifdef __cplusplus diff --git a/src/itoa.c b/src/itoa.c index 34cd603..8902e82 100644 --- a/src/itoa.c +++ b/src/itoa.c @@ -3,47 +3,6 @@ #endif #include -#include - -void kernaux_itoa(const int d, char *buf, const int base) -{ - char *p = buf; - char *p1, *p2; - unsigned long ud = d; - int divisor = 10; - - // If %d is specified and D is minus, put '-' in the head. - if (base == 'd' && d < 0) { - *p++ = '-'; - buf++; - ud = -d; - } - else if (base == 'x') { - divisor = 16; - } - - // Divide UD by DIVISOR until UD == 0. - do { - int remainder = ud % divisor; - *p++ = (remainder < 10) ? remainder + '0' : remainder + 'A' - 10; - } - while (ud /= divisor); - - // Terminate BUF. - *p = '\0'; - - // Reverse BUF. - p1 = buf; - p2 = p - 1; - - while (p1 < p2) { - char tmp = *p1; - *p1 = *p2; - *p2 = tmp; - p1++; - p2--; - } -} void kernaux_utoa10(uint64_t value, char *buffer) { diff --git a/tests/test_itoa.c b/tests/test_itoa.c index 09ec675..5c1e926 100644 --- a/tests/test_itoa.c +++ b/tests/test_itoa.c @@ -48,30 +48,6 @@ static const struct { int main() { - { - char buffer[10]; - - kernaux_itoa(495, buffer, 'd'); - - assert(buffer[0] == '4'); - assert(buffer[1] == '9'); - assert(buffer[2] == '5'); - assert(buffer[3] == '\0'); - } - - { - char buffer[10]; - - kernaux_itoa(-7012, buffer, 'd'); - - assert(buffer[0] == '-'); - assert(buffer[1] == '7'); - assert(buffer[2] == '0'); - assert(buffer[3] == '1'); - assert(buffer[4] == '2'); - assert(buffer[5] == '\0'); - } - char buffer[KERNAUX_ITOA_BUFFER_SIZE]; for (