1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SOLTOOLS_SIMSTR_HXX 29*cdf0e10cSrcweir #define SOLTOOLS_SIMSTR_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir class Simstr /// Simple string class. 33*cdf0e10cSrcweir { 34*cdf0e10cSrcweir // INTERFACE 35*cdf0e10cSrcweir public: 36*cdf0e10cSrcweir // LIFECYCLE 37*cdf0e10cSrcweir Simstr( 38*cdf0e10cSrcweir const char * str = 0); 39*cdf0e10cSrcweir Simstr( /** Creates Simstr out of a copy of the first 40*cdf0e10cSrcweir 'nrOfBytes' bytes of 'anyBytes'. 41*cdf0e10cSrcweir Adds a '\0' at the end. */ 42*cdf0e10cSrcweir const char * anybytes, 43*cdf0e10cSrcweir int nrOfBytes); 44*cdf0e10cSrcweir Simstr( /** Creates Simstr out of a copy of the described bytes within 'anyBytes'. 45*cdf0e10cSrcweir Adds a '\0' at the end. */ 46*cdf0e10cSrcweir const char * anybytes, 47*cdf0e10cSrcweir int firstBytesPos, 48*cdf0e10cSrcweir int nrOfBytes ); 49*cdf0e10cSrcweir Simstr( /// Creates Simstr of 'anzahl' times 'c'. 50*cdf0e10cSrcweir char c, 51*cdf0e10cSrcweir int anzahl); 52*cdf0e10cSrcweir Simstr( 53*cdf0e10cSrcweir const Simstr & S); 54*cdf0e10cSrcweir ~Simstr(); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // OPERATORS 58*cdf0e10cSrcweir operator const char*() const; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir Simstr & operator=( 61*cdf0e10cSrcweir const Simstr & S ); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir Simstr operator+( 64*cdf0e10cSrcweir const Simstr & S ) const; 65*cdf0e10cSrcweir Simstr & operator+=( 66*cdf0e10cSrcweir const Simstr & S ); 67*cdf0e10cSrcweir Simstr & operator+=( 68*cdf0e10cSrcweir const char * s ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir bool operator==( 71*cdf0e10cSrcweir const Simstr & S ) const; 72*cdf0e10cSrcweir bool operator!=( 73*cdf0e10cSrcweir const Simstr & S ) const; 74*cdf0e10cSrcweir bool operator<( 75*cdf0e10cSrcweir const Simstr & S ) const; 76*cdf0e10cSrcweir bool operator>( 77*cdf0e10cSrcweir const Simstr & S ) const; 78*cdf0e10cSrcweir bool operator<=( 79*cdf0e10cSrcweir const Simstr & S ) const; 80*cdf0e10cSrcweir bool operator>=( 81*cdf0e10cSrcweir const Simstr & S ) const; 82*cdf0e10cSrcweir // INFO 83*cdf0e10cSrcweir static const Simstr & 84*cdf0e10cSrcweir null_(); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir const char * str() const; 87*cdf0e10cSrcweir int l() const; // Length of string without '\0' at end. 88*cdf0e10cSrcweir char * s(); // ATTENTION !!! // Only to be used, when a function needs a 'char*' but 89*cdf0e10cSrcweir // nevertheless THAT WILL BE NOT CHANGED! 90*cdf0e10cSrcweir // Typecasts to 'const char*' are performed automatically. 91*cdf0e10cSrcweir char get( 92*cdf0e10cSrcweir int n) const; 93*cdf0e10cSrcweir char get_front() const; 94*cdf0e10cSrcweir char get_back() const; 95*cdf0e10cSrcweir Simstr get( 96*cdf0e10cSrcweir int startPos, 97*cdf0e10cSrcweir int anzahl ) const; 98*cdf0e10cSrcweir Simstr get_front( 99*cdf0e10cSrcweir int anzahl ) const; 100*cdf0e10cSrcweir Simstr get_back( 101*cdf0e10cSrcweir int anzahl ) const; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir int pos_first( 104*cdf0e10cSrcweir char c ) const; 105*cdf0e10cSrcweir int pos_first_after( 106*cdf0e10cSrcweir char c, 107*cdf0e10cSrcweir int startSearchPos ) const; 108*cdf0e10cSrcweir int pos_last( 109*cdf0e10cSrcweir char c ) const; 110*cdf0e10cSrcweir int pos_first( 111*cdf0e10cSrcweir const Simstr & S ) const; 112*cdf0e10cSrcweir int pos_last( 113*cdf0e10cSrcweir const Simstr & S ) const; 114*cdf0e10cSrcweir int count( 115*cdf0e10cSrcweir char c ) const; 116*cdf0e10cSrcweir bool is_empty() const; // Only true if object == "". 117*cdf0e10cSrcweir bool is_no_text() const; // String may contain spaces or tabs. 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir Simstr get_first_token( 120*cdf0e10cSrcweir char c ) const; 121*cdf0e10cSrcweir Simstr get_last_token( 122*cdf0e10cSrcweir char c ) const; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // ACCESS 125*cdf0e10cSrcweir char & ch( /** Reference to sz[n]. Allows change of this char. 126*cdf0e10cSrcweir !!! No safety, if n is out of the allowed range! */ 127*cdf0e10cSrcweir int n ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // OPERATIONS 130*cdf0e10cSrcweir void insert( 131*cdf0e10cSrcweir int pos, 132*cdf0e10cSrcweir char c ); 133*cdf0e10cSrcweir void push_front( 134*cdf0e10cSrcweir char c ); 135*cdf0e10cSrcweir void push_back( 136*cdf0e10cSrcweir char c ); 137*cdf0e10cSrcweir void insert( 138*cdf0e10cSrcweir int pos, 139*cdf0e10cSrcweir const Simstr & S ); 140*cdf0e10cSrcweir void push_front( 141*cdf0e10cSrcweir const Simstr & S ); 142*cdf0e10cSrcweir void push_back( 143*cdf0e10cSrcweir const Simstr & S ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir void remove( 146*cdf0e10cSrcweir int pos, 147*cdf0e10cSrcweir int anzahl = 1 ); 148*cdf0e10cSrcweir void remove_trailing_blanks(); 149*cdf0e10cSrcweir void pop_front( 150*cdf0e10cSrcweir int anzahl = 1 ); 151*cdf0e10cSrcweir void pop_back( 152*cdf0e10cSrcweir int anzahl = 1 ); 153*cdf0e10cSrcweir void rem_back_from( 154*cdf0e10cSrcweir int removeStartPos ); 155*cdf0e10cSrcweir void remove_all( 156*cdf0e10cSrcweir char c ); 157*cdf0e10cSrcweir void remove_all( // Starts search left. 158*cdf0e10cSrcweir const Simstr & S ); 159*cdf0e10cSrcweir void strip( 160*cdf0e10cSrcweir char c ); // Removes all characters == c from front and back. 161*cdf0e10cSrcweir // c == ' ' removes also TABs !!! 162*cdf0e10cSrcweir void empty(); // Changes object to the value "". 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void replace( 165*cdf0e10cSrcweir int pos, 166*cdf0e10cSrcweir char c ); 167*cdf0e10cSrcweir void replace( 168*cdf0e10cSrcweir int startPos, 169*cdf0e10cSrcweir int anzahl, 170*cdf0e10cSrcweir const Simstr & S ); 171*cdf0e10cSrcweir void replace_all( 172*cdf0e10cSrcweir char oldCh, 173*cdf0e10cSrcweir char newCh ); 174*cdf0e10cSrcweir void replace_all( 175*cdf0e10cSrcweir const Simstr & oldS, 176*cdf0e10cSrcweir const Simstr & newS ); 177*cdf0e10cSrcweir void to_lower(); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir Simstr take_first_token( /// Token is removed from the Simstr. 180*cdf0e10cSrcweir char c ); 181*cdf0e10cSrcweir Simstr take_last_token( /// Token is removed from the Simstr. 182*cdf0e10cSrcweir char c ); 183*cdf0e10cSrcweir private: 184*cdf0e10cSrcweir // DATA 185*cdf0e10cSrcweir char * sz; 186*cdf0e10cSrcweir int len; 187*cdf0e10cSrcweir }; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // Simstr - char* / char - concatenations 190*cdf0e10cSrcweir Simstr operator+(const char * str, const Simstr & S); 191*cdf0e10cSrcweir Simstr operator+(const Simstr & S, const char * str); 192*cdf0e10cSrcweir Simstr operator+(char c, const Simstr & S); 193*cdf0e10cSrcweir Simstr operator+(const Simstr & S, char c); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // Simstr - char* - comparison operators 196*cdf0e10cSrcweir bool operator==(const Simstr & S, const char * str); 197*cdf0e10cSrcweir bool operator!=(const Simstr & S, const char * str); 198*cdf0e10cSrcweir bool operator<(const Simstr & S, const char * str); 199*cdf0e10cSrcweir bool operator>(const Simstr & S, const char * str); 200*cdf0e10cSrcweir bool operator<=(const Simstr & S, const char * str); 201*cdf0e10cSrcweir bool operator>=(const Simstr & S, const char * str); 202*cdf0e10cSrcweir bool operator==(const char * str, const Simstr & S); 203*cdf0e10cSrcweir bool operator!=(const char * str, const Simstr & S); 204*cdf0e10cSrcweir bool operator<(const char * str, const Simstr & S); 205*cdf0e10cSrcweir bool operator>(const char * str, const Simstr & S); 206*cdf0e10cSrcweir bool operator<=(const char * str, const Simstr & S); 207*cdf0e10cSrcweir bool operator>=(const char * str, const Simstr & S); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir inline const char * 211*cdf0e10cSrcweir Simstr::str() const { return sz; } 212*cdf0e10cSrcweir inline char * 213*cdf0e10cSrcweir Simstr::s() { return sz; } 214*cdf0e10cSrcweir inline int 215*cdf0e10cSrcweir Simstr::l() const { return len; } 216*cdf0e10cSrcweir inline 217*cdf0e10cSrcweir Simstr::operator const char*() const { return sz; } 218*cdf0e10cSrcweir inline bool 219*cdf0e10cSrcweir Simstr::is_empty() const { return len == 0; } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir #endif 223*cdf0e10cSrcweir 224