Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

ffutil.c

Go to the documentation of this file.
00001 /*
00002  * finflect - Algorithms and tools for inflecting Finnish nouns
00003  * Copyright (C) 2004, 2005  The FinFlect Team
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  *
00020  * For the complete legal text of the GNU Lesser General Public License,
00021  * see the file LICENSE. For a complete list of authors and copyright
00022  * holders, see the file AUTHORS.
00023  */
00024 
00025 /**
00026  * @file ffutil.c Implements the utility functions (declared in ffutil.c).
00027  */
00028 
00029 #include <stdlib.h>
00030 
00031 #include "fftypes.h"
00032 #include "ffutil.h"
00033 
00034 static const char* v_low = "aeiouyåäö";
00035 static const char* v_upp = "AEIOUYÅÄÖ";
00036 static const char* c_low = "bcdfghjklmnpqrstvwxz";
00037 static const char* c_upp = "BCDFGHJKLMNPQRSTVWXZ";
00038 static const ffuint32 v_len = 9;
00039 static const ffuint32 c_len = 20;
00040 
00041 ffbool ffpriv_is_vowel(const char letter) {
00042   const char* i = v_low;
00043 
00044   for (;i < v_low+v_len; ++i) {
00045     if (letter == *i ) {
00046       return 1;
00047     }
00048   }
00049 
00050   i = v_upp;
00051   for (;i < v_upp+v_len; ++i) {
00052     if (letter == *i ) {
00053       return 1;
00054     }
00055   }
00056 
00057   return 0;
00058 }
00059 
00060 ffbool ffpriv_is_consonant(const char letter) {
00061   const char* i = c_low;
00062 
00063   for (;i < c_low+c_len; ++i) {
00064     if (letter == *i ) {
00065       return 1;
00066     }
00067   }
00068 
00069   i = c_upp;
00070   for (;i < c_upp+c_len; ++i) {
00071     if (letter == *i ) {
00072       return 1;
00073     }
00074   }
00075 
00076   return 0;
00077 }
00078 
00079 ffchar* ffpriv_vowel_harmony(const ffstring* string, ffchar* back, ffchar* front) {
00080   ffint32 i = string->len -1;
00081   ffchar c;
00082   for (; i >= 0; i--) {
00083     c = string->str[i];
00084     if (c == 'a' || c == 'A' || c == 'o' || c == 'O' || c == 'u' || c == 'U' ) {
00085       return back;
00086     } else if (c == 'ä' || c == 'Ä' || c == 'ö' || c == 'Ö' || c == 'y' || c == 'Y' ) {
00087       return front;
00088     }
00089   }
00090   return front;
00091 }
00092 
00093 ffuint32 ffutil_tolower(const ffstring* source, ffstring* target) {
00094   ffuint32 i = 0;
00095   ffchar c;
00096 
00097   ffstring_copy(source, target);
00098 
00099   for (;i < source->len; i++) {
00100     c = source->str[i];
00101 
00102     if (c >= 'A' && c <= 'Z' ) {
00103       target->str[i] = c + ('a' - 'A');
00104       continue;
00105     }
00106     switch (c) {
00107     case 'Ä':
00108       target->str[i] = 'ä';
00109       break;
00110     case 'Ö':
00111       target->str[i] = 'ö';
00112       break;
00113     case 'Å':
00114       target->str[i] = 'å';
00115       break;
00116     }
00117   }
00118   return 0;
00119 }
00120 
00121 ffuint32 ffutil_toupper(const ffstring* source, ffstring* target) {
00122   ffuint32 i = 0;
00123   ffchar c;
00124 
00125   ffstring_copy(source, target);
00126   for (;i < source->len; i++) {
00127     c = source->str[i];
00128 
00129     if (c >= 'a' && c <= 'z' ) {
00130       target->str[i] = c - ('a' - 'A');
00131       continue;
00132     }
00133     switch (c) {
00134     case 'ä':
00135       target->str[i] = 'Ä';
00136       break;
00137     case 'ö':
00138       target->str[i] = 'Ö';
00139       break;
00140     case 'å':
00141       target->str[i] = 'Å';
00142       break;
00143     }
00144   }
00145   return 0;
00146 }
00147 
00148 
00149 ffchar ffutil_ffchar_tolower(ffchar c) {
00150   if (c >= 'A' && c <= 'Z' ) {
00151     return c + ('a' - 'A');
00152   }
00153 
00154   switch (c) {
00155   case 'Ä':
00156     return 'ä';
00157   case 'Ö':
00158     return 'ö';
00159   case 'Å':
00160     return 'å';
00161   }
00162   return c;
00163 }

Generated on Thu Jun 2 23:16:59 2005 for FinFlect by  doxygen 1.4.2