diff --git a/src/env_manip.h b/src/env_manip.h index 30888f3..fa1be09 100644 --- a/src/env_manip.h +++ b/src/env_manip.h @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/14 13:46:39 by jguelen #+# #+# */ -/* Updated: 2025/02/18 16:47:34 by khais ### ########.fr */ +/* Updated: 2025/02/19 13:07:32 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ # define ENV_MANIP_H # include +# include # include "libft.h" typedef struct s_env @@ -39,5 +40,6 @@ void env_destroy_node(t_env *node); void env_destroy(t_env *env); void envp_destroy(char **envp); t_env *env_find_node_bykey(t_env *env, char *key); +bool identifier_isvalid(char *id); #endif diff --git a/src/env_manip_utils.c b/src/env_manip_utils.c index a5fbb2a..2049e6a 100644 --- a/src/env_manip_utils.c +++ b/src/env_manip_utils.c @@ -3,15 +3,16 @@ /* ::: :::::::: */ /* env_manip_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/14 18:31:38 by jguelen #+# #+# */ -/* Updated: 2025/02/18 16:40:32 by khais ### ########.fr */ +/* Created: 2025/02/19 13:16/49 by khais #+# #+# */ +/* Updated: 2025/02/19 13:16:49 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "env_manip.h" #include "libft.h" +#include /* ** Free all memory related to a given envp structure @@ -79,3 +80,25 @@ t_env *env_find_node_bykey(t_env *env, char *key) } return (NULL); } + +/* +** Return true if id is a valid bash identifier, false otherwise. +** +** A valid identifier starts with one of a-zA-Z_ +** It can contain any char a-zA-Z0-9_ +** It must contain at least one char +*/ +bool identifier_isvalid(char *id) +{ + if (id == NULL || id[0] == '\0') + return (false); + if (!ft_isalpha(id[0]) && id[0] != '_') + return (false); + while (*id != '\0') + { + if (!ft_isalpha(*id) && !ft_isdigit(*id) && *id != '_') + return (false); + id++; + } + return (true); +}