/usr/include/dclib-0.3/dclib/core/cstring.h is in libdc-dev 0.3.24~svn3121-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | /***************************************************************************
cstring.h - description
-------------------
begin : Fri Sep 21 2001
copyright : (C) 2001-2003 by Mathias Küster
email : mathen@users.berlios.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef CSTRING_H
#define CSTRING_H
/**
*@author Mathias Küster
*
* Now that CStringList is a template class, lots of classes, starting
* with CString, no longer need to inherit CObject or have a virtual
* destructor, which should make creating and destroying them
* slightly faster.
*
* The appending functions no longer start by making a copy of the data
* and then appending that. Instead there is some pointer checking,
* for handling appending (part of) a string to itself.
*
* Despite dclib being full of "inline" functions, IsEmpty() is not inline.
*
* CString s = "";
* s.Data() == NULL;
*
* An empty CString generally contains a NULL pointer. NULL pointers usually
* crash C library functions that take a "char *" parameter.
*
* CString has no idea what encoding the string is in, it's length is the
* number of bytes which may well be more than the number of characters
* for UTF-8. ToUpper() and ToLower() only handle ascii a-z -> A-Z.
*
* The main thing about CString is it does not having the implicit sharing
* that the QT's QString and other classes, so it is not very efficient to
* pass it around by value.
*/
#include <dclib/dcos.h>
class CString {
public:
/** Constructs a null string.
This is a string that has not been assigned to anything, i.e. both the length and data pointer is 0.
*/
CString();
/** Constructs a string that is a deep copy of sz, interpreted as a classic C string. If sz is 0, then a null string is created.
*/
CString( const char * sz );
/** Constructs a string giving it a length of one character, assigning it the character ch.
*/
CString( const char ch );
/** Constructs a string that is a deep copy of stringSrc.
*/
CString( const CString & stringSrc );
/** Destroys the string and frees its buffer.
*/
~CString();
/** */
void Empty();
/** */
bool IsEmpty() const;
/** */
bool NotEmpty() const { return !IsEmpty(); }
/**
* This is supposed to be faster than doing
*
* s.Left(other.Length()) == other
*
* because it avoids Left() which creates a copy.
*
* In QT4 a null QString does not start with an empty QString.
* However in dclib an empty CString is always null.
* Therefore if other is empty StartsWith always returns true
* even if this CString is also empty.
*/
bool StartsWith( const CString & other ) const;
/** */
bool StartsWith( const char * other, long len ) const;
/** */
inline CString& Set( const char * sz, long nLength ) { set(sz,nLength); return *this; }
/** */
long Find( const char ch, long nStart = 0 ) const;
/** */
long Find( const char * sz, long nStart = 0, bool cs = true ) const;
/** */
long Find( const CString & string, long nStart = 0, bool cs = true ) const;
/** */
long FindCase( const char * sz, long nStart = 0 ) const;
/** */
long FindCase( const CString & string, long nStart = 0 ) const;
/** */
long FindRev( char ch, long nStart = -1 ) const;
/** */
long FindRev( const CString & string ) const;
/** */
void Append( const char ch );
/** */
inline void Append( const char * sz ) { add(sz); }
/** */
inline void Append( const CString & string ) { add(string.Data(),string.Length()); }
/** */
inline CString Left( long nCount ) const { return Mid(0,nCount); }
/** */
inline CString Right( long nCount ) const { return Mid(Length()-nCount,nCount); };
/** */
CString Mid( long nFirst, long nCount = -1 ) const;
/** */
CString Section( const char sep, int start, int end ) const;
/** */
CString RightJustify( long nNewLength, char chFill = ' ', bool truncate = false );
/** */
CString ToUpper() const;
/** */
CString ToLower() const;
/** */
CString Replace( CString src, CString string ) const;
/**
* Replaces all occurences of 'before' in the string
* with 'after'.
*
* Although any normal string replace function would
* return a reference to itself by returning *this,
* CString::Swap() does not.
*/
void Swap( const char before, const char after );
/**
* These all used to be called setNum but since
* they didn't (did not modify the string), they just make
* a new string and return it, they have been made static
* and renamed for consistency with QString.
*/
static CString number( const int n );
/** */
static CString number( const unsigned int n );
/** */
static CString number( const long n );
/** */
static CString number( const unsigned long n );
/** */
static CString number( const long long n );
/** */
static CString number( const ulonglong n );
/** */
static CString number( const double n, const int p );
/** */
ulonglong asULL( int base = 10 ) const;
/** */
unsigned int asUINT( int base = 10 ) const;
/** */
unsigned long asULONG( int base = 10 ) const;
/** */
int asINT( int base = 10 ) const;
/** */
long asLONG( int base = 10 ) const;
/** */
long long asLONGLONG( int base = 10 ) const;
/** */
double asDOUBLE() const;
/** */
unsigned char GetHash( long value = 0 ) const;
/** */
inline CString& operator += ( const char ch ) { Append(ch); return *this; };
/** */
inline CString& operator += ( const char * sz ) { add(sz); return *this; };
/** */
inline CString& operator += ( const CString & string ) { add(string.Data(),string.Length()); return *this; };
/** */
inline CString & operator = ( const char * sz ) { set(sz); return *this; };
/** */
inline CString & operator = ( const CString & string ) { set(string.Data(),string.Length()); return *this; };
/** */
inline char * Data() const { return m_szBuffer; }
/** */
inline long Length() const { return m_nStringLength; }
/**
* Returns 0 if strings are equal, <0 if other is less than this, >0 if other is greater than this.
* So essentially it's just strcoll (which uses current locale).
*/
int Compare ( const CString & other ) const;
/** */
int Compare ( const char * other ) const;
private:
/** */
long m_nStringLength;
/** */
long m_nBufferSize;
/** */
char * m_szBuffer;
/** */
void set( const char * sz, long nLength = -1 );
/** */
void add( const char * sz, long nLength = -1 );
/**
* This should never have been public unless you actually
* want a function for leaking memory.
*/
void Init();
/**
* For private use, to create a CString from an existing buffer.
*/
CString( char * buffer, long length, long bufsize );
};
/** */
bool operator == ( const CString & string1, const CString & string2 );
/** */
bool operator == ( const char * sz, const CString & string );
/** */
bool operator == ( const CString & string, const char * sz );
/** */
bool operator != ( const CString & string1, const CString & string2 );
/** */
bool operator != ( const char * sz, const CString & string );
/** */
bool operator != ( const CString & string1, const char * sz );
/** */
inline CString operator + ( const CString & string1, const CString & string2 ) { CString tmp(string1); tmp.Append(string2); return tmp; }
/** */
inline CString operator + ( const char * sz, const CString & string ) { CString tmp(sz); return (tmp+string); }
/** Returns true if lhs is less than rhs, false if equal or greater than */
inline bool operator < ( const CString & lhs, const CString & rhs ) { return (lhs.Compare(rhs) < 0); }
/** Returns true if lhs is less than rhs, false if equal or greater than */
inline bool operator < ( const CString & lhs, const char * rhs ) { return (lhs.Compare(rhs) < 0); }
/** Returns true if lhs is less than rhs, false if equal or greater than */
inline bool operator < ( const char * lhs, const CString & rhs ) { return (rhs.Compare(lhs) > 0); }
/** Returns true if lhs is less than or equal to rhs, false if greater than */
inline bool operator <= ( const CString & lhs, const CString & rhs ) { return (lhs.Compare(rhs) <= 0); }
/** Returns true if lhs is less than or equal to rhs, false if greater than */
inline bool operator <= ( const CString & lhs, const char * rhs ) { return (lhs.Compare(rhs) <= 0); }
/** Returns true if lhs is less than or equal to rhs, false if greater than */
inline bool operator <= ( const char * lhs, const CString & rhs ) { return (rhs.Compare(lhs) >= 0); }
/** Returns true if lhs is greater than rhs, false if equal or less than */
inline bool operator > ( const CString & lhs, const CString & rhs ) { return (lhs.Compare(rhs) > 0); }
/** Returns true if lhs is greater than rhs, false if equal or less than */
inline bool operator > ( const CString & lhs, const char * rhs ) { return (lhs.Compare(rhs) > 0); }
/** Returns true if lhs is greater than rhs, false if equal or less than */
inline bool operator > ( const char * lhs, const CString & rhs ) { return (rhs.Compare(lhs) < 0); }
/** Returns true if lhs is greater than or equal to rhs, false if less than */
inline bool operator >= ( const CString & lhs, const CString & rhs ) { return (lhs.Compare(rhs) >= 0); }
/** Returns true if lhs is greater than or equal to rhs, false if less than */
inline bool operator >= ( const CString & lhs, const char * rhs ) { return (lhs.Compare(rhs) >= 0); }
/** Returns true if lhs is greater than or equal to rhs, false if less than */
inline bool operator >= ( const char * lhs, const CString & rhs ) { return (rhs.Compare(lhs) <= 0); }
#endif
|