-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegEx_Parser.c
1555 lines (1131 loc) · 44.9 KB
/
RegEx_Parser.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
/* ##################################################################################################################################### */
void dividerControl(const char *text, const char *input) {
char wordsArray[10][10];
int wordCount = 0; // Dizi içindeki kelime sayısını tutar
char buffer[10] = {0}; // Kelimeyi geçici olarak tutar
int bufferIndex = 0; // Buffer'ın indeksini tutar
// `|` işaretine göre kelimeleri ayır
for (int i = 0; input[i] != '\0'; i++) {
if (input[i] == '|') {
// '|' ile karşılaştığında, buffer'daki kelimeyi dizine ekle
buffer[bufferIndex] = '\0'; // Null sonlandırıcı ekle
strcpy(wordsArray[wordCount], buffer); // Kelimeyi diziye kopyala
wordCount++; // Dizi içindeki kelime sayısını artır
bufferIndex = 0; // Buffer'ı sıfırla
}
else {
buffer[bufferIndex++] = input[i]; // Karakteri buffer'a ekle
}
}
// Son kelimeyi de ekle (input sonunda '|' yoksa atlanmaması için)
buffer[bufferIndex] = '\0'; // Null sonlandırıcı ekle
strcpy(wordsArray[wordCount], buffer); // Kelimeyi diziye kopyala
wordCount++; // Dizi içindeki kelime sayısını artır
// Metin içinde kelimeleri kontrol et
int found = 0; // Eşleşme olup olmadığını kontrol etmek için
for (int i = 0; i < wordCount; i++) {
if (strstr(text, wordsArray[i]) != NULL) {
printf("%s is Found!\n", wordsArray[i]);
found = 1;
}
}
if (!found) {
printf("No matches found.\n");
}
}
/* ##################################################################################################################################### */
void generateWords(char wordsArray[10][10], const char *pattern, int *wordCount) {
int i = 0;
char preBracket[10] = {0}; // Parantezden önceki kısmı saklamak için
char postBracket[10] = {0}; // Parantezden sonraki kısmı saklamak için
int inBrackets = 0; // Parantez içindeysek
// Şablondaki parçaları oluşturmak için parantez durumunu kontrol et
int preBracketLen = 0;
while (pattern[i] != '\0') {
if (pattern[i] == '(') {
inBrackets = 1; // Parantez içindeyiz
int j = i + 1;
int index = 0; // Dizideki kelime oluşturma indeksi
// Parantez içindeki seçenekler
while (pattern[j] != ')' && pattern[j] != '\0') {
wordsArray[index][0] = '\0'; // Kelimeyi temizle
// Önce parantez öncesi kısmı ekle
strcpy(wordsArray[index], preBracket);
int len = strlen(wordsArray[index]);
wordsArray[index][len] = pattern[j]; // Parantez içindeki karakteri ekle
wordsArray[index][len + 1] = '\0'; // Null terminatör ekle
(*wordCount)++; // Kelime sayısını artır
index++; // Yeni kelime oluşturmak için
j++; // Parantez içi sonraki karaktere geç
}
// Parantez içindeki işleme bitince, postBracket'ı al
if (pattern[j] == ')') {
strcpy(postBracket, &pattern[j + 1]); // Parantez sonrası kısmı ekle
}
break; // Parantez bitince, döngüyü sonlandır
}
else {
// Parantez dışındaysa, ön kısmı oluştur
preBracket[preBracketLen++] = pattern[i];
preBracket[preBracketLen] = '\0';
}
i++; // Sonraki karaktere geç
}
// Parantez sonrası kısmı ekle
for (int k = 0; k < *wordCount; k++) {
strcat(wordsArray[k], postBracket);
}
}
void dividerAndBracketsControl(const char *text, const char *pattern) {
// Şablondan olasılıkları oluşturmak için bir dizi
char wordsArray[10][10] = {0};
int wordCount = 0; // Dizi içindeki kelime sayısı
// Şablona göre kelimeleri oluştur
generateWords(wordsArray, pattern, &wordCount);
// Metni olasılıklara göre kontrol et
int found = 0; // Eşleşme olup olmadığını kontrol etmek için
for (int k = 0; k < wordCount; k++) {
if (strstr(text, wordsArray[k]) != NULL) {
printf("%s is Found!\n", wordsArray[k]);
found = 1;
}
}
if (!found) {
printf("No matches found.\n");
}
}
/* ##################################################################################################################################### */
#define MAX_WORDS 50
#define MAX_WORD_LEN 50
void generWords(const char *pattern, char wordsArray[MAX_WORDS][MAX_WORD_LEN], int *wordsCount) {
int len = strlen(pattern);
int wordIndex = 0;
for (int i = 0; i < len; i++) {
if (pattern[i] == '[') {
// Köşeli parantezin sonunu bul
int bracketEnd = i + 1;
while (bracketEnd < len && pattern[bracketEnd] != ']') {
bracketEnd++;
}
// Köşeli parantez içindeki harfleri işle
for (int j = i + 1; j < bracketEnd; j++) {
char currentWord[MAX_WORD_LEN] = {0};
// Başlangıç kısmını ve köşeli parantez içindeki harfi al
strncpy(currentWord, pattern, i);
currentWord[i] = pattern[j];
strcpy(currentWord + i + 1, pattern + bracketEnd + 1);
strncpy(wordsArray[wordIndex], currentWord, MAX_WORD_LEN - 1);
wordsArray[wordIndex][MAX_WORD_LEN - 1] = '\0'; // Güvenlik için sonlandırıcı ekleyin
wordIndex++;
}
i = bracketEnd; // Köşeli parantezin sonrasına atla
}
}
*wordsCount = wordIndex;
}
void squareBracketsControl(const char *pattern, const char *input) {
char wordsArray[MAX_WORDS][MAX_WORD_LEN];
int wordsCount = 0;
generWords(pattern, wordsArray, &wordsCount);
// input'u virgül ile ayırma
char inputCopy[MAX_WORD_LEN * MAX_WORDS];
strncpy(inputCopy, input, sizeof(inputCopy));
inputCopy[sizeof(inputCopy) - 1] = '\0';
char *token = strtok(inputCopy, ", "); // Virgül ve boşluk ile ayırma
int found = 0;
while (token != NULL) {
for (int i = 0; i < wordsCount; i++) {
if (strcmp(wordsArray[i], token) == 0) {
printf("%s is Found!\n", wordsArray[i]);
found = 1;
break;
}
}
token = strtok(NULL, ", "); // Sonraki kelimeyi alın
}
if (!found) {
printf("Nothing found!\n");
}
}
/* ##################################################################################################################################### */
void parsePattern(const char *pattern, char result[][20], int *count) {
int len = strlen(pattern);
int resCount = 0;
char temp[20]; // Geçici kelime oluşturucu
int tempIndex = 0;
for (int i = 0; i < len; i++) {
if (pattern[i] == '[') {
// Alternatif karakterler kümesini işleme
int j = i + 1;
while (j < len && pattern[j] != ']') {
temp[tempIndex] = pattern[j]; // Parantez içindeki her bir harfi al
temp[tempIndex + 1] = '\0'; // Stringi sonlandır
strcpy(result[resCount], temp); // Oluşan kelimeyi kaydet
resCount++;
j++;
}
i = j; // ']' işaretinden sonra devam et
}
else if (pattern[i] == '\\' && i + 1 < len && pattern[i + 1] == '*') {
// Kaçış karakteri ve '*' sembolü için
for (int k = 0; k < resCount; k++) {
strcat(result[k], "*");
}
i++; // '\\*' sembolünü atla
}
else {
// Normal bir karakterse, tüm kelimelere ekle
for (int k = 0; k < resCount; k++) {
int length = strlen(result[k]);
result[k][length] = pattern[i]; // Karakter ekle
result[k][length + 1] = '\0'; // String sonlandır
}
if (resCount == 0) { // Eğer henüz kelime eklenmediyse
temp[tempIndex] = pattern[i];
temp[tempIndex + 1] = '\0';
strcpy(result[0], temp);
resCount++;
}
}
}
*count = resCount; // Olası kelime sayısını güncelle
}
void squareBracketsAndSlashControl(const char *text, const char *input) {
char wordsArray[20][20];
int wordCount = 0;
parsePattern(input, wordsArray, &wordCount);
// Oluşan kelimeleri giriş metninde arama
for (int i = 0; i < wordCount; i++) {
if (strstr(text, wordsArray[i]) != NULL) {
printf("%s is Found!\n", wordsArray[i]);
}
}
}
/* ##################################################################################################################################### */
void squareBracketsAndHyphenControl(const char *text, const char *input) {
int allowed[256] = {0}; // 256 farklı karakter için tablo
int len = strlen(input);
// input'tan harfleri ve aralıkları belirle
for (int i = 0; i < len; i++) {
if (isalpha(input[i])) {
if (i + 2 < len && input[i + 1] == '-') {
// aralık belirtildi, örneğin: a-z
for (char c = input[i]; c <= input[i + 2]; c++) {
allowed[(int)c] = 1;
}
i += 2; // ilerlemeyi 2 artır, çünkü aralığı işledik
}
else {
// tek harf belirtildi
allowed[(int)input[i]] = 1;
}
}
}
// metinde yalnız başına duran uygun harfleri bul
int text_len = strlen(text);
for (int i = 0; i < text_len; i++) {
if (allowed[(int)text[i]]) {
int isSeparate = 1;
// harfin sol ve sağında harf veya rakam olmamalı
if (i > 0 && (isalpha(text[i - 1]) || isdigit(text[i - 1]))) {
isSeparate = 0;
}
if (i < text_len - 1 && (isalpha(text[i + 1]) || isdigit(text[i + 1]))) {
isSeparate = 0;
}
if (isSeparate) {
printf("%c is Found!\n", text[i]);
}
}
}
printf("\n");
}
/* ##################################################################################################################################### */
// Köşeli parantez içindeki aralıkları eklemek için yardımcı fonksiyon
void addRange(char start, char end, char *array, int *index) {
for (char c = start; c <= end; c++) {
array[*index] = c;
(*index)++;
}
}
// Kullanıcı girdisini virgüllerle ayırmak için fonksiyon
void splitInput(const char *input, char inputArray[][50], int *numWords) {
int j = 0;
*numWords = 0;
for (int i = 0; input[i] != '\0'; i++) {
if (input[i] == ',') {
inputArray[*numWords][j] = '\0'; // Bu kelimenin sonunu belirler
(*numWords)++;
j = 0; // Yeni kelime için sıfırdan başlar
}
else {
inputArray[*numWords][j++] = input[i];
}
}
if (j > 0) { // Son kelimeyi eklemek için kontrol
inputArray[*numWords][j] = '\0';
(*numWords)++;
}
}
// Dizedeki baştaki ve sondaki boşlukları temizleyen yardımcı fonksiyon
void trim(char *str) {
// Baştaki boşlukları temizle
int start = 0;
while (isspace(str[start])) {
start++;
}
// Sondaki boşlukları temizle
int end = strlen(str) - 1;
while (end >= start && isspace(str[end])) {
end--;
}
// Boşlukları ortadan kaldır
for (int i = 0; i <= (end - start); i++) {
str[i] = str[start + i];
}
str[end - start + 1] = '\0'; // Dizenin sonunu belirle
}
// Ana fonksiyon: Olası kelimeleri analiz eder ve kullanıcı girdisi ile karşılaştır
void squareBracketsAndHyphenAndDividerControl(const char *text, const char *input) {
char leftBracketContent[50]; // Köşeli parantez içeriği
int lIndex = 0;
char rightPart[50]; // "|" sonrası sağ kısmı
int rIndex = 0;
int i = 0;
int isLeftBracket = 0;
// Diziyi analiz ederek köşeli parantezleri işle
while (text[i] != '\0') {
if (text[i] == '|') {
isLeftBracket = 1;
i++;
continue;
}
if (isLeftBracket) {
rightPart[rIndex++] = text[i];
}
else {
if (text[i] == '[') {
i++;
while (text[i] != ']' && text[i] != '\0') {
if (text[i + 1] == '-' && text[i + 2] != '\0') {
addRange(text[i], text[i + 2], leftBracketContent, &lIndex);
i += 2; // Aralıkta iki adım ilerle
}
else {
leftBracketContent[lIndex++] = text[i];
}
i++;
}
}
}
i++;
}
rightPart[rIndex] = '\0'; // Sağ kısmın sonunu belirler
// Olası kelimeleri saklayan bir dizi
char wordsArray[50][50];
int wordsIndex = 0;
for (int j = 0; j < lIndex; j++) {
snprintf(wordsArray[wordsIndex], 50, "%c%s", leftBracketContent[j], "at");
wordsIndex++;
}
// Sağ kısmı kelime olarak ekle
snprintf(wordsArray[wordsIndex], 50, "%s", rightPart);
wordsIndex++;
// Kullanıcı girdisini virgüllerle ayır
char inputArray[50][50];
int numWords = 0;
splitInput(input, inputArray, &numWords);
// Eşleşmeleri kontrol et
int found = 0;
for (int k = 0; k < numWords; k++) {
trim(inputArray[k]); // Boşlukları temizle
for (int t = 0; t < wordsIndex; t++) {
if (strcmp(inputArray[k], wordsArray[t]) == 0) {
printf("%s is Found!\n", wordsArray[t]);
found = 1;
}
}
}
if (!found) {
printf("Nothing found!\n");
}
}
/* ##################################################################################################################################### */
void questionMarkControl(const char *text, const char *input) {
char wordsArray[2][100];
int index = -1;
int length = strlen(input);
// Soru işaretinin konumunu bul
for (int i = 0; i < length; i++) {
if (input[i] == '?') {
index = i;
break;
}
}
// Soru işaretini kaldırarak ilk kelimeyi oluştur
strncpy(wordsArray[0], input, index);
wordsArray[0][index] = '\0';
strcat(wordsArray[0], input + index + 1); // Sonraki karakterleri ekle
// Soru işareti ve bir önceki karakteri kaldırarak kelime oluşturmaya devam et
strncpy(wordsArray[1], input, index - 1);
wordsArray[1][index - 1] = '\0';
strcat(wordsArray[1], input + index + 1); // Sonraki karakterleri ekle
// text içinde wordsArray'deki kelimeleri kontrol et
int found = 0;
for (int i = 0; i < 2; i++) {
if (strstr(text, wordsArray[i])) { // text içinde kelimeyi ara
printf("%s is Found!\n", wordsArray[i]);
found = 1;
}
}
if (!found) {
printf("Nothing Found!");
}
}
/* ##################################################################################################################################### */
// Girdi metnindeki ön ve son boşlukları temizler
void trimComma(char *str) {
int len = strlen(str);
// Son boşlukları kaldır
while (len > 0 && isspace(str[len - 1])) {
str[--len] = '\0';
}
// İlk boşlukları kaldır
int start = 0;
while (isspace(str[start])) {
start++;
}
if (start > 0) {
// Boşlukları temizlemek için diziyi sola kaydır
memmove(str, str + start, len - start + 1);
}
}
void generateVariations(const char *text, char wordsArray[][100], int *count) {
char currentWord[100] = {0};
int wordIndex = 0;
*count = 0;
// Varyasyonları oluştururken '*' işaretine dikkat etmek lazım
for (int i = 0; i < strlen(text); i++) {
if (text[i] == '*') {
char repeatedChar = text[i - 1];
int originalLength = wordIndex;
for (int j = 0; j <= 10; j++) {
wordIndex = originalLength;
for (int k = 0; k < j; k++) {
currentWord[wordIndex++] = repeatedChar;
}
for (int l = i + 1; l < strlen(text); l++) {
currentWord[wordIndex++] = text[l];
}
currentWord[wordIndex] = '\0';
strcpy(wordsArray[*count], currentWord);
(*count)++;
}
break; // '*' ile ilgili varyasyonlar tamamlandığında çık
}
else {
currentWord[wordIndex++] = text[i];
}
}
}
void starControl(const char *text, const char *input) {
char wordsArray[11][100] = {0};
int count = 0;
// Olası varyasyonları oluştur
generateVariations(text, wordsArray, &count);
// Girdiyi virgülle ayırırken boşlukları temizle
char inputCopy[256];
strcpy(inputCopy, input);
char *token = strtok(inputCopy, ",");
int found = 0;
while (token != NULL) {
trimComma(token); // Boşlukları temizle
for (int i = 0; i < count; i++) {
if (strcmp(token, wordsArray[i]) == 0) {
printf("%s is Found!\n", wordsArray[i]);
found = 1;
break;
}
}
token = strtok(NULL, ",");
}
if (!found) {
printf("Nothing found!\n", token);
}
}
/* ##################################################################################################################################### */
// "+" işaretinden sonra gelen harfi tekrarlayarak olasılıkları oluşturur
void variationsGen(const char *text, char wordsArray[][100], int *count) {
char prefix[100] = {0}; // "+" öncesi
char repeatChar = 0; // "+" sonrası tekrarlanan harf
char suffix[100] = {0}; // "+" sonrası
int prefixLen = 0;
int suffixLen = 0;
int foundPlus = 0;
int i = 0;
// Metni tarayarak "+" işaretini bul ve onu doğru şekilde ayır
while (text[i] != '\0') {
if (text[i] == '+') {
foundPlus = 1;
repeatChar = text[i - 1]; // "+" işaretinden önceki harfi tekrarlayacağız
i++; // "+" işaretini geç
}
else if (!foundPlus) {
prefix[prefixLen++] = text[i];
i++;
}
else {
suffix[suffixLen++] = text[i];
i++;
}
}
prefix[prefixLen] = '\0';
suffix[suffixLen] = '\0';
// İlk olasılık: gogle (tek tekrar)
strcpy(wordsArray[*count], prefix);
strcat(wordsArray[*count], suffix);
(*count)++;
// Diğer olasılıklar
for (int j = 2; j <= 10; j++) {
strcpy(wordsArray[*count], prefix);
// Repeat harfini 'j' kez ekle
for (int k = 0; k < j; k++) {
strncat(wordsArray[*count], &repeatChar, 1);
}
// Suffix'i ekle
strcat(wordsArray[*count], suffix);
(*count)++;
}
}
// Girdideki kelimeleri olasılıklar ile karşılaştırır
void plusControl(const char *text, const char *input) {
char wordsArray[11][100] = {0}; // 11 olasılık oluştur (1'den 10'a kadar)
int count = 0;
// Olasılıkları oluştur
variationsGen(text, wordsArray, &count);
// Input'u virgüllerle ayır
char inputCopy[256];
strcpy(inputCopy, input);
char *token = strtok(inputCopy, ",");
int found = 0;
while (token != NULL) {
// Boşlukları temizlemek için
while (*token == ' ') {
token++;
}
// Varyasyonları input ile karşılaştır
for (int i = 0; i < count; i++) {
if (strcmp(token, wordsArray[i]) == 0) {
printf("%s is Found!\n", wordsArray[i]);
found = 1;
break;
}
}
token = strtok(NULL, ",");
}
if (!found) {
printf("Nothing found!\n");
}
}
/* ##################################################################################################################################### */
// Boşlukları temizlemek için bir yardımcı fonksiyon
void triM(char *str) {
int len = strlen(str);
// String'in sonundaki boşlukları kaldır
while (len > 0 && isspace(str[len - 1])) {
str[--len] = '\0';
}
// String'in başındaki boşlukları kaldır
int start = 0;
while (start < len && isspace(str[start])) {
start++;
}
if (start > 0) {
memmove(str, str + start, len - start + 1);
}
}
// "+" işaretine göre olasılıkları oluşturur
void gnrtVariations(const char *text, char wordsArray[][100], int *count) {
char prefix[100] = {0}; // "+" öncesi
char repeat[100] = {0}; // "+" sonrası parantez içi
char suffix[100] = {0}; // "+" sonrası
int prefixLen = 0;
int repeatLen = 0;
int suffixLen = 0;
int foundPlus = 0;
int i = 0;
// Metni analiz ederek "+" işareti ve parantez içindeki kısmı ayır
while (text[i] != '\0') {
if (text[i] == '(') {
// Parantez içindeki tekrar edilecek kısmı al
i++;
while (text[i] != ')' && text[i] != '\0') {
repeat[repeatLen++] = text[i];
i++;
}
repeat[repeatLen] = '\0';
i++; // Parantez kapandığında sonraki karaktere geç
}
else if (text[i] == '+') {
foundPlus = 1;
i++; // "+" işaretini geç
}
else if (!foundPlus) {
// "+" işaretinden önceki kısmı al
prefix[prefixLen++] = text[i];
i++;
}
else {
// "+" işaretinden sonraki kısmı al
suffix[suffixLen++] = text[i];
i++;
}
}
prefix[prefixLen] = '\0';
suffix[suffixLen] = '\0';
// "+" işareti için 1'den 10'a kadar tekrar varyasyonları oluştur
*count = 0;
for (int j = 1; j <= 10; j++) {
strcpy(wordsArray[*count], prefix);
// Tekrar eden kısmı 'j' kez ekle
for (int k = 0; k < j; k++) {
strcat(wordsArray[*count], repeat);
}
// Suffix'i ekle
strcat(wordsArray[*count], suffix);
(*count)++;
}
}
// Girdideki kelimeleri olasılıklar ile karşılaştırır
void plusAndBracketsControl(const char *text, const char *input) {
char wordsArray[10][100]; // 10 olasılık oluştur
int count = 0;
// Olasılıkları oluştur
gnrtVariations(text, wordsArray, &count);
// Inputu virgüller ile ayır
char inputCopy[256];
strcpy(inputCopy, input);
char *token = strtok(inputCopy, ",");
int found = 0;
while (token != NULL) {
triM(token); // Boşlukları temizle
// Varyasyonları input ile karşılaştır
for (int i = 0; i < count; i++) {
if (strcmp(token, wordsArray[i]) == 0) {
printf("%s is Found!\n", wordsArray[i]);
found = 1;
break;
}
}
token = strtok(NULL, ",");
}
if (!found) {
printf("Nothing found!\n");
}
}
/* ##################################################################################################################################### */
// Girilen formatın "x{y,z}" veya "x{y,}" veya "x{y}" olmasını kontrol eder.
void extractPatternAndCounts(const char *input, char *patternChar, int *min, int *max) {
int len = strlen(input);
int i = 0;
// PatternChar'ı ve min ile max değerlerini ayrıştır
while (i < len && isalpha(input[i])) {
i++;
}
if (i > 0 && i < len && input[i] == '{' && input[len - 1] == '}') {
*patternChar = input[i - 1];
char numbers[20];
strncpy(numbers, &input[i + 1], len - i - 2);
numbers[len - i - 2] = '\0';
char *commaPos = strchr(numbers, ',');
if (commaPos) {
*commaPos = '\0';
*min = atoi(numbers);
*max = atoi(commaPos + 1);
if (*max == 0) {
*max = 10; // max değeri varsayılan 10 yapıyoruz (işlem hızı için sonsuz değil de 10 kere yapayım dedim istersek arttırız)
}
}
else {
// Tek sayı için
*min = atoi(numbers);
*max = *min;
}
}
}
void curlyBracketsControl(const char *text, const char *input) {
char patternChar;
int min = 0, max = 0;
extractPatternAndCounts(input, &patternChar, &min, &max);
int count = 0;
int matchFound = 0;
// Eşleşmeleri kontrol et
for (int i = 0; text[i] != '\0'; i++) {
if (text[i] == patternChar) {
count++;
}
else {
if (count >= min && count <= max) {
printf("%.*s is Found!\n", count, &text[i - count]);
matchFound = 1;
}
count = 0; // Sıfırla
}
}
// Sonunda da kontrol yap
if (count >= min && count <= max) {
printf("%.*s is Found!\n", count, &text[strlen(text) - count]);
matchFound = 1;
}
if (!matchFound) {
printf("Nothing found!\n");
}
}
/* ##################################################################################################################################### */
int find_slash_D(const char *str) {
int lenT = 11;
int len = strlen(str);
if (len != lenT) {
return 0; // Uzunluk uygun değil
}
// İlk karaktere bakar
if (str[0] == '1') {
return 1; // Eşleşme bulundu
}
return 0; // Eşleşme bulunmadı
}
// Virgülle ayrılmış kelimelerde kontrol eder
void curlyBracketsAndSlash_d_Control(const char *text, const char *input) {
char inputCopy[256];
strcpy(inputCopy, input);
char *token = strtok(inputCopy, ",");
int found = 0;
while (token != NULL) {
// Başında boşlukları temizleyin
while (*token == ' ') {
token++;
}
// kontrol
if (find_slash_D(token)) {
printf("%s is Found!\n", token);
found = 1;
}
token = strtok(NULL, ",");
}
if (!found) {
printf("Nothing found!\n");
}
}
/* ##################################################################################################################################### */
void slash_d_Control(const char *text) {
int found = 0; // Bir eşleşme olup olmadığını kontrol eder
const char *delimiter = " "; // Boşlukları ayırıcı olarak kullan
char text_copy[256]; // Güvenli uzunlukta bir buffer
strcpy(text_copy, text); // Orijinal text'i değiştirilebilmek için kopyala