@@ -2,6 +2,7 @@ extern crate log;
2
2
extern crate pest;
3
3
4
4
use pest:: Parser ;
5
+ use pest_derive:: Parser ;
5
6
6
7
#[ derive( Parser ) ]
7
8
#[ grammar = "grammar.pest" ]
@@ -365,8 +366,8 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
365
366
)
366
367
. is_err ( )
367
368
&& ( chars. get ( * pos + 2 ) != Some ( & 'E' )
368
- || get_substring ( & chars, pos. wrapping_sub ( 2 ) , * pos + 4 ) == "BACHER"
369
- || get_substring ( & chars, pos. wrapping_sub ( 2 ) , * pos + 4 ) == "MACHER" )
369
+ || get_substring ( chars, pos. wrapping_sub ( 2 ) , * pos + 4 ) == "BACHER"
370
+ || get_substring ( chars, pos. wrapping_sub ( 2 ) , * pos + 4 ) == "MACHER" )
370
371
{
371
372
* p += "K" ;
372
373
* s += "K" ;
@@ -375,15 +376,15 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
375
376
return ;
376
377
}
377
378
378
- if * pos == 0 && get_substring ( & chars, 1 , 6 ) == "AESAR" {
379
+ if * pos == 0 && get_substring ( chars, 1 , 6 ) == "AESAR" {
379
380
* p += "S" ;
380
381
* s += "S" ;
381
382
* pos += 2 ;
382
383
383
384
return ;
384
385
}
385
386
386
- if get_substring ( & chars, * pos + 1 , * pos + 4 ) == "HIA" {
387
+ if get_substring ( chars, * pos + 1 , * pos + 4 ) == "HIA" {
387
388
* p += "K" ;
388
389
* s += "K" ;
389
390
* pos += 2 ;
@@ -414,7 +415,7 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
414
415
return ;
415
416
}
416
417
417
- if germanic ( & chars)
418
+ if germanic ( chars)
418
419
|| Word :: parse (
419
420
Rule :: greek_ch,
420
421
get_substring ( chars, pos. wrapping_sub ( 2 ) , * pos + 4 ) . as_str ( ) ,
@@ -464,15 +465,15 @@ fn c_case(State { pos, chars, p, s }: &mut State) {
464
465
return ;
465
466
}
466
467
467
- if chars. get ( * pos + 1 ) == Some ( & 'C' ) && !( * pos == 1 && chars. get ( 0 ) == Some ( & 'M' ) ) {
468
+ if chars. get ( * pos + 1 ) == Some ( & 'C' ) && !( * pos == 1 && chars. first ( ) == Some ( & 'M' ) ) {
468
469
if ( chars. get ( * pos + 2 ) == Some ( & 'I' )
469
470
|| chars. get ( * pos + 2 ) == Some ( & 'E' )
470
471
|| chars. get ( * pos + 2 ) == Some ( & 'H' ) )
471
472
&& get_substring ( chars, * pos + 2 , * pos + 4 ) != "HU"
472
473
{
473
474
if ( * pos == 1 && chars. get ( pos. wrapping_sub ( 1 ) ) == Some ( & 'A' ) )
474
- || get_substring ( & chars, pos. wrapping_sub ( 1 ) , * pos + 4 ) == "UCCEE"
475
- || get_substring ( & chars, pos. wrapping_sub ( 1 ) , * pos + 4 ) == "UCCES"
475
+ || get_substring ( chars, pos. wrapping_sub ( 1 ) , * pos + 4 ) == "UCCEE"
476
+ || get_substring ( chars, pos. wrapping_sub ( 1 ) , * pos + 4 ) == "UCCES"
476
477
{
477
478
* p += "KS" ;
478
479
* s += "KS" ;
@@ -584,7 +585,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
584
585
if * pos > 0
585
586
&& Word :: parse (
586
587
Rule :: vowels,
587
- get_char_as_string ( & chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
588
+ get_char_as_string ( chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
588
589
)
589
590
. is_err ( )
590
591
{
@@ -627,7 +628,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
627
628
&& chars. get ( pos. wrapping_sub ( 1 ) ) == Some ( & 'U' )
628
629
&& Word :: parse (
629
630
Rule :: g_for_f,
630
- get_char_as_string ( & chars, pos. wrapping_sub ( 3 ) ) . as_str ( ) ,
631
+ get_char_as_string ( chars, pos. wrapping_sub ( 3 ) ) . as_str ( ) ,
631
632
)
632
633
. is_ok ( )
633
634
{
@@ -645,14 +646,14 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
645
646
646
647
if chars. get ( * pos + 1 ) == Some ( & 'N' ) {
647
648
if * pos == 1
648
- && Word :: parse ( Rule :: vowels, get_char_as_string ( & chars, 0 ) . as_str ( ) ) . is_ok ( )
649
- && !slavo_germanic ( & chars)
649
+ && Word :: parse ( Rule :: vowels, get_char_as_string ( chars, 0 ) . as_str ( ) ) . is_ok ( )
650
+ && !slavo_germanic ( chars)
650
651
{
651
652
* p += "KN" ;
652
653
* s += "N" ;
653
- } else if get_substring ( & chars, * pos + 2 , * pos + 4 ) != "EY"
654
+ } else if get_substring ( chars, * pos + 2 , * pos + 4 ) != "EY"
654
655
&& chars. get ( * pos + 1 ) != Some ( & 'Y' )
655
- && !slavo_germanic ( & chars)
656
+ && !slavo_germanic ( chars)
656
657
{
657
658
* p += "N" ;
658
659
* s += "KN"
@@ -666,7 +667,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
666
667
return ;
667
668
}
668
669
669
- if get_substring ( & chars, * pos + 1 , * pos + 3 ) == "LI" && !slavo_germanic ( & chars) {
670
+ if get_substring ( chars, * pos + 1 , * pos + 3 ) == "LI" && !slavo_germanic ( chars) {
670
671
* p += "KL" ;
671
672
* s += "L" ;
672
673
* pos += 2 ;
@@ -677,7 +678,7 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
677
678
if * pos == 0
678
679
&& Word :: parse (
679
680
Rule :: initial_g_or_for_k_or_j,
680
- get_substring ( & chars, 1 , 3 ) . as_str ( ) ,
681
+ get_substring ( chars, 1 , 3 ) . as_str ( ) ,
681
682
)
682
683
. is_ok ( )
683
684
{
@@ -688,18 +689,18 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
688
689
return ;
689
690
}
690
691
691
- if get_substring ( & chars, * pos + 1 , * pos + 3 ) == "ER"
692
+ if get_substring ( chars, * pos + 1 , * pos + 3 ) == "ER"
692
693
&& chars. get ( pos. wrapping_sub ( 1 ) ) != Some ( & 'I' )
693
694
&& chars. get ( pos. wrapping_sub ( 1 ) ) != Some ( & 'E' )
694
695
&& Word :: parse (
695
696
Rule :: initial_anger_exception,
696
- get_substring ( & chars, 0 , 6 ) . as_str ( ) ,
697
+ get_substring ( chars, 0 , 6 ) . as_str ( ) ,
697
698
)
698
699
. is_err ( )
699
700
|| ( chars. get ( * pos + 1 ) == Some ( & 'Y' )
700
701
&& Word :: parse (
701
702
Rule :: g_for_k_or_j,
702
- get_char_as_string ( & chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
703
+ get_char_as_string ( chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
703
704
)
704
705
. is_err ( ) )
705
706
{
@@ -718,13 +719,13 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
718
719
&& chars. get ( * pos + 1 ) == Some ( & 'G' )
719
720
&& chars. get ( * pos + 2 ) == Some ( & 'I' ) )
720
721
{
721
- if get_substring ( & chars, * pos + 1 , * pos + 3 ) == "ET" || germanic ( & chars) {
722
+ if get_substring ( chars, * pos + 1 , * pos + 3 ) == "ET" || germanic ( chars) {
722
723
* p += "K" ;
723
724
* s += "K" ;
724
725
} else {
725
726
* p += "J" ;
726
727
727
- if get_substring ( & chars, * pos + 1 , * pos + 5 ) == "IER " {
728
+ if get_substring ( chars, * pos + 1 , * pos + 5 ) == "IER " {
728
729
* s += "J" ;
729
730
} else {
730
731
* s += "K" ;
@@ -747,11 +748,11 @@ fn g_case(State { pos, chars, p, s }: &mut State) {
747
748
}
748
749
749
750
fn h_case ( State { pos, chars, p, s } : & mut State ) {
750
- if Word :: parse ( Rule :: vowels, get_char_as_string ( & chars, * pos + 1 ) . as_str ( ) ) . is_ok ( )
751
+ if Word :: parse ( Rule :: vowels, get_char_as_string ( chars, * pos + 1 ) . as_str ( ) ) . is_ok ( )
751
752
&& ( * pos == 0
752
753
|| Word :: parse (
753
754
Rule :: vowels,
754
- get_char_as_string ( & chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
755
+ get_char_as_string ( chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
755
756
)
756
757
. is_ok ( ) )
757
758
{
@@ -765,8 +766,8 @@ fn h_case(State { pos, chars, p, s }: &mut State) {
765
766
}
766
767
767
768
fn j_case ( State { pos, chars, p, s } : & mut State ) {
768
- if get_substring ( & chars, * pos, * pos + 4 ) == "JOSE" || get_substring ( & chars, 0 , 4 ) == "SAN " {
769
- if get_substring ( & chars, 0 , 4 ) == "SAN " || ( * pos == 0 && chars. get ( * pos + 4 ) == Some ( & ' ' ) )
769
+ if get_substring ( chars, * pos, * pos + 4 ) == "JOSE" || get_substring ( chars, 0 , 4 ) == "SAN " {
770
+ if get_substring ( chars, 0 , 4 ) == "SAN " || ( * pos == 0 && chars. get ( * pos + 4 ) == Some ( & ' ' ) )
770
771
{
771
772
* p += "H" ;
772
773
* s += "H" ;
@@ -783,11 +784,11 @@ fn j_case(State { pos, chars, p, s }: &mut State) {
783
784
if * pos == 0 {
784
785
* p += "J" ;
785
786
* s += "A" ;
786
- } else if !slavo_germanic ( & chars)
787
+ } else if !slavo_germanic ( chars)
787
788
&& ( chars. get ( * pos + 1 ) == Some ( & 'A' ) || chars. get ( * pos + 1 ) == Some ( & 'O' ) )
788
789
&& Word :: parse (
789
790
Rule :: vowels,
790
- get_char_as_string ( & chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
791
+ get_char_as_string ( chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
791
792
)
792
793
. is_ok ( )
793
794
{
@@ -800,7 +801,7 @@ fn j_case(State { pos, chars, p, s }: &mut State) {
800
801
&& chars. get ( pos. wrapping_sub ( 1 ) ) != Some ( & 'L' )
801
802
&& Word :: parse (
802
803
Rule :: j_for_j_exception,
803
- get_char_as_string ( & chars, * pos + 1 ) . as_str ( ) ,
804
+ get_char_as_string ( chars, * pos + 1 ) . as_str ( ) ,
804
805
)
805
806
. is_err ( )
806
807
{
@@ -836,7 +837,7 @@ fn l_case(State { pos, chars, p, s }: &mut State) {
836
837
|| Word :: parse (
837
838
Rule :: alle,
838
839
get_substring (
839
- & chars,
840
+ chars,
840
841
chars. len ( ) . wrapping_sub ( 7 ) ,
841
842
chars. len ( ) . wrapping_sub ( 5 ) ,
842
843
)
@@ -863,7 +864,7 @@ fn m_case(State { pos, chars, p, s }: &mut State) {
863
864
|| ( chars. get ( pos. wrapping_sub ( 1 ) ) == Some ( & 'U' )
864
865
&& chars. get ( * pos + 1 ) == Some ( & 'B' )
865
866
&& ( * pos + 1 == chars. len ( ) . wrapping_sub ( 6 )
866
- || get_substring ( & chars, * pos + 2 , * pos + 4 ) == "ER" ) )
867
+ || get_substring ( chars, * pos + 2 , * pos + 4 ) == "ER" ) )
867
868
{
868
869
* pos += 1 ;
869
870
}
@@ -920,7 +921,7 @@ fn q_case(State { pos, chars, p, s }: &mut State) {
920
921
921
922
fn r_case ( State { pos, chars, p, s } : & mut State ) {
922
923
if * pos == chars. len ( ) . wrapping_sub ( 6 )
923
- && !slavo_germanic ( & chars)
924
+ && !slavo_germanic ( chars)
924
925
&& chars. get ( pos. wrapping_sub ( 1 ) ) == Some ( & 'E' )
925
926
&& chars. get ( pos. wrapping_sub ( 2 ) ) == Some ( & 'I' )
926
927
&& chars. get ( pos. wrapping_sub ( 4 ) ) != Some ( & 'M' )
@@ -950,7 +951,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
950
951
return ;
951
952
}
952
953
953
- if * pos == 0 && get_substring ( & chars, 1 , 5 ) == "UGAR" {
954
+ if * pos == 0 && get_substring ( chars, 1 , 5 ) == "UGAR" {
954
955
* p += "X" ;
955
956
* s += "S" ;
956
957
* pos += 1 ;
@@ -961,7 +962,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
961
962
if chars. get ( * pos + 1 ) == Some ( & 'H' ) {
962
963
if Word :: parse (
963
964
Rule :: h_for_s,
964
- get_substring ( & chars, * pos + 1 , * pos + 5 ) . as_str ( ) ,
965
+ get_substring ( chars, * pos + 1 , * pos + 5 ) . as_str ( ) ,
965
966
)
966
967
. is_ok ( )
967
968
{
@@ -979,7 +980,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
979
980
if chars. get ( * pos + 1 ) == Some ( & 'I' )
980
981
&& ( chars. get ( * pos + 2 ) == Some ( & 'O' ) || chars. get ( * pos + 2 ) == Some ( & 'A' ) )
981
982
{
982
- if slavo_germanic ( & chars) {
983
+ if slavo_germanic ( chars) {
983
984
* p += "S" ;
984
985
* s += "S" ;
985
986
} else {
@@ -1015,12 +1016,12 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
1015
1016
if chars. get ( * pos + 2 ) == Some ( & 'H' ) {
1016
1017
if Word :: parse (
1017
1018
Rule :: dutch_sch,
1018
- get_substring ( & chars, * pos + 3 , * pos + 5 ) . as_str ( ) ,
1019
+ get_substring ( chars, * pos + 3 , * pos + 5 ) . as_str ( ) ,
1019
1020
)
1020
1021
. is_ok ( )
1021
1022
{
1022
- if get_substring ( & chars, * pos + 3 , * pos + 5 ) == "ER"
1023
- || get_substring ( & chars, * pos + 3 , * pos + 5 ) == "EN"
1023
+ if get_substring ( chars, * pos + 3 , * pos + 5 ) == "ER"
1024
+ || get_substring ( chars, * pos + 3 , * pos + 5 ) == "EN"
1024
1025
{
1025
1026
* p += "X" ;
1026
1027
* s += "SK"
@@ -1035,7 +1036,7 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
1035
1036
}
1036
1037
1037
1038
if * pos == 0
1038
- && Word :: parse ( Rule :: vowels, get_char_as_string ( & chars, 3 ) . as_str ( ) ) . is_err ( )
1039
+ && Word :: parse ( Rule :: vowels, get_char_as_string ( chars, 3 ) . as_str ( ) ) . is_err ( )
1039
1040
&& chars. get ( 3 ) != Some ( & 'W' )
1040
1041
{
1041
1042
* p += "X" ;
@@ -1068,8 +1069,8 @@ fn s_case(State { pos, chars, p, s }: &mut State) {
1068
1069
}
1069
1070
1070
1071
if * pos == chars. len ( ) . wrapping_sub ( 6 )
1071
- && ( get_substring ( & chars, pos. wrapping_sub ( 2 ) , * pos) == "AI"
1072
- || get_substring ( & chars, pos. wrapping_sub ( 2 ) , * pos) == "OI" )
1072
+ && ( get_substring ( chars, pos. wrapping_sub ( 2 ) , * pos) == "AI"
1073
+ || get_substring ( chars, pos. wrapping_sub ( 2 ) , * pos) == "OI" )
1073
1074
{
1074
1075
* s += "S" ;
1075
1076
} else {
@@ -1109,7 +1110,7 @@ fn t_case(State { pos, chars, p, s }: &mut State) {
1109
1110
if chars. get ( * pos + 1 ) == Some ( & 'H' )
1110
1111
|| ( chars. get ( * pos + 1 ) == Some ( & 'T' ) && chars. get ( * pos + 2 ) == Some ( & 'H' ) )
1111
1112
{
1112
- if germanic ( & chars)
1113
+ if germanic ( chars)
1113
1114
|| ( ( chars. get ( * pos + 2 ) == Some ( & 'O' ) || chars. get ( * pos + 2 ) == Some ( & 'A' ) )
1114
1115
&& chars. get ( * pos + 3 ) == Some ( & 'M' ) )
1115
1116
{
@@ -1154,7 +1155,7 @@ fn w_case(State { pos, chars, p, s }: &mut State) {
1154
1155
}
1155
1156
1156
1157
if * pos == 0 {
1157
- if Word :: parse ( Rule :: vowels, get_char_as_string ( & chars, * pos + 1 ) . as_str ( ) ) . is_ok ( ) {
1158
+ if Word :: parse ( Rule :: vowels, get_char_as_string ( chars, * pos + 1 ) . as_str ( ) ) . is_ok ( ) {
1158
1159
* p += "A" ;
1159
1160
* s += "F" ;
1160
1161
} else if chars. get ( * pos + 1 ) == Some ( & 'H' ) {
@@ -1168,11 +1169,11 @@ fn w_case(State { pos, chars, p, s }: &mut State) {
1168
1169
&& chars. get ( * pos + 1 ) == Some ( & 'S' )
1169
1170
&& chars. get ( * pos + 2 ) == Some ( & 'K' )
1170
1171
&& ( chars. get ( * pos + 3 ) == Some ( & 'I' ) || chars. get ( * pos + 3 ) == Some ( & 'Y' ) ) )
1171
- || get_substring ( & chars, 0 , 3 ) == "SCH"
1172
+ || get_substring ( chars, 0 , 3 ) == "SCH"
1172
1173
|| ( * pos == chars. len ( ) . wrapping_sub ( 6 )
1173
1174
&& Word :: parse (
1174
1175
Rule :: vowels,
1175
- get_char_as_string ( & chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
1176
+ get_char_as_string ( chars, pos. wrapping_sub ( 1 ) ) . as_str ( ) ,
1176
1177
)
1177
1178
. is_ok ( ) )
1178
1179
{
@@ -1224,7 +1225,7 @@ fn z_case(State { pos, chars, p, s }: &mut State) {
1224
1225
&& ( chars. get ( * pos + 2 ) == Some ( & 'A' )
1225
1226
|| chars. get ( * pos + 2 ) == Some ( & 'I' )
1226
1227
|| chars. get ( * pos + 2 ) == Some ( & 'O' ) ) )
1227
- || ( slavo_germanic ( & chars) && * pos > 0 && chars. get ( pos. wrapping_sub ( 1 ) ) != Some ( & 'T' ) )
1228
+ || ( slavo_germanic ( chars) && * pos > 0 && chars. get ( pos. wrapping_sub ( 1 ) ) != Some ( & 'T' ) )
1228
1229
{
1229
1230
* p += "S" ;
1230
1231
* s += "TS"
0 commit comments