00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "ffstring.h"
00031 #include "ffregex.h"
00032 #include "ffpriv_consonant_gradation.h"
00033
00034
00035 ffint32 ffpriv_consonant_gradation(ffstring* word, ffuint32 direction, ffuint32 type) {
00036 ffint32 err;
00037 ffstring t;
00038
00039 if (direction == 1 && type == 1) {
00040 if (ffregex_match_ci("^.*(kk|pp|tt)[aeiouyåäöÅÄÖ]$", word)) {
00041 err = ffstring_tail(word, 2, &t);
00042 if (err) {
00043 return err;
00044 }
00045 err = ffstring_rfe_ff(word, 3, &t);
00046 ffstring_delete(&t);
00047 return err;
00048 }
00049
00050 if (ffregex_match_ci("^.*[nlr]t[aeiouyåäöÅÄÖ]$", word)) {
00051 return -!ffregex_replace_ci("(.)t(.)$", "${1}${1}${2}", word);
00052 }
00053
00054 if (ffregex_match_ci("^.*[aeiouyåäöÅÄÖ]t[aeiouyåäöÅÄÖ]$", word)) {
00055 return -!ffregex_replace_ci("t(.)$", "d${1}", word);
00056 }
00057
00058 if (ffregex_match_ci("^.*mp[aeiouyåäöÅÄÖ]$", word)) {
00059 return -!ffregex_replace_ci("p(.)$", "m${1}", word);
00060 }
00061
00062 if (ffregex_match_ci("^.*[lr]p[aeiouyåäöÅÄÖ]$", word)) {
00063 return -!ffregex_replace_ci("p(.)$", "v${1}", word);
00064 }
00065
00066 if (ffregex_match_ci("^.*[aeiouyåäöÅÄÖ]p[aeiouyåäöÅÄÖ]$", word)) {
00067 return -!ffregex_replace_ci("p(.)$", "v${1}", word);
00068 }
00069
00070 if (ffregex_match_ci("^.*[lr]k[aeiouyåäöÅÄÖ]$", word)) {
00071 return -!ffregex_replace_ci("k(.)$", "${1}", word);
00072 }
00073
00074 if (ffregex_match_ci("^.*nk[aeiouyåäöÅÄÖ]$", word)) {
00075 return -!ffregex_replace_ci("k(.)$", "g${1}", word);
00076 }
00077
00078 if (ffregex_match_ci("^.*ht[aeiouyåäöÅÄÖ]$", word)) {
00079 return -!ffregex_replace_ci("t(.)$", "d${1}", word);
00080 }
00081
00082 if (ffregex_match_ci("^.[uy]k[uy]$", word)) {
00083 return -!ffregex_replace_ci("k(.)$", "v${1}", word);
00084 }
00085
00086 if (ffregex_match_ci("^([aeiouyåäöÅÄÖ]|[^aeiouyåäöÅÄÖ][aeiouyåäöÅÄÖ]+)k[aeiouyåäöÅÄÖ]$", word)) {
00087 return -!ffregex_replace_ci("k(.)$", "${1}", word);
00088 }
00089 } else if (direction == 2 && type == 1) {
00090
00091 if (ffregex_match_ci("^.*[io]e$", word)
00092 || ffregex_match_ci("(^[^aeiouyåäöÅÄÖ]u|^.*(iu))e$", word)
00093 || ffregex_match_ci("^.[aäÄ]e$", word)) {
00094 ffstring_append(word, "!");
00095 return -!ffregex_replace_ci("(e)!$", "k${1}", word);
00096 }
00097
00098 if (ffstring_tail_equals_ci(word, 3, "lle")) {
00099 return ffstring_rfe(word, 2, "te");
00100 }
00101
00102
00103 if (ffregex_match_ci("[^str]te$", word)) {
00104 return ffstring_rfe(word, 1, "te");
00105 }
00106
00107 if (ffregex_match_ci("[^skt]ke$", word)) {
00108 return ffstring_rfe(word, 1, "ke");
00109 }
00110
00111 if (ffregex_match_ci("[^spt]pe$", word)) {
00112 return ffstring_rfe(word, 1, "pe");
00113 }
00114
00115 }
00116
00117 return 0;
00118 }
00119