-
Notifications
You must be signed in to change notification settings - Fork 0
/
genuid.c
101 lines (91 loc) · 2.55 KB
/
genuid.c
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
#include "genuid.h"
static const char* exceptionSymbol = "DFGJMQV0";
static bool check_rules_gen(char* ch_src)
{
for (int i = 0; i < 8; i++)
{
if (ch_src == exceptionSymbol[i])
{
return true;
}
}
return false;
}
static bool check_input_correct_str(const char* str)
{
size_t len = strlen(str);
for (int x = 0; x < len; x++)
{
if (check_rules_gen(str[x]))
{
return true;
}
}
return false;
}
int generate_uid_str(const char* str, char* result)
{
if (str == NULL)
return 1;
int size = strlen(str); //Get size string
if (size == 0)
return 2;
if (check_input_correct_str(str))
return 3;
int couter_up = 0;
char* buff = (char*)malloc(size + 1); //create conteain buffer
strcpy(buff, str);
buff[size - 1] ++; //create iteration on 1
for (int i = size - 1; i >= 0;) //glob iterator
{
for (int j = 0; j < 5;) //parse duplet
{
if (buff[i - j] != '-')
{
if ((buff[i - j] > '0' &&
buff[i - j] <= '9' + 1) ||
couter_up > 0) //parse (char)number
{
if (couter_up > 0)
{
buff[i - j] ++;
couter_up--;
}
if (buff[i - j] > '9')
{
buff[i - j] = '1';
couter_up++;
}
}
j++; //increment on next char
if ((buff[i - j] > 'A' &&
buff[i - j] <= 'Z' + 1)
|| couter_up > 0) //parse char
{
if (couter_up > 0)
{
do
{
buff[i - j] ++;
} while (check_rules_gen(buff[i - j])); //check rules exeption char
couter_up--;
}
if (buff[i - j] > 'Z')
{
buff[i - j] = 'A';
couter_up++;
}
}
j++;
}
else
{
j++;
}
}
i -= 5;
}
strcpy(result, buff);
free(buff);
return false;
}