1 /* 2 * cStringUtil.h 3 * Avida 4 * 5 * Called "string_util.hh" prior to 12/7/05. 6 * Copyright 1999-2011 Michigan State University. All rights reserved. 7 * Copyright 1993-2003 California Institute of Technology. 8 * 9 * 10 * This file is part of Avida. 11 * 12 * Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License 13 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 14 * 15 * Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License along with Avida. 19 * If not, see <http://www.gnu.org/licenses/>. 20 * 21 */ 22 23 #ifndef cStringUtil_h 24 #define cStringUtil_h 25 26 #ifndef cString_h 27 #include "cString.h" 28 #endif 29 30 #ifndef tArray_h 31 #include "tArray.h" 32 #endif 33 34 class cStringUtil 35 { 36 private: 37 cStringUtil(); // @not_implemented 38 39 public: 40 static cString Stringf(const char * fmt, ...); 41 static cString ToRomanNumeral(const int in_value); 42 static int StrLength(const char * _in); 43 44 /** 45 * Calculate the Hamming distance between two strings. 46 * 47 * @return The Hamming distance. 48 * @param string1 the first string to compare. 49 * @param string2 the second string to compare. 50 * @param offset This parameter determines how many characters the second 51 * string should be shifted wrt. the first before the comparison. 52 **/ 53 static int Distance(const cString& string1, const cString& string2, int offset = 0); 54 55 /** 56 * Calculate the edit distance between two strings. 57 * 58 * @return The Edit (Levenstein) distance. 59 * @param string1 the first string to compare. 60 * @param string2 the second string to compare. 61 * @param description The string to write out the differences 62 **/ 63 static int EditDistance(const cString& string1, const cString& string2); 64 static int EditDistance(const cString& string1, const cString& string2, cString& info, const char gap = ' '); 65 66 /** 67 * Various, overloaded conversion functions for use in templates. Note 68 * that in all cases, the second argument is simply to set the return type. 69 **/ 70 static const cString & Convert(const cString& in_string, const cString& out_string); 71 static bool Convert(const cString& in_string, bool type_bool); 72 static int Convert(const cString& in_string, int type_int); 73 static double Convert(const cString& in_string, double type_double); 74 static cString Convert(const cString& in_string); 75 static cString Convert(bool in_bool); 76 static cString Convert(int in_int); 77 static cString Convert(double in_double); 78 79 /* Return an array of integers from a string with format x,y..z,a */ 80 81 static tArray<int> ReturnArray(cString& in_string); 82 }; 83 84 85 #endif 86