00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _GSTRING_H_
00058 #define _GSTRING_H_
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00108
00109
00110 #include "DjVuGlobal.h"
00111 #include "GContainer.h"
00112
00113 #include <stdlib.h>
00114 #include <stdarg.h>
00115 #ifdef WIN32
00116 # include <windows.h>
00117 # define HAS_WCHAR 1
00118 # define HAS_MBSTATE 1
00119 #endif
00120
00121 #if HAS_WCHAR
00122 # if !defined(AUTOCONF) || HAVE_WCHAR_H
00123 # include <wchar.h>
00124 # endif
00125 #endif
00126
00127
00128 #ifdef HAVE_NAMESPACES
00129 namespace DJVU {
00130 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00131 }
00132 #endif
00133 #endif
00134
00135 #if !HAS_MBSTATE
00136 # ifndef HAVE_MBSTATE_T
00137 typedef int mbstate_t;
00138 # endif
00139 #endif
00140
00141 class GBaseString;
00142
00143
00144 class GStringRep : public GPEnabled
00145 {
00146 public:
00147 enum EncodeType { XUCS4, XUCS4BE, XUCS4LE, XUCS4_2143, XUCS4_3412,
00148 XUTF16, XUTF16BE, XUTF16LE, XUTF8, XEBCDIC, XOTHER } ;
00149
00150 enum EscapeMode { UNKNOWN_ESCAPED=0, IS_ESCAPED=1, NOT_ESCAPED=2 };
00151
00152 class UTF8;
00153 friend class UTF8;
00154 class Unicode;
00155 friend class Unicode;
00156
00157 class ChangeLocale;
00158 #if HAS_WCHAR
00159 class Native;
00160 friend class Native;
00161 #endif // HAS_WCHAR
00162 friend class GBaseString;
00163 friend class GUTF8String;
00164 friend class GNativeString;
00165 friend unsigned int hash(const GBaseString &ref);
00166
00167 public:
00168
00169 GStringRep(void);
00170
00171 virtual ~GStringRep();
00172
00173
00174
00175 virtual GP<GStringRep> blank(const unsigned int sz) const = 0;
00176
00177 GP<GStringRep> getbuf(int n) const;
00178
00179 GP<GStringRep> setat(int n, char ch) const;
00180
00181 virtual GP<GStringRep> append(const GP<GStringRep> &s2) const = 0;
00182
00183 virtual bool isUTF8(void) const { return false; }
00184
00185 virtual bool isNative(void) const { return false; }
00186
00187 virtual GP<GStringRep> toNative(
00188 const EscapeMode escape=UNKNOWN_ESCAPED ) const = 0;
00189
00190 virtual GP<GStringRep> toUTF8(const bool nothrow=false) const = 0;
00191
00192 virtual GP<GStringRep> toThis(
00193 const GP<GStringRep> &rep,const GP<GStringRep> &locale=0) const = 0;
00194
00195 virtual int cmp(const GP<GStringRep> &s2,const int len=(-1)) const = 0;
00196
00197
00198 virtual int toInt(void) const = 0;
00199 virtual long int toLong(
00200 const int pos, int &endpos, const int base=10) const = 0;
00201 virtual unsigned long toULong(
00202 const int pos, int &endpos, const int base=10) const = 0;
00203 virtual double toDouble(const int pos, int &endpos) const = 0;
00204
00205
00206 int nextChar( const int from=0 ) const;
00207
00208
00209 int nextNonSpace( const int from=0, const int len=(-1) ) const;
00210
00211
00212 int nextSpace( const int from=0, const int len=(-1) ) const;
00213
00214
00215 int firstEndSpace( int from=0, const int len=(-1) ) const;
00216
00217
00218 template <class TYPE> static GP<GStringRep> create(
00219 const unsigned int sz,TYPE *);
00220
00221 GP<GStringRep> strdup(const char *s) const;
00222
00223
00224 GP<GStringRep> append(const char *s2) const;
00225
00226
00227 GP<GStringRep> concat(const GP<GStringRep> &s1,const GP<GStringRep> &s2) const;
00228 GP<GStringRep> concat(const char *s1,const GP<GStringRep> &s2) const;
00229 GP<GStringRep> concat(const GP<GStringRep> &s1,const char *s2) const;
00230 GP<GStringRep> concat(const char *s1,const char *s2) const;
00231
00232
00233
00234
00235 GP<GStringRep> substr(
00236 const char *s,const int start,const int length=(-1)) const;
00237
00238 GP<GStringRep> substr(
00239 const unsigned short *s,const int start,const int length=(-1)) const;
00240
00241 GP<GStringRep> substr(
00242 const unsigned long *s,const int start,const int length=(-1)) const;
00243
00250 GP<GStringRep> vformat(va_list args) const;
00251
00252
00253 static GP<GStringRep> UTF8ToNative( const char *s,
00254 const EscapeMode escape=UNKNOWN_ESCAPED );
00255 static GP<GStringRep> NativeToUTF8( const char *s );
00256
00257
00258 GP<GStringRep> upcase(void) const;
00259
00260 GP<GStringRep> downcase(void) const;
00261
00263 static unsigned long UTF8toUCS4(
00264 unsigned char const *&s, void const * const endptr );
00265
00268 static int UTF8toUCS4(
00269 unsigned long &w, unsigned char const s[], void const * const endptr )
00270 { unsigned char const *r=s;w=UTF8toUCS4(r,endptr);return (int)((size_t)r-(size_t)s); }
00271
00273 static int UTF16toUCS4(
00274 unsigned long &w, unsigned short const * const s,void const * const eptr);
00275
00276 static int UCS4toUTF16(
00277 unsigned long w, unsigned short &w1, unsigned short &w2);
00278
00279 int cmp(const char *s2, const int len=(-1)) const;
00280 static int cmp(
00281 const GP<GStringRep> &s1, const GP<GStringRep> &s2, const int len=(-1)) ;
00282 static int cmp(
00283 const GP<GStringRep> &s1, const char *s2, const int len=(-1));
00284 static int cmp(
00285 const char *s1, const GP<GStringRep> &s2, const int len=(-1));
00286 static int cmp(
00287 const char *s1, const char *s2, const int len=(-1));
00288
00289
00290 int getUCS4(unsigned long &w, const int from) const;
00291
00292 virtual unsigned char *UCS4toString(
00293 const unsigned long w, unsigned char *ptr, mbstate_t *ps=0) const = 0;
00294
00295 static unsigned char *UCS4toUTF8(
00296 const unsigned long w,unsigned char *ptr);
00297
00298 static unsigned char *UCS4toNative(
00299 const unsigned long w,unsigned char *ptr, mbstate_t *ps);
00300
00301 int search(char c, int from=0) const;
00302
00303 int search(char const *str, int from=0) const;
00304
00305 int rsearch(char c, int from=0) const;
00306
00307 int rsearch(char const *str, int from=0) const;
00308
00309 int contains(char const accept[], int from=0) const;
00310
00311 int rcontains(char const accept[], int from=0) const;
00312
00313 protected:
00314
00315 virtual unsigned long getValidUCS4(const char *&source) const = 0;
00316
00317 GP<GStringRep> tocase(
00318 bool (*xiswcase)(const unsigned long wc),
00319 unsigned long (*xtowcase)(const unsigned long wc)) const;
00320
00321
00322
00323
00324 const char * isCharType( bool (*xiswtest)(const unsigned long wc), const char *ptr,
00325 const bool reverse=false) const;
00326
00327
00328 int nextCharType(
00329 bool (*xiswtest)(const unsigned long wc),const int from,const int len,
00330 const bool reverse=false) const;
00331
00332 static bool giswspace(const unsigned long w);
00333 static bool giswupper(const unsigned long w);
00334 static bool giswlower(const unsigned long w);
00335 static unsigned long gtowupper(const unsigned long w);
00336 static unsigned long gtowlower(const unsigned long w);
00337
00338 virtual void set_remainder( void const * const buf, const unsigned int size,
00339 const EncodeType encodetype);
00340 virtual void set_remainder( void const * const buf, const unsigned int size,
00341 const GP<GStringRep> &encoding );
00342 virtual void set_remainder ( const GP<Unicode> &remainder );
00343
00344 virtual GP<Unicode> get_remainder( void ) const;
00345
00346 public:
00347
00348
00349
00350
00351 GP<GStringRep> toEscaped( const bool tosevenbit ) const;
00352
00353
00354 virtual bool is_valid(void) const = 0;
00355
00356 virtual int ncopy(wchar_t * const buf, const int buflen) const = 0;
00357
00358 protected:
00359
00360
00361 int size;
00362 char *data;
00363 };
00364
00365 class GStringRep::UTF8 : public GStringRep
00366 {
00367 public:
00368
00369 UTF8(void);
00370
00371 virtual ~UTF8();
00372
00373
00374 virtual GP<GStringRep> blank(const unsigned int sz = 0) const;
00375 virtual GP<GStringRep> append(const GP<GStringRep> &s2) const;
00376
00377 virtual bool isUTF8(void) const;
00378
00379 virtual GP<GStringRep> toNative(
00380 const EscapeMode escape=UNKNOWN_ESCAPED) const;
00381
00382 virtual GP<GStringRep> toUTF8(const bool nothrow=false) const;
00383
00384 virtual GP<GStringRep> toThis(
00385 const GP<GStringRep> &rep,const GP<GStringRep> &) const;
00386
00387 virtual int cmp(const GP<GStringRep> &s2,const int len=(-1)) const;
00388
00389 static GP<GStringRep> create(const unsigned int sz = 0);
00390
00391
00392 virtual int toInt(void) const;
00393 virtual long int toLong(
00394 const int pos, int &endpos, const int base=10) const;
00395 virtual unsigned long toULong(
00396 const int pos, int &endpos, const int base=10) const;
00397 virtual double toDouble(
00398 const int pos, int &endpos) const;
00399
00400
00401 static GP<GStringRep> create(const char *s);
00402
00403
00404 static GP<GStringRep> create(
00405 const GP<GStringRep> &s1,const GP<GStringRep> &s2);
00406 static GP<GStringRep> create( const GP<GStringRep> &s1,const char *s2);
00407 static GP<GStringRep> create( const char *s1, const GP<GStringRep> &s2);
00408 static GP<GStringRep> create( const char *s1,const char *s2);
00409
00410
00411 static GP<GStringRep> create(
00412 const char *s,const int start,const int length=(-1));
00413
00414 static GP<GStringRep> create(
00415 const unsigned short *s,const int start,const int length=(-1));
00416
00417 static GP<GStringRep> create(
00418 const unsigned long *s,const int start,const int length=(-1));
00419
00420 static GP<GStringRep> create_format(const char fmt[],...);
00421 static GP<GStringRep> create(const char fmt[],va_list& args);
00422
00423 virtual unsigned char *UCS4toString(
00424 const unsigned long w,unsigned char *ptr, mbstate_t *ps=0) const;
00425
00426
00427 virtual bool is_valid(void) const;
00428
00429 virtual int ncopy(wchar_t * const buf, const int buflen) const;
00430
00431 friend class GBaseString;
00432
00433 protected:
00434
00435 virtual unsigned long getValidUCS4(const char *&source) const;
00436 };
00437
00438 class GUTF8String;
00439 class GNativeString;
00440
00464 class GBaseString : protected GP<GStringRep>
00465 {
00466 public:
00467 enum EscapeMode {
00468 UNKNOWN_ESCAPED=GStringRep::UNKNOWN_ESCAPED,
00469 IS_ESCAPED=GStringRep::IS_ESCAPED,
00470 NOT_ESCAPED=GStringRep::NOT_ESCAPED };
00471
00472 friend class GUTF8String;
00473 friend class GNativeString;
00474 protected:
00475
00476 void init(void);
00477
00478 ~GBaseString();
00479 GBaseString &init(const GP<GStringRep> &rep);
00480
00481
00483 GBaseString( void );
00484
00485 public:
00486
00492 operator const char* ( void ) const ;
00494 unsigned int length( void ) const;
00505 bool operator! ( void ) const;
00506
00507
00513 char operator[] (int n) const;
00515 bool is_int(void) const;
00517 bool is_float(void) const;
00518
00520 GNativeString getUTF82Native( EscapeMode escape=UNKNOWN_ESCAPED ) const;
00521 GUTF8String getNative2UTF8( void ) const;
00522
00523
00525 void empty( void );
00526
00531 int search(char c, int from=0) const;
00532
00538 int search(const char *str, int from=0) const;
00539
00544 int rsearch(char c, const int from=0) const;
00550 int rsearch(const char *str, const int from=0) const;
00554 int contains(const char accept[], const int from=0) const;
00558 int rcontains(const char accept[], const int from=0) const;
00559
00562 GUTF8String operator+(const GUTF8String &s2) const;
00563 GNativeString operator+(const GNativeString &s2) const;
00564
00566 int toInt(void) const;
00567
00569 long toLong(const int pos, int &endpos, const int base=10) const;
00570
00572 unsigned long toULong(
00573 const int pos, int &endpos, const int base=10) const;
00574
00576 double toDouble(
00577 const int pos, int &endpos ) const;
00578
00580 static long toLong(
00581 const GUTF8String& src, const int pos, int &endpos, const int base=10);
00582
00583 static unsigned long toULong(
00584 const GUTF8String& src, const int pos, int &endpos, const int base=10);
00585
00586 static double toDouble(
00587 const GUTF8String& src, const int pos, int &endpos);
00588
00590 static long toLong(
00591 const GNativeString& src, const int pos, int &endpos, const int base=10);
00592
00593 static unsigned long toULong(
00594 const GNativeString& src, const int pos, int &endpos, const int base=10);
00595
00596 static double toDouble(
00597 const GNativeString& src, const int pos, int &endpos);
00598
00599
00600
00601
00604 int cmp(const GBaseString &s2, const int len=(-1)) const;
00607 int cmp(const char *s2, const int len=(-1)) const;
00610 int cmp(const char s2) const;
00613 static int cmp(const char *s1, const char *s2, const int len=(-1));
00621 bool operator==(const GBaseString &s2) const;
00622 bool operator==(const char *s2) const;
00623 friend bool operator==(const char *s1, const GBaseString &s2);
00624
00628 bool operator!=(const GBaseString &s2) const;
00629 bool operator!=(const char *s2) const;
00630 friend bool operator!=(const char *s1, const GBaseString &s2);
00631
00635 bool operator>=(const GBaseString &s2) const;
00636 bool operator>=(const char *s2) const;
00637 bool operator>=(const char s2) const;
00638 friend bool operator>=(const char *s1, const GBaseString &s2);
00639 friend bool operator>=(const char s1, const GBaseString &s2);
00640
00645 bool operator<(const GBaseString &s2) const;
00646 bool operator<(const char *s2) const;
00647 bool operator<(const char s2) const;
00648 friend bool operator<(const char *s1, const GBaseString &s2);
00649 friend bool operator<(const char s1, const GBaseString &s2);
00650
00655 bool operator> (const GBaseString &s2) const;
00656 bool operator> (const char *s2) const;
00657 bool operator> (const char s2) const;
00658 friend bool operator> (const char *s1, const GBaseString &s2);
00659 friend bool operator> (const char s1, const GBaseString &s2);
00660
00665 bool operator<=(const GBaseString &s2) const;
00666 bool operator<=(const char *s2) const;
00667 bool operator<=(const char s2) const;
00668 friend bool operator<=(const char *s1, const GBaseString &s2);
00669 friend bool operator<=(const char s1, const GBaseString &s2);
00670
00680 friend unsigned int hash(const GBaseString &ref);
00681
00682 friend class GStringRep;
00683
00685 int nextNonSpace( const int from=0, const int len=(-1) ) const;
00686
00688 int nextChar( const int from=0 ) const;
00689
00691 int nextSpace( const int from=0, const int len=(-1) ) const;
00692
00694 int firstEndSpace( const int from=0,const int len=(-1) ) const;
00695
00697 bool is_valid(void) const;
00698
00700 int ncopy(wchar_t * const buf, const int buflen) const;
00701
00702 protected:
00703 const char *gstr;
00704 static void throw_illegal_subscript() no_return;
00705 static const char *nullstr;
00706 public:
00707 GNativeString UTF8ToNative(
00708 const bool currentlocale=false,
00709 const EscapeMode escape=UNKNOWN_ESCAPED) const;
00710 GUTF8String NativeToUTF8(void) const;
00711 protected:
00712 int CheckSubscript(int n) const;
00713 };
00714
00736 class GUTF8String : public GBaseString
00737 {
00738 public:
00739 ~GUTF8String();
00740 void init(void);
00741
00742 GUTF8String &init(const GP<GStringRep> &rep);
00743
00744
00746 GUTF8String(void);
00748 GUTF8String(const char dat);
00750 GUTF8String(const char *str);
00752 GUTF8String(const unsigned char *str);
00753 GUTF8String(const unsigned short *dat);
00754 GUTF8String(const unsigned long *dat);
00759 GUTF8String(const char *dat, unsigned int len);
00760 GUTF8String(const unsigned short *dat, unsigned int len);
00761 GUTF8String(const unsigned long *dat, unsigned int len);
00762
00764 GUTF8String(const GP<GStringRep> &str);
00765 GUTF8String(const GBaseString &str);
00766 GUTF8String(const GUTF8String &str);
00767 GUTF8String(const GNativeString &str);
00772 GUTF8String(const GBaseString &gs, int from, int len);
00773
00777 GUTF8String& operator= (const char str);
00778 GUTF8String& operator= (const char *str);
00779 GUTF8String& operator= (const GP<GStringRep> &str);
00780 GUTF8String& operator= (const GBaseString &str);
00781 GUTF8String& operator= (const GUTF8String &str);
00782 GUTF8String& operator= (const GNativeString &str);
00783
00791 GUTF8String(const GUTF8String &fmt, va_list &args);
00792
00794
00797 GUTF8String(const int number);
00798
00802 GUTF8String(const double number);
00803
00804
00812 GUTF8String &format(const char *fmt, ... );
00820 GUTF8String &vformat(const GUTF8String &fmt, va_list &args);
00821
00826 GUTF8String toEscaped( const bool tosevenbit=false ) const;
00827
00832 GUTF8String fromEscaped( void ) const;
00833
00840 GUTF8String fromEscaped(
00841 const GMap<GUTF8String,GUTF8String> ConvMap ) const;
00842
00843
00844
00846 GUTF8String& operator+= (char ch);
00847
00849 GUTF8String& operator+= (const char *str);
00851 GUTF8String& operator+= (const GBaseString &str);
00852
00857 GUTF8String substr(int from, int len) const;
00858
00862 GUTF8String upcase( void ) const;
00866 GUTF8String downcase( void ) const;
00867
00871 GUTF8String operator+(const GBaseString &s2) const;
00872 GUTF8String operator+(const GUTF8String &s2) const;
00873 GUTF8String operator+(const GNativeString &s2) const;
00874 GUTF8String operator+(const char *s2) const;
00875 friend GUTF8String operator+(const char *s1, const GUTF8String &s2);
00876
00885 char *getbuf(int n = -1);
00894 void setat(const int n, const char ch);
00895 public:
00896 typedef enum GStringRep::EncodeType EncodeType;
00897 static GUTF8String create(void const * const buf,
00898 const unsigned int size,
00899 const EncodeType encodetype, const GUTF8String &encoding);
00900 static GUTF8String create( void const * const buf,
00901 unsigned int size, const EncodeType encodetype );
00902 static GUTF8String create( void const * const buf,
00903 const unsigned int size, const GUTF8String &encoding );
00904 static GUTF8String create( void const * const buf,
00905 const unsigned int size, const GP<GStringRep::Unicode> &remainder);
00906 GP<GStringRep::Unicode> get_remainder(void) const;
00907 static GUTF8String create( const char *buf, const unsigned int bufsize );
00908 static GUTF8String create( const unsigned short *buf, const unsigned int bufsize );
00909 static GUTF8String create( const unsigned long *buf, const unsigned int bufsize );
00910 };
00911
00912
00913 #if !HAS_WCHAR
00914 #define GBaseString GUTF8String
00915 #endif
00916
00938 class GNativeString : public GBaseString
00939 {
00940 public:
00941 ~GNativeString();
00942
00944 GNativeString(void);
00946 GNativeString(const char dat);
00948 GNativeString(const char *str);
00950 GNativeString(const unsigned char *str);
00951 GNativeString(const unsigned short *str);
00952 GNativeString(const unsigned long *str);
00957 GNativeString(const char *dat, unsigned int len);
00958 GNativeString(const unsigned short *dat, unsigned int len);
00959 GNativeString(const unsigned long *dat, unsigned int len);
00961 GNativeString(const GP<GStringRep> &str);
00962 GNativeString(const GBaseString &str);
00963 #if HAS_WCHAR
00964 GNativeString(const GUTF8String &str);
00965 #endif
00966 GNativeString(const GNativeString &str);
00971 GNativeString(const GBaseString &gs, int from, int len);
00972
00980 GNativeString(const GNativeString &fmt, va_list &args);
00981
00985 GNativeString(const int number);
00986
00990 GNativeString(const double number);
00991
00992 #if !HAS_WCHAR
00993 #undef GBaseString
00994 #else
00996 void init(void);
00997
00999 GNativeString &init(const GP<GStringRep> &rep);
01000
01004 GNativeString& operator= (const char str);
01005 GNativeString& operator= (const char *str);
01006 GNativeString& operator= (const GP<GStringRep> &str);
01007 GNativeString& operator= (const GBaseString &str);
01008 GNativeString& operator= (const GUTF8String &str);
01009 GNativeString& operator= (const GNativeString &str);
01010
01012 GNativeString& operator+= (char ch);
01014 GNativeString& operator+= (const char *str);
01016 GNativeString& operator+= (const GBaseString &str);
01017
01022 GNativeString substr(int from, int len) const;
01023
01027 GNativeString upcase( void ) const;
01031 GNativeString downcase( void ) const;
01032
01033
01034 GNativeString operator+(const GBaseString &s2) const;
01035 GNativeString operator+(const GNativeString &s2) const;
01036 GUTF8String operator+(const GUTF8String &s2) const;
01037 GNativeString operator+(const char *s2) const;
01038 friend GNativeString operator+(const char *s1, const GNativeString &s2);
01039
01047 GNativeString &format(const char *fmt, ... );
01055 GNativeString &vformat(const GNativeString &fmt, va_list &args);
01056
01061 GNativeString toEscaped( const bool tosevenbit=false ) const;
01062
01063
01073 char *getbuf(int n = -1);
01083 void setat(const int n, const char ch);
01084
01085 static GNativeString create( const char *buf, const unsigned int bufsize );
01086 static GNativeString create( const unsigned short *buf, const unsigned int bufsize );
01087 static GNativeString create( const unsigned long *buf, const unsigned int bufsize );
01088 #endif // WinCE
01089 };
01090
01092
01093 inline
01094 GBaseString::operator const char* ( void ) const
01095 {
01096 return ptr?(*this)->data:nullstr;
01097 }
01098
01099 inline unsigned int
01100 GBaseString::length( void ) const
01101 {
01102 return ptr ? (*this)->size : 0;
01103 }
01104
01105 inline bool
01106 GBaseString::operator! ( void ) const
01107 {
01108 return !ptr;
01109 }
01110
01111 inline GUTF8String
01112 GUTF8String::upcase( void ) const
01113 {
01114 if (ptr) return (*this)->upcase();
01115 return *this;
01116 }
01117
01118 inline GUTF8String
01119 GUTF8String::downcase( void ) const
01120 {
01121 if (ptr) return (*this)->downcase();
01122 return *this;
01123 }
01124
01125 inline void
01126 GUTF8String::init(void)
01127 { GBaseString::init(); }
01128
01129 inline GUTF8String &
01130 GUTF8String::init(const GP<GStringRep> &rep)
01131 { GP<GStringRep>::operator=(rep?rep->toUTF8(true):rep); init(); return *this; }
01132
01133 inline GUTF8String &
01134 GUTF8String::vformat(const GUTF8String &fmt, va_list &args)
01135 { return (*this = (fmt.ptr?GUTF8String(fmt,args):fmt)); }
01136
01137 inline GUTF8String
01138 GUTF8String::toEscaped( const bool tosevenbit ) const
01139 { return ptr?GUTF8String((*this)->toEscaped(tosevenbit)):(*this); }
01140
01141 inline GP<GStringRep::Unicode>
01142 GUTF8String::get_remainder(void) const
01143 {
01144 GP<GStringRep::Unicode> retval;
01145 if(ptr)
01146 retval=((*this)->get_remainder());
01147 return retval;
01148 }
01149
01150 inline
01151 GUTF8String::GUTF8String(const GNativeString &str)
01152 { init(str.length()?(str->toUTF8(true)):(GP<GStringRep>)str); }
01153
01154 inline
01155 GUTF8String::GUTF8String(const GP<GStringRep> &str)
01156 { init(str?(str->toUTF8(true)):str); }
01157
01158 inline
01159 GUTF8String::GUTF8String(const GBaseString &str)
01160 { init(str.length()?(str->toUTF8(true)):(GP<GStringRep>)str); }
01161
01162 inline void
01163 GBaseString::init(void)
01164 {
01165 gstr=ptr?((*this)->data):nullstr;
01166 }
01168 inline int
01169 GBaseString::toInt(void) const
01170 { return ptr?(*this)->toInt():0; }
01171
01173 inline long
01174 GBaseString::toLong(const int pos, int &endpos, const int base) const
01175 {
01176 long int retval=0;
01177 if(ptr)
01178 {
01179 retval=(*this)->toLong(pos, endpos, base);
01180 }else
01181 {
01182 endpos=(-1);
01183 }
01184 return retval;
01185 }
01186
01187 inline long
01188 GBaseString::toLong(
01189 const GUTF8String& src, const int pos, int &endpos, const int base)
01190 {
01191 return src.toLong(pos,endpos,base);
01192 }
01193
01194 inline long
01195 GBaseString::toLong(
01196 const GNativeString& src, const int pos, int &endpos, const int base)
01197 {
01198 return src.toLong(pos,endpos,base);
01199 }
01200
01202 inline unsigned long
01203 GBaseString::toULong(const int pos, int &endpos, const int base) const
01204 {
01205 unsigned long retval=0;
01206 if(ptr)
01207 {
01208 retval=(*this)->toULong(pos, endpos, base);
01209 }else
01210 {
01211 endpos=(-1);
01212 }
01213 return retval;
01214 }
01215
01216 inline unsigned long
01217 GBaseString::toULong(
01218 const GUTF8String& src, const int pos, int &endpos, const int base)
01219 {
01220 return src.toULong(pos,endpos,base);
01221 }
01222
01223 inline unsigned long
01224 GBaseString::toULong(
01225 const GNativeString& src, const int pos, int &endpos, const int base)
01226 {
01227 return src.toULong(pos,endpos,base);
01228 }
01229
01231 inline double
01232 GBaseString::toDouble(
01233 const int pos, int &endpos ) const
01234 {
01235 double retval=(double)0;
01236 if(ptr)
01237 {
01238 retval=(*this)->toDouble(pos, endpos);
01239 }else
01240 {
01241 endpos=(-1);
01242 }
01243 return retval;
01244 }
01245
01246 inline double
01247 GBaseString::toDouble(
01248 const GUTF8String& src, const int pos, int &endpos)
01249 {
01250 return src.toDouble(pos,endpos);
01251 }
01252
01253 inline double
01254 GBaseString::toDouble(
01255 const GNativeString& src, const int pos, int &endpos)
01256 {
01257 return src.toDouble(pos,endpos);
01258 }
01259
01260 inline GBaseString &
01261 GBaseString::init(const GP<GStringRep> &rep)
01262 { GP<GStringRep>::operator=(rep); init(); return *this;}
01263
01264 inline char
01265 GBaseString::operator[] (int n) const
01266 { return ((n||ptr)?((*this)->data[CheckSubscript(n)]):0); }
01267
01268 inline int
01269 GBaseString::search(char c, int from) const
01270 { return ptr?((*this)->search(c,from)):(-1); }
01271
01272 inline int
01273 GBaseString::search(const char *str, int from) const
01274 { return ptr?((*this)->search(str,from)):(-1); }
01275
01276 inline int
01277 GBaseString::rsearch(char c, const int from) const
01278 { return ptr?((*this)->rsearch(c,from)):(-1); }
01279
01280 inline int
01281 GBaseString::rsearch(const char *str, const int from) const
01282 { return ptr?((*this)->rsearch(str,from)):(-1); }
01283
01284 inline int
01285 GBaseString::contains(const char accept[], const int from) const
01286 { return ptr?((*this)->contains(accept,from)):(-1); }
01287
01288 inline int
01289 GBaseString::rcontains(const char accept[], const int from) const
01290 { return ptr?((*this)->rcontains(accept,from)):(-1); }
01291
01292 inline int
01293 GBaseString::cmp(const GBaseString &s2, const int len) const
01294 { return GStringRep::cmp(*this,s2,len); }
01295
01296 inline int
01297 GBaseString::cmp(const char *s2, const int len) const
01298 { return GStringRep::cmp(*this,s2,len); }
01299
01300 inline int
01301 GBaseString::cmp(const char s2) const
01302 { return GStringRep::cmp(*this,&s2,1); }
01303
01304 inline int
01305 GBaseString::cmp(const char *s1, const char *s2, const int len)
01306 { return GStringRep::cmp(s1,s2,len); }
01307
01308 inline bool
01309 GBaseString::operator==(const GBaseString &s2) const
01310 { return !cmp(s2); }
01311
01312 inline bool
01313 GBaseString::operator==(const char *s2) const
01314 { return !cmp(s2); }
01315
01316 inline bool
01317 GBaseString::operator!=(const GBaseString &s2) const
01318 { return !!cmp(s2); }
01319
01320 inline bool
01321 GBaseString::operator!=(const char *s2) const
01322 { return !!cmp(s2); }
01323
01324 inline bool
01325 GBaseString::operator>=(const GBaseString &s2) const
01326 { return (cmp(s2)>=0); }
01327
01328 inline bool
01329 GBaseString::operator>=(const char *s2) const
01330 { return (cmp(s2)>=0); }
01331
01332 inline bool
01333 GBaseString::operator>=(const char s2) const
01334 { return (cmp(s2)>=0); }
01335
01336 inline bool
01337 GBaseString::operator<(const GBaseString &s2) const
01338 { return (cmp(s2)<0); }
01339
01340 inline bool
01341 GBaseString::operator<(const char *s2) const
01342 { return (cmp(s2)<0); }
01343
01344 inline bool
01345 GBaseString::operator<(const char s2) const
01346 { return (cmp(s2)<0); }
01347
01348 inline bool
01349 GBaseString::operator> (const GBaseString &s2) const
01350 { return (cmp(s2)>0); }
01351
01352 inline bool
01353 GBaseString::operator> (const char *s2) const
01354 { return (cmp(s2)>0); }
01355
01356 inline bool
01357 GBaseString::operator> (const char s2) const
01358 { return (cmp(s2)>0); }
01359
01360 inline bool
01361 GBaseString::operator<=(const GBaseString &s2) const
01362 { return (cmp(s2)<=0); }
01363
01364 inline bool
01365 GBaseString::operator<=(const char *s2) const
01366 { return (cmp(s2)<=0); }
01367
01368 inline bool
01369 GBaseString::operator<=(const char s2) const
01370 { return (cmp(s2)<=0); }
01371
01372 inline int
01373 GBaseString::nextNonSpace( const int from, const int len ) const
01374 { return ptr?(*this)->nextNonSpace(from,len):0; }
01375
01376 inline int
01377 GBaseString::nextChar( const int from ) const
01378 { return ptr?(*this)->nextChar(from):0; }
01379
01380 inline int
01381 GBaseString::nextSpace( const int from, const int len ) const
01382 { return ptr?(*this)->nextSpace(from,len):0; }
01383
01384 inline int
01385 GBaseString::firstEndSpace( const int from,const int len ) const
01386 { return ptr?(*this)->firstEndSpace(from,len):0; }
01387
01388 inline bool
01389 GBaseString::is_valid(void) const
01390 { return ptr?((*this)->is_valid()):true; }
01391
01392 inline int
01393 GBaseString::ncopy(wchar_t * const buf, const int buflen) const
01394 {if(buf&&buflen)buf[0]=0;return ptr?((*this)->ncopy(buf,buflen)):0;}
01395
01396 inline int
01397 GBaseString::CheckSubscript(int n) const
01398 {
01399 if(n)
01400 {
01401 if (n<0 && ptr)
01402 n += (*this)->size;
01403 if (n<0 || !ptr || n > (int)(*this)->size)
01404 throw_illegal_subscript();
01405 }
01406 return n;
01407 }
01408
01409 inline GBaseString::GBaseString(void) { init(); }
01410
01411 inline GUTF8String::GUTF8String(void) { }
01412
01413 inline GUTF8String::GUTF8String(const GUTF8String &str) : GBaseString(str)
01414 { init(str); }
01415
01416 inline GUTF8String& GUTF8String::operator= (const GP<GStringRep> &str)
01417 { return init(str); }
01418
01419 inline GUTF8String& GUTF8String::operator= (const GBaseString &str)
01420 { return init(str); }
01421
01422 inline GUTF8String& GUTF8String::operator= (const GUTF8String &str)
01423 { return init(str); }
01424
01425 inline GUTF8String& GUTF8String::operator= (const GNativeString &str)
01426 { return init(str); }
01427
01428 inline GUTF8String
01429 GUTF8String::create( const char *buf, const unsigned int bufsize )
01430 {
01431 #if HAS_WCHAR
01432 return GNativeString(buf,bufsize);
01433 #else
01434 return GUTF8String(buf,bufsize);
01435 #endif
01436 }
01437
01438 inline GUTF8String
01439 GUTF8String::create( const unsigned short *buf, const unsigned int bufsize )
01440 {
01441 return GUTF8String(buf,bufsize);
01442 }
01443
01444 inline GUTF8String
01445 GUTF8String::create( const unsigned long *buf, const unsigned int bufsize )
01446 {
01447 return GUTF8String(buf,bufsize);
01448 }
01449
01450 inline GNativeString::GNativeString(void) {}
01451
01452 #if !HAS_WCHAR
01453
01454
01455 inline
01456 GNativeString::GNativeString(const GUTF8String &str)
01457 : GUTF8String(str) {}
01458
01459 inline
01460 GNativeString::GNativeString(const GP<GStringRep> &str)
01461 : GUTF8String(str) {}
01462
01463 inline
01464 GNativeString::GNativeString(const char dat)
01465 : GUTF8String(dat) {}
01466
01467 inline
01468 GNativeString::GNativeString(const char *str)
01469 : GUTF8String(str) {}
01470
01471 inline
01472 GNativeString::GNativeString(const unsigned char *str)
01473 : GUTF8String(str) {}
01474
01475 inline
01476 GNativeString::GNativeString(const unsigned short *str)
01477 : GUTF8String(str) {}
01478
01479 inline
01480 GNativeString::GNativeString(const unsigned long *str)
01481 : GUTF8String(str) {}
01482
01483 inline
01484 GNativeString::GNativeString(const char *dat, unsigned int len)
01485 : GUTF8String(dat,len) {}
01486
01487 inline
01488 GNativeString::GNativeString(const unsigned short *dat, unsigned int len)
01489 : GUTF8String(dat,len) {}
01490
01491 inline
01492 GNativeString::GNativeString(const unsigned long *dat, unsigned int len)
01493 : GUTF8String(dat,len) {}
01494
01495 inline
01496 GNativeString::GNativeString(const GNativeString &str)
01497 : GUTF8String(str) {}
01498
01499 inline
01500 GNativeString::GNativeString(const int number)
01501 : GUTF8String(number) {}
01502
01503 inline
01504 GNativeString::GNativeString(const double number)
01505 : GUTF8String(number) {}
01506
01507 inline
01508 GNativeString::GNativeString(const GNativeString &fmt, va_list &args)
01509 : GUTF8String(fmt,args) {}
01510
01511 #else // HAS_WCHAR
01512
01514 inline void
01515 GNativeString::init(void)
01516 { GBaseString::init(); }
01517
01519 inline GNativeString &
01520 GNativeString::init(const GP<GStringRep> &rep)
01521 {
01522 GP<GStringRep>::operator=(rep?rep->toNative(GStringRep::NOT_ESCAPED):rep);
01523 init();
01524 return *this;
01525 }
01526
01527 inline GNativeString
01528 GNativeString::substr(int from, int len) const
01529 { return GNativeString(*this, from, len); }
01530
01531 inline GNativeString &
01532 GNativeString::vformat(const GNativeString &fmt, va_list &args)
01533 { return (*this = (fmt.ptr?GNativeString(fmt,args):fmt)); }
01534
01535 inline GNativeString
01536 GNativeString::toEscaped( const bool tosevenbit ) const
01537 { return ptr?GNativeString((*this)->toEscaped(tosevenbit)):(*this); }
01538
01539 inline
01540 GNativeString::GNativeString(const GUTF8String &str)
01541 {
01542 if (str.length())
01543 init(str->toNative(GStringRep::NOT_ESCAPED));
01544 else
01545 init((GP<GStringRep>)str);
01546 }
01547
01548 inline
01549 GNativeString::GNativeString(const GP<GStringRep> &str)
01550 {
01551 if (str)
01552 init(str->toNative(GStringRep::NOT_ESCAPED));
01553 else
01554 init(str);
01555 }
01556
01557 inline
01558 GNativeString::GNativeString(const GBaseString &str)
01559 {
01560 if (str.length())
01561 init(str->toNative(GStringRep::NOT_ESCAPED));
01562 else
01563 init((GP<GStringRep>)str);
01564 }
01565
01566
01567 inline
01568 GNativeString::GNativeString(const GNativeString &fmt, va_list &args)
01569 {
01570 if (fmt.ptr)
01571 init(fmt->vformat(args));
01572 else
01573 init(fmt);
01574 }
01575
01576 inline GNativeString
01577 GNativeString::create( const char *buf, const unsigned int bufsize )
01578 {
01579 return GNativeString(buf,bufsize);
01580 }
01581
01582 inline GNativeString
01583 GNativeString::create( const unsigned short *buf, const unsigned int bufsize )
01584 {
01585 return GNativeString(buf,bufsize);
01586 }
01587
01588 inline GNativeString
01589 GNativeString::create( const unsigned long *buf, const unsigned int bufsize )
01590 {
01591 return GNativeString(buf,bufsize);
01592 }
01593
01594 inline GNativeString&
01595 GNativeString::operator= (const GP<GStringRep> &str)
01596 { return init(str); }
01597
01598 inline GNativeString&
01599 GNativeString::operator= (const GBaseString &str)
01600 { return init(str); }
01601
01602 inline GNativeString&
01603 GNativeString::operator= (const GUTF8String &str)
01604 { return init(str); }
01605
01606 inline GNativeString&
01607 GNativeString::operator= (const GNativeString &str)
01608 { return init(str); }
01609
01610 inline GNativeString
01611 GNativeString::upcase( void ) const
01612 {
01613 if (ptr) return (*this)->upcase();
01614 return *this;
01615 }
01616
01617 inline GNativeString
01618 GNativeString::downcase( void ) const
01619 {
01620 if (ptr) return (*this)->downcase();
01621 return *this;
01622 }
01623
01624 #endif // HAS_WCHAR
01625
01626 inline bool
01627 operator==(const char *s1, const GBaseString &s2)
01628 { return !s2.cmp(s1); }
01629
01630 inline bool
01631 operator!=(const char *s1, const GBaseString &s2)
01632 { return !!s2.cmp(s1); }
01633
01634 inline bool
01635 operator>=(const char *s1, const GBaseString &s2)
01636 { return (s2.cmp(s1)<=0); }
01637
01638 inline bool
01639 operator>=(const char s1, const GBaseString &s2)
01640 { return (s2.cmp(s1)<=0); }
01641
01642 inline bool
01643 operator<(const char *s1, const GBaseString &s2)
01644 { return (s2.cmp(s1)>0); }
01645
01646 inline bool
01647 operator<(const char s1, const GBaseString &s2)
01648 { return (s2.cmp(s1)>0); }
01649
01650 inline bool
01651 operator> (const char *s1, const GBaseString &s2)
01652 { return (s2.cmp(s1)<0); }
01653
01654 inline bool
01655 operator> (const char s1, const GBaseString &s2)
01656 { return (s2.cmp(s1)<0); }
01657
01658 inline bool
01659 operator<=(const char *s1, const GBaseString &s2)
01660 { return !(s1>s2); }
01661
01662 inline bool
01663 operator<=(const char s1, const GBaseString &s2)
01664 { return !(s1>s2); }
01665
01666
01667
01668
01669 #ifdef HAVE_NAMESPACES
01670 }
01671 # ifndef NOT_USING_DJVU_NAMESPACE
01672 using namespace DJVU;
01673 # endif
01674 #endif
01675 #endif
01676