-
Notifications
You must be signed in to change notification settings - Fork 2
/
String.c
204 lines (178 loc) · 2.87 KB
/
String.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "String.h"
BOOL _itoa(long _value, char* _result, int _base)
{
if (_base < 2 || _base > 36) { *_result = '\0'; return FALSE; }
char* ptr = _result, *ptr1 = _result, tmp_char;
int tmp_value;
//음수 양수 상관없이 처리가 가능함.
do {
tmp_value = _value;
_value /= _base;
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - _value * _base)];
} while (_value);
//Sign 처리
if (tmp_value < 0) *ptr++ = '-';
*ptr-- = '\0';
//Reverse
while (ptr1 < ptr) {
tmp_char = *ptr;
*ptr-- = *ptr1;
*ptr1++ = tmp_char;
}
return TRUE;
}
BOOL _u_itoa(QWORD _value, char* _result, unsigned int _base)
{
if (_base < 2 || _base > 36) { *_result = '\0'; return FALSE; }
char* ptr = _result, *ptr1 = _result, tmp_char;
unsigned long tmp_value;
//음수 양수 상관없이 처리가 가능함.
do {
tmp_value = _value;
_value /= _base;
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - _value * _base)];
} while (_value);
*ptr-- = '\0';
//Reverse
while (ptr1 < ptr) {
tmp_char = *ptr;
*ptr-- = *ptr1;
*ptr1++ = tmp_char;
}
return TRUE;
}
int _ctoi(char _c)
{
switch (_c)
{
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
case 'A':
return 10;
case 'b':
case 'B':
return 11;
case 'c':
case 'C':
return 12;
case 'd':
case 'D':
return 13;
case 'e':
case 'E':
return 14;
case 'f':
case 'F':
return 15;
case 'g':
case 'G':
return 16;
case 'h':
case 'H':
return 17;
case 'i':
case 'I':
return 18;
case 'j':
case 'J':
return 19;
case 'k':
case 'K':
return 20;
case 'l':
case 'L':
return 21;
case 'm':
case 'M':
return 22;
case 'n':
case 'N':
return 23;
case 'o':
case 'O':
return 24;
case 'p':
case 'P':
return 25;
case 'q':
case 'Q':
return 26;
case 'r':
case 'R':
return 27;
case 's':
case 'S':
return 28;
case 't':
case 'T':
return 29;
case 'u':
case 'U':
return 30;
case 'v':
case 'V':
return 31;
case 'w':
case 'W':
return 32;
case 'x':
case 'X':
return 33;
case 'y':
case 'Y':
return 34;
case 'z':
case 'Z':
return 35;
}
}
BOOL _atoi(const char* _number, long* _value, int _base)
{
if (!_number)
return FALSE;
if (_base < 2 || _base > 36)
return FALSE;
int sign = 1;
int i = 0;
if (_number[0] == '-')
{
sign = -1;
i = 1;
}
long result = 0;
char c = 0;
while ((c = _number[i++]) != '\0')
{
int num = _ctoi(c);
if (num > _base)
return FALSE;
result = result * _base + num;
}
*_value = sign*result;
return TRUE;
}
int __StringLength(const char* _str)
{
int result = 0;
for (result = 0; _str[result] != '\0'; result++);
return result;
}