This repository was archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcstr.c
More file actions
180 lines (171 loc) · 3.34 KB
/
cstr.c
File metadata and controls
180 lines (171 loc) · 3.34 KB
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
#include"inc_com.h"
uchar sig_find(string argc,uchar symb){
/*在字符串argc中寻找symb并且返回首字序号*/
uchar i=0;
for(i=0;i<argc.len;i++)
{
if(*(argc.head+i)==symb)
{
return(i);
}
}
return(255);
}
void stringcopy(string source,string target){
uchar i=0;
for(i=0;i<source.len;i++){
*(target.head+i)=*(source.head+i);
}
}
uchar length(uchar argc[],uchar symb){
uchar i=0;
while(1){
if(argc[i]==symb||i==255)
{
return(i);
}else{
i++;
}/*End if*/
}/*End While*/
}
uchar sig_count(string argc,uchar symb){
/*在字符串argc中统计symb的个数*/
uchar i=0,cnt=0;
for(i=0;i<argc.len;i++)
{
if(*(argc.head+i)==symb)
{
cnt++;
}
}
return(cnt);
}
uchar clear_bub(string argc,uchar buble){
uchar i=0,move=0;
argc.len=length(argc.head,0);
for(i=0;i<=argc.len;i++)
{
buble_find: ;
*(argc.head+i)=*(argc.head+i+move);
if(*(argc.head+i)==buble){
move++;
goto buble_find;
}
}
return(move);
}
unsigned char str_instead(string argc,string symb,string pif){
unsigned char i=0,
j=0;
unsigned char slen=0;
slen=length(argc.head,0);
for(i=0;i<slen;i++){
if(*(argc.head+i)==*(symb.head)){
for(j=i+1;j<symb.len+i;j++){
if(*(argc.head+j)!=*(symb.head+j-i)){
goto nexti;
}
}
/*chech completed*/
if(symb.len==pif.len){
for(j=0;j<pif.len;j++){
*(argc.head+i+j)=*(pif.head+j);
}
}else if(symb.len>pif.len){
for(j=0;j<pif.len;j++){
*(argc.head+i+j)=*(pif.head+j);
}/*copy first*/
for(j=i+pif.len;j<=slen;j++){
*(argc.head+j)=*(argc.head+j+symb.len-pif.len);
}/*move*/
slen-=(symb.len-pif.len);
}else if(symb.len<pif.len){
for(j=slen;j>=i+symb.len;j--){
*(argc.head+j+pif.len-symb.len)=*(argc.head+j);
}/*move first*/
for(j=0;j<pif.len;j++){
*(argc.head+i+j)=*(pif.head+j);
}/*copy second*/
slen-=(symb.len-pif.len);
}
}
nexti:;
}/*next i*/
return(slen);
}
double tra_number(string DAT){
unsigned char i;
double rtn=0,hel=0;
signed short dot=-1;
for(i=0;i<DAT.len;i++){
if(*(DAT.head+i)=='.'){
dot=i;
break;
}
}
if(dot<=-1){//无小数点
for(i=0;i<DAT.len;i++){
rtn*=10;
rtn+=*(DAT.head+i)-0x30;
}
return(rtn);
}else{
for(i=0;i<dot;i++){
rtn*=10;
rtn += *(DAT.head+i)-0x30;
}
for(i=DAT.len-1;i>dot;i--){
hel/=10;
hel+= *(DAT.head+i)-0x30;
}
hel/=10;
rtn+=hel;
return(rtn);
}
}
bit str_compare(string argc,string symb){
uchar i=0;
if(argc.len!=symb.len){
return(0);
}
for(i=0;i<argc.len;i++){
if(*(symb.head+i)!=*(argc.head+i)){
return(0);
}
}
return(1);
}
unsigned char findlastbracket(string expression,unsigned char left_brackets){
unsigned short i=0;
unsigned short exitflag=0;
unsigned unpair=0;
unpair=left_brackets;
for(i=0;exitflag==0;i++){
if(expression.head[i]==')'){
unpair--;
}else if(*(expression.head+i)=='('||
*(expression.head+i)=='S'||
*(expression.head+i)=='C'||
*(expression.head+i)=='T'||
*(expression.head+i)=='s'||
*(expression.head+i)=='c'||
*(expression.head+i)=='t'||
*(expression.head+i)=='l'||
*(expression.head+i)=='n'
){
unpair++;
}
if(unpair==0){
exitflag=1;
}
}
return((unsigned char)(i-1));
}
void sig_instead(string argc,unsigned char symb,unsigned char pif){
unsigned char i;
for(i=0;i<argc.len;i++){
if(argc.head[i]==symb){
argc.head[i]=pif;
}
}
}