/* * strutil.h by Matze Braun * * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 of the License) * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef __STRUTIL_H__ #define __STRUTIL_H__ // CS INCLUDES #include #include #include #include #include void Split(const csString& str, csArray & arr); /** * Return the given word number * * Return word at the position number in the input string str. If a pointer * to startpos is given the position of the found word would be return. * * @param str The string that are to be search for the word * @param number The position of the the word to be found * @param startpos A pointer that if non zero will get the position in the string where word where found. * @return Return the word at position number in the string. */ csString& GetWordNumber(const csString& str, int number, size_t * startpos = NULL); /** WordArray is class that parses text command (e.g. "/newguild Insomniac Developers") to words */ class WordArray : protected csStringArray { public: WordArray(const csString& cmd, bool ignoreQuotes = true); size_t GetCount() const { return Length(); } /* Returns given word, or empty string if it does not exist */ csString& Get(size_t wordNum) { if(wordNum < Length()) temp = csStringArray::Get(wordNum); else temp = ""; return temp; } csString& operator[](size_t wordNum) { if(wordNum < Length()) temp = csStringArray::Get(wordNum); else temp = ""; return temp; } int GetInt(size_t wordNum) { return atoi(Get(wordNum).GetData()); } float GetFloat(size_t wordNum) { return atof(Get(wordNum).GetData()); } /* Returns all words, starting at given word */ csString& GetTail(size_t wordNum); void GetTail(size_t wordNum, csString& dest); /* Gets all the words from startWord to endWord */ csString& GetWords( size_t startWord, size_t endWord); size_t FindStr(const char *str,int start=0); protected: csString temp,temp2; size_t AddWord(const csString& cmd, size_t pos); size_t AddQuotedWord(const csString& cmd, size_t pos); void SkipSpaces(const csString& cmd, size_t & pos); }; bool psContain(const csString& str, const csArray& strs); bool psSentenceContain(const csString& sentence,const csString& word); char* PS_GetFileName(char* path); csArray psSplit(csString& str, char delimer); csString toString(const csVector3& pos); csString toString(const csVector3& pos, iSector* sector); #endif