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

Generated on Sun May 15 21:50:47 2005 for FinFlect by  doxygen 1.4.1