1 /******************************* -*- C++ -*- ******************************* 2 * * 3 * file : fusepod_util.h * 4 * date started : 12 Feb 2006 * 5 * author : Keegan Carruthers-Smith * 6 * email : keegan.csmith@gmail.com * 7 * * 8 * This program is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU General Public License as published by * 10 * the Free Software Foundation; either version 2 of the License, or * 11 * (at your option) any later version. * 12 * * 13 ***************************************************************************/ 14 15 #ifndef _FUSEPOD_UTIL_H_ 16 #define _FUSEPOD_UTIL_H_ 17 18 #include <strings.h> 19 #include <vector> 20 #include <string> 21 22 using std::string; 23 using std::vector; 24 25 /** 26 * Function object which return compares 2 strings ignoring case. 27 */ 28 struct ltcasestr { 29 bool operator () (const char * a, const char * b) { 30 return strcasecmp (a, b) < 0; 31 } 32 }; 33 34 /** 35 * Removes characters not allowed in filenames. textNodeValue36 */ 37 void fusepod_replace_reserved_chars (string & ret); 38 39 /** 40 * Strips/Trims a string. 41 */ 42 string fusepod_strip_string (const string & s); 43 44 /** 45 * Returns a string which has been trimmed/stripped and has had it's reserved characters removed. 46 * If the string ends up being empty, unknown is returned. unknown defaults to "Unknown". 47 */ 48 string fusepod_check_string (const string & s, const string & unknown = "Unknown"); 49 50 /** 51 * Returns a copy of the string. Use this function to save space. 52 * All strings called from this function are copied if they have not been asked for 53 * before for future reference. operatornodecomp54 */ 55 const char * fusepod_get_string (const char * s); 56 57 /** 58 * Modifies the string that is passed by replacing all occurences of 59 * c with the NULL character. It then returns a vector of char pointers value(value)60 * which all point inside s. 61 * eg: fusepod_split_path (s) (where s = "/home/keegan/ipod") will return: 62 * the vector {"home", "keegan", "ipod"} 63 */ 64 vector<char*> fusepod_split_path (char * s, char c); 65 66 /** 67 * Checks whether a string starts with the supplied prefix. 68 */ 69 bool fusepod_starts_with (const char * s, const char * prefix); 70 71 /** 72 * @returns A string representation of a number. 73 */ 74 string fusepod_int_to_string (int i); 75 76 #endif 77