Skip to content

Commit

Permalink
[Update] - ctype (qdd comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaucoul committed Jul 22, 2024
1 parent 3ccde5a commit 10a1196
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Hephaistos/libs/convert/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/20 22:59:13 by vvaucoul #+# #+# */
/* Updated: 2024/01/15 11:58:02 by vvaucoul ### ########.fr */
/* Updated: 2024/07/22 12:55:40 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
8 changes: 3 additions & 5 deletions Hephaistos/libs/convert/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/20 22:58:53 by vvaucoul #+# #+# */
/* Updated: 2024/07/21 23:55:15 by vvaucoul ### ########.fr */
/* Updated: 2024/07/22 12:48:32 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,16 +19,14 @@
#define __ITOA_BUFFER_LENGTH__ 12
#define __ASCII_BASE__ "0123456789ABCDEF"

/* Conversion functions using stack-based buffers */
extern int atoi(const char *str);
extern int itoa(int nbr, char str[__ITOA_BUFFER_LENGTH__]);
extern int uitoa(uint32_t nbr, char str[__ITOA_BUFFER_LENGTH__]);
extern int itoa_base(int nbr, int base, char str[__ITOA_BUFFER_LENGTH__]);
extern uint32_t uitoa_base(uint32_t nbr, int base, char str[__ITOA_BUFFER_LENGTH__]);

// ! ||--------------------------------------------------------------------------------||
// ! || SAFE FUNCTIONS (MEMORY AVAILABLE) ||
// ! ||--------------------------------------------------------------------------------||

/* Conversion functions using heap-based buffers */
extern int atoi_base_s(const char *str, int base);
extern char *itoa_s(int nbr);
extern char *uitoa_s(uint32_t nbr);
Expand Down
92 changes: 91 additions & 1 deletion Hephaistos/libs/ctype/ctype.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,158 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/20 13:24:25 by vvaucoul #+# #+# */
/* Updated: 2024/01/14 12:34:34 by vvaucoul ### ########.fr */
/* Updated: 2024/07/22 12:56:57 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

#include "ctype.h"

/**
* @brief Check if a character is alphanumeric.
*
* @param c The character to check.
* @return true if the character is alphanumeric, false otherwise.
*/
bool isalnum(uchar_t c) {
return (isalpha(c) || isdigit(c));
}

/**
* @brief Check if a character is alphabetic.
*
* @param c The character to check.
* @return true if the character is alphabetic, false otherwise.
*/
bool isalpha(uchar_t c) {
return (islower(c) || isupper(c));
}

/**
* @brief Check if a character is a blank space or tab.
*
* @param c The character to check.
* @return true if the character is a blank space or tab, false otherwise.
*/
bool isblank(uchar_t c) {
return (c == ' ' || c == '\t');
}

/**
* @brief Check if a character is a control character.
*
* @param c The character to check.
* @return true if the character is a control character, false otherwise.
*/
bool iscntrl(uchar_t c) {
return (c >= 0 && c <= 31) || c == 127;
}

/**
* @brief Check if a character is a digit.
*
* @param c The character to check.
* @return true if the character is a digit, false otherwise.
*/
bool isdigit(uchar_t c) {
return (c >= '0' && c <= '9');
}

/**
* @brief Check if a character is a printable character except space.
*
* @param c The character to check.
* @return true if the character is a printable character except space, false otherwise.
*/
bool isgraph(uchar_t c) {
return (c >= 33 && c <= 126);
}

/**
* @brief Check if a character is a lowercase letter.
*
* @param c The character to check.
* @return true if the character is a lowercase letter, false otherwise.
*/
bool islower(uchar_t c) {
return (c >= 'a' && c <= 'z');
}

/**
* @brief Check if a character is a printable character.
*
* @param c The character to check.
* @return true if the character is a printable character, false otherwise.
*/
bool isprint(uchar_t c) {
return (c >= 32 && c <= 126);
}

/**
* @brief Check if a character is a punctuation character.
*
* @param c The character to check.
* @return true if the character is a punctuation character, false otherwise.
*/
bool ispunct(uchar_t c) {
return (isgraph(c) && !isalnum(c));
}

/**
* @brief Check if a character is an uppercase letter.
*
* @param c The character to check.
* @return true if the character is an uppercase letter, false otherwise.
*/
bool isupper(uchar_t c) {
return (c >= 'A' && c <= 'Z');
}

/**
* @brief Check if a character is a hexadecimal digit.
*
* @param c The character to check.
* @return true if the character is a hexadecimal digit, false otherwise.
*/
bool isxdigit(uchar_t c) {
return (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
}

/**
* @brief Check if a character is a valid ASCII character.
*
* @param c The character to check.
* @return true if the character is a valid ASCII character, false otherwise.
*/
bool isascii(uchar_t c) {
return (c >= 0 && c <= 127);
}

/**
* @brief Convert a character to its ASCII equivalent.
*
* @param c The character to convert.
* @return The ASCII equivalent of the character.
*/
uchar_t toascii(uchar_t c) {
return (c & 0x7F);
}

/**
* @brief Convert a character to lowercase.
*
* @param c The character to convert.
* @return The lowercase equivalent of the character.
*/
uchar_t tolower(uchar_t c) {
return (isupper(c) ? c + 32 : c);
}

/**
* @brief Convert a character to uppercase.
*
* @param c The character to convert.
* @return The uppercase equivalent of the character.
*/
uchar_t toupper(uchar_t c) {
return (islower(c) ? c - 32 : c);
}
2 changes: 1 addition & 1 deletion Hephaistos/workflows/tests/workflow_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vvaucoul <vvaucoul@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 19:13:30 by vvaucoul #+# #+# */
/* Updated: 2024/01/15 11:58:39 by vvaucoul ### ########.fr */
/* Updated: 2024/07/22 12:56:03 by vvaucoul ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit 10a1196

Please sign in to comment.