// -*- C++ -*- /* This file is part of *====================================================== * *LyX,TheDocumentProcessor * *Copyright(C)19951996MatthiasEttrich *andtheLyXTeam. *
*======================================================*/
// This one is heavily based on the string class in The C++ // Programming Language by Bjarne Stroustrup
#ifndef _LSTRING_H_ #define _LSTRING_H_
#ifdef __GNUG__ #pragma interface #endif
#include <config.h> // needed at least for compiler that do not // understand 'explicit' (JMarc) #ifdef _AIX // AIX has strange ideas about where definitions like strcasecmp // should go (JMarc) #include <strings.h> #else #include <string.h> #endif
/** A string class for LyX ThisisapermanentStringclass.Itwassupposedtobesuperseeded withQStringwhenweswitchtotheQtlibrary,butnowit'ssodeveloped thatitisasgoodastheirs(ormaybeevenbetter:-)
/**@name Methods */ //@{ /// to comply with the STL strings bool empty() const; /// //bool isEmpty() const; /// //bool notEmpty() const; /// int length() const;
// should be renamed to erase() (STL) /** equivalent to *this = empty. But usable outside LString
implementation */
LString &clean();
/// This should be renamed to c_str() charconst* c_str() const;
// we should make the caller supply the storage to copy into. (STL) /** This one returns a verbatim copy. Only temporary. Thecallershouldcalldelete[]whendonewiththestring
*/ char * copy() const;
/// bool contains(charconst *) const;
// Remove and replace (STL) /// Truncate to substring. I.e. #"abcdef".substring(2,4)="cde"#
LString& substring(int i1, int i2);
/** Splits the string by the first delim. Splitsthestringbythefirstappearanceofdelim. Theleadingstringuptodelimisreturnedinpiece(notincluding delim),whiletheoriginalstringiscutfromafterthedelimiter. Example: #s1="";s2="a;bc".split(s1,';')->s1=="a";s2=="bc";#
*/
LString& split(LString& piece, char delim); /// Same as split but does not return a piece
LString& split(char delim); /// Same as split but uses the last delim.
LString& rsplit(LString& piece, char delim);
/** Extracts a token from this string at the nth delim. Doesn'tmodifytheoriginalstring.Similartostrtok. Example: #"a;bc;d".token(';',1)=="bc";# #"a;bc;d".token(';',2)=="d";#
*/
LString token(char delim, int n=0) const;
/** Search a token in this string using the delim. Doesn'tmodifytheoriginalstring.Returns-1incaseof failure. Example: #"a;bc;d".tokenPos(';',"bc")==1;# #"a;bc;d".token(';',"d")==2;#
*/ int tokenPos(char delim, LString const &tok);
/** Strips characters off the end of a string. #"abccc".strip('c')="ab".#
*/
LString& strip(charconst c = ' ');
/** Strips characters of the beginning of a string.
#"cccba".frontstrip('c') = "ba"#. */
LString& frontStrip(charconst c = ' ');
/// Does the string start with this prefix? bool prefixIs(charconst *) const;
/// Does the string end with this char? bool suffixIs(char) const;
/// Does the string end with this suffix? bool suffixIs(charconst *) const;
/// Substitute all "oldchar"s with "newchar"
LString& subst(char oldchar, char newchar);
/// Substitutes all instances of oldstr with newstr
LString& subst(charconst * oldstr, LString const & newstr);
/** Compares a string and a (simple) regular expression Theonlyelementallowedis"*"foranystringofcharacters
*/ bool regexMatch(LString const & pattern) const;
/// Lowercases a string
LString& lowercase();
/// Counts how many of character c there is in string int countChar(constchar c) const;
/// Position of the character c from the beggining int charPos(constchar c) const;
protected: private: /// A string representation struct srep { /// Length unsignedint l; /// Reference count (number of references - 1) unsignedshort n; /// Extra space at end of allocated string unsignedshort e; /// Data. At least 1 char for trailing null. char s[1]; ///
srep() { n = 0; l = 0; e = 0; s[0] = '\0'; }
};
/** The empty srep is a local static in each function that needsone.Thereisno"global"emptysrepbutLString doesn'tneedone(nocodeactuallyreliesuponasingle emptysrep). Thisovercomes*all*"staticinitialization"problems, atmaximumspeed,withasmalloverheadof6localstatic empty_reps.
*/ // This is the only other option (or a variant of this anyway) // I originally offered this style of empty_rep in 9709 but // it was rejected for requiring too many function calls and pointer operations(!) // and because another implementation was to be trialed (which has since // apparently failed for some compilers). ARRae // static srep& empty_rep() // { // static srep mt; // return mt; // }
/// A string is a pointer to it's representation
srep *p; /// void lose();
};
inline LString::LString(LString const &x)
{
x.p->n++;
p = x.p;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.