/*************************************************************************** * Copyright (C) 2004 by Paulo Moura Guedes * * moura@tdewebdev.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; either version 2 of the License, or * * (at your option) any later version. * * * * 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., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef STRING_H #define STRING_H #include #include #include class TQString; typedef unsigned int uint; /* Similar to std::string::find but return the next index of the last char of the first word it finds. Case insensitive. e.g. findWord("Biltre larvado", "biltre") => 6 */ int findWord(TQString const& s, TQString const& palavra, uint a_partir_do_indice = 0); /** Similar to std::string::find but return the next index of the first char it finds. Case insensitive. */ int findChar(TQString const& s, TQChar letra, uint a_partir_do_indice = 0); /** Same as findWord but non space chars are eliminated. e.g. findWord("", " 2 findSeparableWord("", " 2 findWord("<\na href="">", " -1 findSeparableWord("<\na href="">", " 3 */ int findSeparableWord(TQString const& s, TQString const& palavra, uint a_partir_do_indice = 0); /** Space means Unicode characters with decimal values 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space). */ bool isSpace(TQChar c); /** Return -1 if unsuccessful. */ int nextNonSpaceChar(TQString const& s, uint i); int nextNonSpaceCharReverse(TQString const& s, uint i); int nextSpaceChar(TQString const& s, uint i); int nextCharDifferentThan(TQChar c, TQString const& s, uint i); /** Return a vector with the words */ std::vector tokenize(TQString s); std::vector tokenizeWordsSeparatedByDots(TQString s); std::vector tokenizeWordsSeparatedBy(TQString s, TQChar criteria); /** Returns a string that has whitespace removed from the start and the end, and which has each sequence of internal whitespace replaced with a single space. */ TQString simplifyWhiteSpace(TQString const& s); /** If char 'caractere' is the last in the string 's' it is removed */ void removeLastCharIfExists(TQString& s, TQChar caractere); TQString upperCase(TQString const& s); TQString lowerCase(TQString const& s); /** Remove whitespaces from the end of the string */ void stripWhiteSpaceFromTheEnd(TQString& s); /** Returns a string that has whitespace removed from the start and the end. */ void stripWhiteSpace(TQString& s); /** Case insensitive comparisons */ bool equal(TQString const& s1, TQString const& s2); bool notEqual(TQString const& s1, TQString const& s2); bool equal(TQChar c1, TQChar c2); bool notEqual(TQChar c1, TQChar c2); //_________________________________________________________________________ inline bool isSpace(TQChar c) { return c.isSpace(); } inline bool equal(TQString const& s1, TQString const& s2) { if(s1 == s2) return true; else return s1.lower() == s2.lower(); } inline bool notEqual(TQString const& s1, TQString const& s2) { return !(equal(s1, s2)); } inline bool equal(TQChar c1, TQChar c2) { return c1.lower() == c2.lower(); } inline bool notEqual(TQChar c1, TQChar c2) { return !(equal(c1, c2)); } inline TQString upperCase(TQString const& s) { return s.upper(); } inline TQString lowerCase(TQString const& s) { return s.lower(); } inline TQString simplifyWhiteSpace(TQString const& s) { return s.simplifyWhiteSpace(); } inline void removeLastCharIfExists(TQString& s, TQChar caractere) { int index = s.length() - 1; if(s[index] == caractere) s.remove(index); } inline void stripWhiteSpace(TQString& s) { s = s.stripWhiteSpace(); } #endif