Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/misc/string.c → src/string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>

#include <limits.h>
void *memset(void *s, int c, size_t count)
{
char *xs = (char *)s;
Expand Down
94 changes: 94 additions & 0 deletions test/include/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) mlibc & plct lab
*
* SPDX-License-Identifier: MIT
*
* Change Logs:
* Date Author Notes
* 2023/06/16 bernard the first verison
*/

#ifndef MLIBC_CTYPE_H__
#define MLIBC_CTYPE_H__

#ifdef __cplusplus
extern "C" {
#endif

static inline int isupper(int a)
{
return (int)(((unsigned)(a)-(unsigned)'A') < 26U);
}

static inline int isalpha(int c)
{
return (int)((((unsigned)c|32u)-(unsigned)'a') < 26U);
}

static inline int isspace(int c)
{
return (int)(c == (int)' ' || ((unsigned)c-(unsigned)'\t') < 5U);
}

static inline int isgraph(int c)
{
return (int)((((unsigned)c) > ' ') && (((unsigned)c) <= (unsigned)'~'));
}

static inline int isprint(int c)
{
return (int)((((unsigned)c) >= ' ') && (((unsigned)c) <= (unsigned)'~'));
}

static inline int isdigit(int a)
{
return (int)(((unsigned)(a)-(unsigned)'0') < 10U);
}

static inline int isxdigit(int a)
{
unsigned int ua = (unsigned int)a;

return (int)(((ua - (unsigned)'0') < 10U) || ((ua | 32U) - (unsigned)'a' < 6U));
}

static inline int tolower(int chr)
{
return (chr >= (int)'A' && chr <= (int)'Z') ? (chr + 32) : (chr);
}

static inline int islower(int c)
{
return ((unsigned)c - 'a') < 26;
}

static inline int toupper(int chr)
{
return (int)((chr >= (int)'a' && chr <= (int)'z') ? (chr - 32) : (chr));
}

static inline int isalnum(int chr)
{
return (int)(isalpha(chr) || isdigit(chr));
}

static inline int isblank(int c)
{
return (c == ' ' || c == '\t');
}

static inline int iscntrl(int c)
{
return ((unsigned)c < 0x20 || c == 0x7F);
}

static inline int ispunct(int c)
{
return isgraph(c) && !isalnum(c);
}

#ifdef __cplusplus
}
#endif

#endif /*MLIBC_CTYPE_H__*/
45 changes: 45 additions & 0 deletions test/include/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) mlibc & plct lab
*
* SPDX-License-Identifier: MIT
*
* Change Logs:
* Date Author Notes
* 2021-02-17 Bernard first version
* 2021-05-02 Meco Man implement strcpy memmove5
*/

#ifndef MLIBC_STRING_H__
#define MLIBC_STRING_H__

#include "stdint.h"
#include <sys/types.h>

void *memset(void *s, int c, size_t count);
void *memcpy(void *dst, const void *src, size_t count);
int memcmp(const void *cs, const void *ct, size_t count);
void *memmove(void *d, const void *s, size_t n);
void* memchr(const void* m, int c, size_t n);

size_t strlen(const char *s);
int strcmp(const char *cs, const char *ct);
int strncmp(const char *cs, const char *ct, size_t count);
char *strcpy(char *d, const char *s);
char *strncpy(char *dst, const char *src, size_t n);
char *strcat(char * dest, const char * src);
char *strncat(char *dest, const char *src, size_t count);
char* strrchr(const char* s, int c);
char *strchr(const char* str, int c);
char *__strchrnul(const char *s, int c);
char* strstr(const char* string, const char* substring);
char *strrev(char *str);
size_t strcspn(const char* s, const char* c);
char* strtok_r(char* s, const char* delim, char** last);
char* strtok(char* s, const char* delim);
char *strpbrk(const char *s1, const char *s2);
size_t strspn(const char *s, const char *group);
size_t strxfrm(char *dest, const char *src, size_t n);
char *strdup(const char *s);
char *strndup (const char *, size_t);

#endif /*MLIBC_STRING_H__*/
Loading