mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-26 11:30:03 +05:30
52 lines
1.9 KiB
C
52 lines
1.9 KiB
C
/*
|
|
* string_case.h
|
|
*
|
|
* Author: Intel A80486DX2-66
|
|
* License: Unlicense
|
|
*/
|
|
|
|
#ifndef _STRING_CASE_H
|
|
#define _STRING_CASE_H
|
|
|
|
#ifdef __STDC_ALLOC_LIB__
|
|
# define __STDC_WANT_LIB_EXT2__ 1
|
|
#else
|
|
# define _POSIX_C_SOURCE 200809L
|
|
#endif
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define ASCII_IS_LOWER(c) ((c) >= 'a' && (c) <= 'z')
|
|
#define ASCII_IS_UPPER(c) ((c) >= 'A' && (c) <= 'Z')
|
|
#define ASCII_IS_ALPHA(c) (ASCII_IS_LOWER(c) || ASCII_IS_UPPER(c))
|
|
#define ASCII_MOD_ALPHA(c, v) (ASCII_IS_ALPHA(c) ? v : c)
|
|
#define ASCII_LOWERCASE(c) (ASCII_MOD_ALPHA((c), (c) | 0x20))
|
|
#define ASCII_UPPERCASE(c) (ASCII_MOD_ALPHA((c), ASCII_LOWERCASE(c) - 0x20))
|
|
#define ASCII_MOD_STRM(s, m) \
|
|
char* ptr = s; \
|
|
while (*ptr) { \
|
|
*ptr = m(*ptr); \
|
|
ptr++; \
|
|
} \
|
|
return s
|
|
|
|
#define ASCII_MOD_STR(s, m) \
|
|
char* s_dup = strdup((s)), * ptr = s_dup; \
|
|
while (*ptr) { \
|
|
*ptr = m(*ptr); \
|
|
ptr++; \
|
|
} \
|
|
return s_dup
|
|
|
|
#define ASCII_UPPERCASE_STRM_T(s) ASCII_MOD_STRM(s, ASCII_UPPERCASE)
|
|
#define ASCII_LOWERCASE_STRM_T(s) ASCII_MOD_STRM(s, ASCII_LOWERCASE)
|
|
#define ASCII_UPPERCASE_STR_T(s) ASCII_MOD_STR(s, ASCII_UPPERCASE)
|
|
#define ASCII_LOWERCASE_STR_T(s) ASCII_MOD_STR(s, ASCII_LOWERCASE)
|
|
|
|
char* ascii_lowercase_str(const char* s);
|
|
char* ascii_lowercase_strm(char* s);
|
|
char* ascii_uppercase_str(const char* s);
|
|
char* ascii_uppercase_strm(char* s);
|
|
|
|
#endif /* _STRING_CASE_H */
|