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

ffstring.h

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 ffstring.h
00027  * Defines a string datatype and related operations (implemented in ffstring.c) designed
00028  * for maximum flexibility for the programmer.
00029  * A general rule for argument order: If we're creating a new ffstring, the source
00030  * comes before the target. If we're just operating on an existing one, the target comes
00031  * first.
00032  */
00033 
00034 
00035 #ifndef __FFSTRING_H
00036 #define __FFSTRING_H
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 #include "fftypes.h"
00043 
00044 /**
00045  * Our much beloved string data type.
00046  */
00047 typedef struct ffstring
00048 {
00049   /**
00050    * Length of the string
00051    */
00052   ffuint32 len;
00053   /**
00054    * Data
00055    */
00056   ffchar* str;
00057 }
00058 ffstring;
00059 
00060 /**
00061  * Creates a new ffstring from a C-style string.
00062  * @param source The default content for the new ffstring. Must be a valid C-style string.
00063  * @param target Pointer to an uninitialized ffstring.
00064  * @return 0 on success. -1 on memory error.
00065  */
00066 ffint32 ffstring_create(const ffchar* source, ffstring* target);
00067 
00068 
00069 /**
00070  * Deletes an ffstring.
00071  * @param target The ffstring to be deleted.
00072  * @return 0 on success.
00073  */
00074 ffint32 ffstring_delete(ffstring* target);
00075 
00076 
00077 /**
00078  * Creates a copy of an ffstring. The caller should take care of disposing of it.
00079  * @param source String to be copied
00080  * @param target Pointer to uninitialized ffstring.
00081  * @return 0 on success or the error number returned by ffstring_create.
00082  */
00083 ffint32 ffstring_copy(const ffstring* source, ffstring* target);
00084 
00085 /**
00086  * Deletes count characters from the end of the target string. count must smaller or
00087  * equal to current length or an error is returned. 
00088  * The original data remains unchanged if an error occures.
00089  * (DFE == Delete From End)
00090  * @param target String from where characters are deleted
00091  * @param count How many characters are deleted
00092  * @return 0 on success. -1 on memory error. -2 on argument error.
00093  */
00094 ffint32 ffstring_dfe(ffstring* target, ffuint32 count);
00095 
00096 /**
00097  * Replaces the last count characters from the end of the target string with the C-style
00098  * string append. (RFE == Replace From End)
00099  * @param target String to modify
00100  * @param count Number of characters to delete
00101  * @param append String to append
00102  * @return 0 on success. -1 on memory error. -2 on argument error.
00103  */
00104 ffint32 ffstring_rfe(ffstring* target, ffuint32 count, ffchar* append);
00105 
00106 /**
00107  * Replaces the last count characters from the end of the target string with the ffstring
00108  * append. (RFE == Replace From End)
00109  * @param target The ffstring to modify
00110  * @param count Number of characters to delete
00111  * @param append The ffstring to append
00112  * @return 0 on success. -1 on memory error. -2 on argument error.
00113  */
00114 ffint32 ffstring_rfe_ff(ffstring* target, ffuint32 count, const ffstring* append);
00115 
00116 /**
00117  * Append a C-style string to the target ffstring. If the process fails, the target
00118  * ffstring remains unchanged.
00119  * @param target The target ffstring
00120  * @param append The C-style string to be appended
00121  * @return 0 on success. -1 on memory error.
00122  */
00123 ffint32 ffstring_append(ffstring* target, ffchar* append);
00124 
00125 /**
00126  * Append a ffstring to the target ffstring.
00127  * @param target The target ffstring
00128  * @param append The ffstring to be appended
00129  * @return 0 on success. -1 on memory error.
00130  */
00131 ffint32 ffstring_append_ff(ffstring* target, const ffstring* append);
00132  
00133 /**
00134  * Returns the current number of ffstring instances.
00135  * @return The current number of ffstring instances.
00136  */
00137 ffint32 ffstring_instcount(void);
00138 
00139 /**
00140  * Creates a new ffstring from at most count characters (not including the terminating
00141  * null byte) from the head of the source ffstring. The caller should
00142  * take care of disposing of the new ffstring.
00143  * @param source The source ffstring
00144  * @param count The number of characters to extract
00145  * @param target The target ffstring
00146  * @return 0 on success, -1 on memory error, -2 on argument terror
00147  */
00148 ffint32 ffstring_tail(const ffstring* source, ffint32 count, ffstring* target);
00149 
00150 /**
00151  * Converts a ffstring to lowercase.
00152  * @param target The ffstring to convert.
00153  * @return 0 on success, -1 on error.
00154  */
00155 ffint32 ffstring_tolower(ffstring* target);
00156 
00157 /**
00158  * Creates a lowercase copy of an ffstring. The caller has to take care of disposing of the new
00159  * ffstring.
00160  * @param source The source ffstring
00161  * @param target The uninitialized target ffstring
00162  * @return 0 on success, -1 on memory error
00163  */
00164 ffint32 ffstring_lower(const ffstring* source, ffstring* target);
00165 
00166 /**
00167  * Case-sensitively compares an ffstring to a C-style string using strcmp(3).
00168  * @param left The first string
00169  * @param right The second string
00170  * @return below zero if left < right, 0 if left == right, above zero if left > right
00171  */
00172 ffint32 ffstring_compare(const ffstring* left, const ffchar* right);
00173 
00174 /**
00175  * Case-insensitively compares an ffstring to a C-style string using tolower(3) and strcmp(3).
00176  * @param left The first string
00177  * @param right The second string
00178  * @return below zero if left < right, 0 if left == right, above zero if left > right
00179  */
00180 ffint32 ffstring_compare_ci(const ffstring* left, const ffchar* right);
00181 
00182 /**
00183  * Case-sensitively compares an ffstring to another using strcmp(3).
00184  * @param left The first string
00185  * @param right The second string
00186  * @return below zero if left < right, 0 if left == right, above zero if left > right
00187  */
00188 ffint32 ffstring_compare_ff(const ffstring* left, const ffstring* right);
00189 
00190 /**
00191  * Case-insensitively compares an ffstring to another string using tolower(3) and strcmp(3).
00192  * @param left The first string
00193  * @param right The second string
00194  * @return below zero if left < right, 0 if left == right, above zero if left > right
00195  */
00196 ffint32 ffstring_compare_ff_ci(const ffstring* left, const ffstring* right);
00197 
00198 /**
00199  * Case-sensitively compares the specified number of last characters of the given ffstring
00200  * to a C-style string.
00201  * @param left The string whose tail we're going to compare
00202  * @param count The number of characters to compare
00203  * @param right The C-style string to compare to
00204  * @return below zero if the extracted tail < right, 0 if they're the same, above zero otherwise
00205  */
00206 ffint32 ffstring_compare_tail(const ffstring* left, ffuint32 count, const ffchar* right);
00207 
00208 /**
00209  * Case-insensitively compares the specified number of last characters of the given ffstring
00210  * to a C-style string.
00211  * @param left The string whose tail we're going to compare
00212  * @param count The number of characters to compare
00213  * @param right The C-style string to compare to
00214  * @return below zero if the extracted tail < right, 0 if they're the same, above zero otherwise
00215  */
00216 ffint32 ffstring_compare_tail_ci(const ffstring* left, ffuint32 count, const ffchar* right);
00217 
00218 /**
00219  * Case-sensitively compares the specified number of last characters of the given ffstring
00220  * to another ffstring.
00221  * @param left The string whose tail we're going to compare
00222  * @param count The number of characters to compare
00223  * @param right The ffstring to compare to
00224  * @return below zero if the extracted tail < right, 0 if they're the same, above zero otherwise
00225  */
00226 ffint32 ffstring_compare_tail_ff(const ffstring* left, ffuint32 count, const ffstring* right);
00227 
00228 /**
00229  * Case-insensitively compares the specified number of last characters of the given ffstring
00230  * to another ffstring.
00231  * @param left The string whose tail we're going to compare
00232  * @param count The number of characters to compare
00233  * @param right The ffstring to compare to
00234  * @return below zero if the extracted tail < right, 0 if they're the same, above zero otherwise
00235  */
00236 ffint32 ffstring_compare_tail_ff_ci(const ffstring* left, ffuint32 count, const ffstring* right);
00237 
00238 /**
00239  * Returns the last character of the given ffstring.
00240  * @param source The source ffstring
00241  * @return The last character
00242  * @todo Wrong description
00243  */
00244 ffchar ffstring_last(const ffstring* source);
00245 
00246 /**
00247  * Case-sensitively compares the last character of the given ffstring to a given character
00248  * @param left The ffstring whose last character we're going to compare
00249  * @param right The character to compare to
00250  * @return below zero if last(left) < right, zero if last(left) == right, above zero otherwise
00251  */
00252 ffint32 ffstring_compare_last(const ffstring* left, const ffchar right);
00253 
00254 /**
00255  * Case-insensitively compares the last character of the given ffstring to a given character
00256  * @param left The ffstring whose last character we're going to compare
00257  * @param right The character to compare to
00258  * @return below zero if last(left) < right, zero if last(left) == right, above zero otherwise
00259  */
00260 ffint32 ffstring_compare_last_ci(const ffstring* left, const ffchar right);
00261 
00262 /**
00263  * Checks if the given ffstring and C-style string are the same.
00264  * @param left The first string
00265  * @param right The second string
00266  * @return 1 if the strings are the same; 0 if they're not.
00267  */
00268 ffbool ffstring_equals(const ffstring* left, const ffchar* right);
00269 
00270 /**
00271  * Case-insensitively checks if the given ffstring and C-style string are the same.
00272  * @param left The first string
00273  * @param right The second string
00274  * @return 1 if the strings are the same; 0 if they're not.
00275  */
00276 ffbool ffstring_equals_ci(const ffstring* left, const ffchar* right);
00277 
00278 /**
00279  * Checks if the two given ffstrings are the same.
00280  * @param left The first string
00281  * @param right The second string
00282  * @return 1 if the strings are the same; 0 if they're not.
00283  */
00284 ffbool ffstring_equals_ff(const ffstring* left, const ffstring* right);
00285 
00286 /**
00287  * Case-insensitively checks if the two given ffstrings are the same.
00288  * @param left The first string
00289  * @param right The second string
00290  * @return 1 if the strings are the same; 0 if they're not.
00291  */
00292 ffbool ffstring_equals_ff_ci(const ffstring* left, const ffstring* right);
00293 
00294 /**
00295  * Checks if the tail of the given ffstring is the same as the given C-style string.
00296  * @param left The string whose tail we are going to compare
00297  * @param count The length of the tail to be compared
00298  * @param right The string we're comparing to
00299  */
00300 ffbool ffstring_tail_equals(const ffstring* left, const ffint32 count, const ffchar* right);
00301 
00302 /**
00303  * Case-insensitively checks if the tail of the given ffstring is the same as the given C-style string.
00304  * @param left The string whose tail we are going to compare
00305  * @param count The length of the tail to be compared
00306  * @param right The string we're comparing to
00307  */
00308 ffbool ffstring_tail_equals_ci(const ffstring* left, const ffint32 count, const ffchar* right);
00309 
00310 /**
00311  * Checks if the tail of the given ffstring equals the other given ffstring.
00312  * @param left The string whose tail we are going to compare
00313  * @param count The length of the tail to be compared
00314  * @param right The string we're comparing to
00315  */
00316 ffbool ffstring_tail_equals_ff(const ffstring* left, const ffint32 count, const ffstring* right);
00317 
00318 /**
00319  * Case-insensitively checks if the tail of the given ffstring equals the other given ffstring.
00320  * @param left The string whose tail we are going to compare
00321  * @param count The length of the tail to be compared
00322  * @param right The string we're comparing to
00323  */
00324 ffbool ffstring_tail_equals_ff_ci(const ffstring* left, const ffint32 count, const ffstring* right);
00325 
00326 /**
00327  * Checks if the last character of the given string matches the given character.
00328  * @param left The string whose last character we are going to compare
00329  * @param right The character to compare to
00330  */    
00331 ffbool ffstring_last_equals(const ffstring* left, ffchar right);
00332 
00333 /**
00334  * Case-insensitively checks if the last character of the given string matches the given character.
00335  * @param left The string whose last character we are going to compare
00336  * @param right The character to compare to
00337  */  
00338 ffbool ffstring_last_equals_ci(const ffstring* left, ffchar right);
00339 
00340 /**
00341  * Decreases the ffstring instance counter. This function is meant to be used when an ffstring
00342  * struct ceases to exist but the real string data (ffstring.str) remains. USE WITH CAUTION!
00343  * @return 0 on success, -1 if the instance counter would go negative if decreased
00344  */
00345 ffint32 ffstring_decinst(void);
00346 
00347 #ifdef __cplusplus
00348 }
00349 #endif
00350 
00351 #endif

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