-
Notifications
You must be signed in to change notification settings - Fork 2
/
sstring.h
135 lines (121 loc) · 6.01 KB
/
sstring.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Defines */
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* Error Codes */
#define SS_UNKNOWN 0x00
#define SS_OK 0x01
#define SS_DELETED 0x02
#define SS_SET_VALUE 0x03
#define SS_CONCATENATED 0x04
#define SS_ZEROED 0x05
#define SS_EQUAL 0x06
#define SS_NOT_EQUAL 0x07
#define SS_INVALID_BUFFER 0x08
#define SS_STRING_FOUND 0x09
#define SS_STRING_NOT_FOUND 0x10
#define SS_VERY_LARGE_STRING 0x11
#define SS_STRING_COPIED 0x12
#define SS_REPLACED 0x13
#define SS_TOLOWER_EXECUTED 0x14
#define SS_TOUPPER_EXECUTED 0x15
#define SS_POSITION_FOUND 0x16
#define SS_STRING_REVERTED 0x17
/* Constructor option */
#define use_sstring \
struct _sstring {\
struct sstring * (*new)(unsigned char *);\
} string = { new_sstring };\
/* Types. (Public) */
typedef unsigned int (*___error)(struct sstring *);
typedef unsigned char *(*___string)(struct sstring *);
typedef unsigned int (*___length)(struct sstring *);
typedef unsigned char *(*___value)(struct sstring *, const unsigned char *);
typedef void (*___delete)(struct sstring *);
typedef unsigned char *(*___concat)(struct sstring *, const unsigned char *);
typedef void (*___zero)(struct sstring *);
typedef int (*___compare)(struct sstring *, const unsigned char *);
typedef unsigned char *(*___search)(struct sstring *, const unsigned char *);
typedef unsigned char *(*___set_value)(struct sstring *, const unsigned char *, unsigned int);
typedef unsigned char *(*___replace)(struct sstring *, const unsigned char *, const unsigned char *);
typedef unsigned char *(*___tolower)(struct sstring *);
typedef unsigned char *(*___toupper)(struct sstring *);
typedef unsigned int (*___position)(struct sstring *, const unsigned char *);
typedef unsigned int (*___is_char)(const char);
typedef unsigned int (*___is_numeric)(const char);
typedef unsigned char *(*___revert)(struct sstring *);
/* Types. (Private) */
typedef unsigned int (*___len)(const unsigned char *);
typedef void *(*___set)(void *, unsigned int, unsigned int);
typedef void *(*___copy)(void *, const void *, unsigned int);
typedef void *(*___alloc)(void *, unsigned int);
typedef void (*___clear)(void *, unsigned int);
/* Structure of Sonic String. */
typedef struct sstring
{
int _last_error; // Armazena Código do ultimo erro.
unsigned char *_string_value; // Armazena Valor atual da string.
unsigned int _string_length; // Armazena Tamanho atual da string.
/* Public */
___error error; // Retorna ultimo código de erro.
___string string; // Retorna string atual.
___length length; // Retorna tamanho da string.
___value value; // Seta novo valor na string.
___delete delete; // Deleta string da memória.
___concat concat; // Concatena texto no final da string.
___zero zero; // Seta todos os bytes da string para '\0';
___compare compare; // Compara se strings são iguais.
___search search; // Procura por string.
___set_value set_value; // Substitui string a partir de uma determinada posição.
___replace replace; // Substitui todas as ocorrencias encontradas em uma string.
___tolower tolower; // Converte string para minuscula.
___toupper toupper; // Converte string para maiuscula.
___position position; // Retorna posição do delimitador na string.
___is_char is_char; // Verifica se caracter é alguma letra do alfabeto.
___is_numeric is_numeric; // Verifica se caracter é um número decimal.
___revert revert; // Reverte ordem dos caracteres da string.
/* Private */
___len _len; // Equivalente a strlen().
___set _set; // Equivalente a memset().
___copy _copy; // Equivalente a memcpy().
___alloc _alloc; // Equivalente a realloc().
___clear _clear; // Equivalente a free().
} sstring;
/* Prototypes. (Checking) */
int sstring_isok(sstring *this);
int sstring_array_isok(sstring *this[], int limit);
/* Prototypes. (Constructor) */
sstring *new_sstring(const unsigned char *string_initialization);
/* Prototypes. (Public) */
unsigned int _error(sstring *this);
unsigned char *_string(sstring *this);
unsigned int _length(sstring *this);
unsigned char *_value(sstring *this, const unsigned char *string);
void _delete(sstring *this);
unsigned char *_concat(sstring *this, const unsigned char *string);
void _zero(sstring *this);
unsigned int _compare(sstring *this, const unsigned char *string);
unsigned char *_search(sstring *this, const unsigned char *delimiter);
unsigned char *_set_value(sstring *this, const unsigned char *string, unsigned int startup);
unsigned char *_replace(sstring *this, const unsigned char *old_string, const unsigned char *new_string);
unsigned char *__tolower(sstring *this);
unsigned char *__toupper(sstring *this);
unsigned int _position(sstring *this, const unsigned char *delimiter);
unsigned int _is_char(const char _char);
unsigned int _is_numeric(const char _char);
unsigned char *_revert(sstring *this);
/* Prototypes. (Private) */
unsigned int _len(const unsigned char *string);
void *_set(void *pointer, unsigned int value, unsigned int length);
void *_copy(void *destination, const void *source, unsigned int length);
void *_alloc(void* pointer, unsigned int length);
void _clear(void *pointer, unsigned int length);
unsigned char *_search_ex(unsigned char *string, const unsigned char *delimiter, unsigned int *last_error, unsigned int *position);
unsigned char *_str_to_lower_and_upper(unsigned char *string, const unsigned int length,
const unsigned int start_a, const unsigned int start_b, const unsigned int delimiter);