|
Packit |
df99a1 |
//C- -*- C++ -*-
|
|
Packit |
df99a1 |
//C- -------------------------------------------------------------------
|
|
Packit |
df99a1 |
//C- DjVuLibre-3.5
|
|
Packit |
df99a1 |
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
|
|
Packit |
df99a1 |
//C- Copyright (c) 2001 AT&T
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- This software is subject to, and may be distributed under, the
|
|
Packit |
df99a1 |
//C- GNU General Public License, either Version 2 of the license,
|
|
Packit |
df99a1 |
//C- or (at your option) any later version. The license should have
|
|
Packit |
df99a1 |
//C- accompanied the software or you may obtain a copy of the license
|
|
Packit |
df99a1 |
//C- from the Free Software Foundation at http://www.fsf.org .
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- This program is distributed in the hope that it will be useful,
|
|
Packit |
df99a1 |
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
df99a1 |
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
df99a1 |
//C- GNU General Public License for more details.
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
|
|
Packit |
df99a1 |
//C- Lizardtech Software. Lizardtech Software has authorized us to
|
|
Packit |
df99a1 |
//C- replace the original DjVu(r) Reference Library notice by the following
|
|
Packit |
df99a1 |
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
|
|
Packit |
df99a1 |
//C-
|
|
Packit |
df99a1 |
//C- ------------------------------------------------------------------
|
|
Packit |
df99a1 |
//C- | DjVu (r) Reference Library (v. 3.5)
|
|
Packit |
df99a1 |
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
|
|
Packit |
df99a1 |
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
|
|
Packit |
df99a1 |
//C- | 6,058,214 and patents pending.
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | This software is subject to, and may be distributed under, the
|
|
Packit |
df99a1 |
//C- | GNU General Public License, either Version 2 of the license,
|
|
Packit |
df99a1 |
//C- | or (at your option) any later version. The license should have
|
|
Packit |
df99a1 |
//C- | accompanied the software or you may obtain a copy of the license
|
|
Packit |
df99a1 |
//C- | from the Free Software Foundation at http://www.fsf.org .
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | The computer code originally released by LizardTech under this
|
|
Packit |
df99a1 |
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
|
|
Packit |
df99a1 |
//C- | ORIGINAL CODE." Subject to any third party intellectual property
|
|
Packit |
df99a1 |
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
|
|
Packit |
df99a1 |
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
|
|
Packit |
df99a1 |
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
|
|
Packit |
df99a1 |
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
|
|
Packit |
df99a1 |
//C- | General Public License. This grant only confers the right to
|
|
Packit |
df99a1 |
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
|
|
Packit |
df99a1 |
//C- | the extent such infringement is reasonably necessary to enable
|
|
Packit |
df99a1 |
//C- | recipient to make, have made, practice, sell, or otherwise dispose
|
|
Packit |
df99a1 |
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
|
|
Packit |
df99a1 |
//C- | any greater extent that may be necessary to utilize further
|
|
Packit |
df99a1 |
//C- | modifications or combinations.
|
|
Packit |
df99a1 |
//C- |
|
|
Packit |
df99a1 |
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
|
|
Packit |
df99a1 |
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
Packit |
df99a1 |
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
|
|
Packit |
df99a1 |
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
df99a1 |
//C- +------------------------------------------------------------------
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifndef _GSTRING_H_
|
|
Packit |
df99a1 |
#define _GSTRING_H_
|
|
Packit |
df99a1 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
df99a1 |
#include "config.h"
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#if NEED_GNUG_PRAGMAS
|
|
Packit |
df99a1 |
# pragma interface
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** @name GString.h
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Files #"GString.h"# and #"GString.cpp"# implement a general
|
|
Packit |
df99a1 |
purpose string class \Ref{GBaseString}, with dirived types
|
|
Packit |
df99a1 |
\Ref{GUTF8String} and \Ref{GNativeString} for UTF8 MBS encoding
|
|
Packit |
df99a1 |
and the current Native MBS encoding respectively. This
|
|
Packit |
df99a1 |
implementation relies on smart pointers (see
|
|
Packit |
df99a1 |
\Ref{GSmartPointer.h}).
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
{\bf Historical Comments} --- At some point during the DjVu
|
|
Packit |
df99a1 |
research era, it became clear that C++ compilers rarely provided
|
|
Packit |
df99a1 |
portable libraries. We then decided to avoid fancy classes (like
|
|
Packit |
df99a1 |
#iostream# or #string#) and to rely only on the good old C
|
|
Packit |
df99a1 |
library. A good string class however is very useful. We had
|
|
Packit |
df99a1 |
already randomly picked letter 'G' to prefix class names and we
|
|
Packit |
df99a1 |
logically derived the new class name. Native English speakers
|
|
Packit |
df99a1 |
kept laughing in hiding. This is ironic because we completely
|
|
Packit |
df99a1 |
forgot this letter 'G' when creating more challenging things
|
|
Packit |
df99a1 |
like the ZP Coder or the IW44 wavelets.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
{\bf Later Changes}
|
|
Packit |
df99a1 |
When converting to I18N, we (Lizardtech) decided that two string classes
|
|
Packit |
df99a1 |
where needing, replacing the original GString with \Ref{GUTF8String} and
|
|
Packit |
df99a1 |
\Ref{GNativeString}.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
@memo
|
|
Packit |
df99a1 |
General purpose string class.
|
|
Packit |
df99a1 |
@author
|
|
Packit |
df99a1 |
L\'eon Bottou <leonb@research.att.com> -- initial implementation.\\
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// From: Leon Bottou, 1/31/2002
|
|
Packit |
df99a1 |
// This file has very little to do with my initial implementation.
|
|
Packit |
df99a1 |
// It has been practically rewritten by Lizardtech for i18n changes.
|
|
Packit |
df99a1 |
// My original implementation was very small in comparison
|
|
Packit |
df99a1 |
// <http://prdownloads.sourceforge.net/djvu/DjVu2_2b-src.tgz>.
|
|
Packit |
df99a1 |
// In my opinion, the duplication of the string classes is a failed
|
|
Packit |
df99a1 |
// attempt to use the type system to enforce coding policies.
|
|
Packit |
df99a1 |
// This could be fixed. But there are better things to do in djvulibre.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
//@{
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include "DjVuGlobal.h"
|
|
Packit |
df99a1 |
#include "GContainer.h"
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#include <stddef.h>
|
|
Packit |
df99a1 |
#include <stdlib.h>
|
|
Packit |
df99a1 |
#include <stdarg.h>
|
|
Packit |
df99a1 |
#ifdef _WIN32
|
|
Packit |
df99a1 |
# include <windows.h>
|
|
Packit |
df99a1 |
# ifndef AUTOCONF
|
|
Packit |
df99a1 |
# define HAS_WCHAR 1
|
|
Packit |
df99a1 |
# define HAS_WCTYPE 1
|
|
Packit |
df99a1 |
# define HAS_MBSTATE 1
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
# include <wchar.h>
|
|
Packit |
df99a1 |
#elif HAVE_WCHAR_H
|
|
Packit |
df99a1 |
# include <wchar.h>
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if HAVE_STDINT_H
|
|
Packit |
df99a1 |
# include <stdint.h>
|
|
Packit |
df99a1 |
#elif HAVE_INTTYPES_H
|
|
Packit |
df99a1 |
# include <inttypes.h>
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
# ifdef _WIN32
|
|
Packit |
df99a1 |
typedef unsigned __int32 uint32_t;
|
|
Packit |
df99a1 |
typedef unsigned __int16 uint16_t;
|
|
Packit |
df99a1 |
# else
|
|
Packit |
df99a1 |
# pragma message("Please verify defs for uint32_t and uint16_t")
|
|
Packit |
df99a1 |
typedef unsigned int uint32_t // verify
|
|
Packit |
df99a1 |
typedef unsigned short uint16_t // verify
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifdef HAVE_NAMESPACES
|
|
Packit |
df99a1 |
namespace DJVU {
|
|
Packit |
df99a1 |
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if !HAS_MBSTATE
|
|
Packit |
df99a1 |
# ifndef HAVE_MBSTATE_T
|
|
Packit |
df99a1 |
typedef int mbstate_t;
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class GBaseString;
|
|
Packit |
df99a1 |
class GUTF8String;
|
|
Packit |
df99a1 |
class GNativeString;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Internal string representation.
|
|
Packit |
df99a1 |
class DJVUAPI GStringRep : public GPEnabled
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
enum EncodeType { XUCS4, XUCS4BE, XUCS4LE, XUCS4_2143, XUCS4_3412,
|
|
Packit |
df99a1 |
XUTF16, XUTF16BE, XUTF16LE, XUTF8, XEBCDIC, XOTHER } ;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
enum EscapeMode { UNKNOWN_ESCAPED=0, IS_ESCAPED=1, NOT_ESCAPED=2 };
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class UTF8;
|
|
Packit |
df99a1 |
friend class UTF8;
|
|
Packit |
df99a1 |
class Unicode;
|
|
Packit |
df99a1 |
friend class Unicode;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class ChangeLocale;
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
class Native;
|
|
Packit |
df99a1 |
friend class Native;
|
|
Packit |
df99a1 |
#endif // HAS_WCHAR
|
|
Packit |
df99a1 |
friend class GBaseString;
|
|
Packit |
df99a1 |
friend class GUTF8String;
|
|
Packit |
df99a1 |
friend class GNativeString;
|
|
Packit |
df99a1 |
friend DJVUAPI unsigned int hash(const GBaseString &ref;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
// default constructor
|
|
Packit |
df99a1 |
GStringRep(void);
|
|
Packit |
df99a1 |
// virtual destructor
|
|
Packit |
df99a1 |
virtual ~GStringRep();
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Other virtual methods.
|
|
Packit |
df99a1 |
// Create an empty string.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> blank(const unsigned int sz) const = 0;
|
|
Packit |
df99a1 |
// Create a duplicate at the given size.
|
|
Packit |
df99a1 |
GP<GStringRep> getbuf(int n) const;
|
|
Packit |
df99a1 |
// Change the value of one of the bytes.
|
|
Packit |
df99a1 |
GP<GStringRep> setat(int n, char ch) const;
|
|
Packit |
df99a1 |
// Append a string.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> append(const GP<GStringRep> &s2) const = 0;
|
|
Packit |
df99a1 |
// Test if isUTF8.
|
|
Packit |
df99a1 |
virtual bool isUTF8(void) const { return false; }
|
|
Packit |
df99a1 |
// Test if Native.
|
|
Packit |
df99a1 |
virtual bool isNative(void) const { return false; }
|
|
Packit |
df99a1 |
// Convert to Native.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> toNative(
|
|
Packit |
df99a1 |
const EscapeMode escape=UNKNOWN_ESCAPED ) const = 0;
|
|
Packit |
df99a1 |
// Convert to UTF8.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> toUTF8(const bool nothrow=false) const = 0;
|
|
Packit |
df99a1 |
// Convert to same as current class.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> toThis(
|
|
Packit |
df99a1 |
const GP<GStringRep> &rep,const GP<GStringRep> &locale=0) const = 0;
|
|
Packit |
df99a1 |
// Compare with #s2#.
|
|
Packit |
df99a1 |
virtual int cmp(const GP<GStringRep> &s2,const int len=(-1)) const = 0;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Convert strings to numbers.
|
|
Packit |
df99a1 |
virtual int toInt(void) const = 0;
|
|
Packit |
df99a1 |
virtual long int toLong(
|
|
Packit |
df99a1 |
const int pos, int &endpos, const int base=10) const = 0;
|
|
Packit |
df99a1 |
virtual unsigned long toULong(
|
|
Packit |
df99a1 |
const int pos, int &endpos, const int base=10) const = 0;
|
|
Packit |
df99a1 |
virtual double toDouble(const int pos, int &endpos) const = 0;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// return the position of the next character
|
|
Packit |
df99a1 |
int nextChar( const int from=0 ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// return next non space position
|
|
Packit |
df99a1 |
int nextNonSpace( const int from=0, const int len=(-1) ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// return next white space position
|
|
Packit |
df99a1 |
int nextSpace( const int from=0, const int len=(-1) ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// return the position after the last non-whitespace character.
|
|
Packit |
df99a1 |
int firstEndSpace( int from=0, const int len=(-1) ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Create an empty string.
|
|
Packit |
df99a1 |
template <class TYPE> static GP<GStringRep> create(
|
|
Packit |
df99a1 |
const unsigned int sz,TYPE *);
|
|
Packit |
df99a1 |
// Creates with a strdup string.
|
|
Packit |
df99a1 |
GP<GStringRep> strdup(const char *s) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Creates by appending to the current string
|
|
Packit |
df99a1 |
GP<GStringRep> append(const char *s2) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Creates with a concat operation.
|
|
Packit |
df99a1 |
GP<GStringRep> concat(const GP<GStringRep> &s1,const GP<GStringRep> &s2) const;
|
|
Packit |
df99a1 |
GP<GStringRep> concat(const char *s1,const GP<GStringRep> &s2) const;
|
|
Packit |
df99a1 |
GP<GStringRep> concat(const GP<GStringRep> &s1,const char *s2) const;
|
|
Packit |
df99a1 |
GP<GStringRep> concat(const char *s1,const char *s2) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/* Creates with a strdup and substr. Negative values have strlen(s)+1
|
|
Packit |
df99a1 |
added to them.
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
GP<GStringRep> substr(
|
|
Packit |
df99a1 |
const char *s,const int start,const int length=(-1)) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
GP<GStringRep> substr(
|
|
Packit |
df99a1 |
const uint16_t *s,const int start,const int length=(-1)) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
GP<GStringRep> substr(
|
|
Packit |
df99a1 |
const uint32_t *s,const int start,const int length=(-1)) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Initializes a string with a formatted string (as in #vprintf#). The
|
|
Packit |
df99a1 |
string is re-initialized with the characters generated according to the
|
|
Packit |
df99a1 |
specified format #fmt# and using the optional arguments. See the ANSI-C
|
|
Packit |
df99a1 |
function #vprintf()# for more information. The current implementation
|
|
Packit |
df99a1 |
will cause a segmentation violation if the resulting string is longer
|
|
Packit |
df99a1 |
than 32768 characters. */
|
|
Packit |
df99a1 |
GP<GStringRep> vformat(va_list args) const;
|
|
Packit |
df99a1 |
// -- SEARCHING
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static GP<GStringRep> UTF8ToNative( const char *s,
|
|
Packit |
df99a1 |
const EscapeMode escape=UNKNOWN_ESCAPED );
|
|
Packit |
df99a1 |
static GP<GStringRep> NativeToUTF8( const char *s );
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Creates an uppercase version of the current string.
|
|
Packit |
df99a1 |
GP<GStringRep> upcase(void) const;
|
|
Packit |
df99a1 |
// Creates a lowercase version of the current string.
|
|
Packit |
df99a1 |
GP<GStringRep> downcase(void) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns the next UCS4 character, and updates the pointer s. */
|
|
Packit |
df99a1 |
static uint32_t UTF8toUCS4(
|
|
Packit |
df99a1 |
unsigned char const *&s, void const * const endptr );
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns the number of bytes in next UCS4 character,
|
|
Packit |
df99a1 |
and sets #w# to the next UCS4 chacter. */
|
|
Packit |
df99a1 |
static int UTF8toUCS4(
|
|
Packit |
df99a1 |
uint32_t &w, unsigned char const s[], void const * const endptr )
|
|
Packit |
df99a1 |
{ unsigned char const *r=s;w=UTF8toUCS4(r,endptr);return (int)((size_t)r-(size_t)s); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns the next UCS4 word from the UTF16 string. */
|
|
Packit |
df99a1 |
static int UTF16toUCS4(
|
|
Packit |
df99a1 |
uint32_t &w, uint16_t const * const s,void const * const eptr);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static int UCS4toUTF16(
|
|
Packit |
df99a1 |
uint32_t w, uint16_t &w1, uint16_t &w2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int cmp(const char *s2, const int len=(-1)) const;
|
|
Packit |
df99a1 |
static int cmp(
|
|
Packit |
df99a1 |
const GP<GStringRep> &s1, const GP<GStringRep> &s2, const int len=(-1)) ;
|
|
Packit |
df99a1 |
static int cmp(
|
|
Packit |
df99a1 |
const GP<GStringRep> &s1, const char *s2, const int len=(-1));
|
|
Packit |
df99a1 |
static int cmp(
|
|
Packit |
df99a1 |
const char *s1, const GP<GStringRep> &s2, const int len=(-1));
|
|
Packit |
df99a1 |
static int cmp(
|
|
Packit |
df99a1 |
const char *s1, const char *s2, const int len=(-1));
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Lookup the next character, and return the position of the next character.
|
|
Packit |
df99a1 |
int getUCS4(uint32_t &w, const int from) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
virtual unsigned char *UCS4toString(
|
|
Packit |
df99a1 |
const uint32_t w, unsigned char *ptr, mbstate_t *ps=0) const = 0;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static unsigned char *UCS4toUTF8(
|
|
Packit |
df99a1 |
const uint32_t w,unsigned char *ptr);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static unsigned char *UCS4toNative(
|
|
Packit |
df99a1 |
const uint32_t w,unsigned char *ptr, mbstate_t *ps);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int search(char c, int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int search(char const *str, int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int rsearch(char c, int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int rsearch(char const *str, int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int contains(char const accept[], int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
int rcontains(char const accept[], int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
// Return the next character and increment the source pointer.
|
|
Packit |
df99a1 |
virtual uint32_t getValidUCS4(const char *&source) const = 0;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
GP<GStringRep> tocase(
|
|
Packit |
df99a1 |
bool (*xiswcase)(const unsigned long wc),
|
|
Packit |
df99a1 |
unsigned long (*xtowcase)(const unsigned long wc)) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Tests if the specified character passes the xiswtest. If so, the
|
|
Packit |
df99a1 |
// return pointer is incremented to the next character, otherwise the
|
|
Packit |
df99a1 |
// specified #ptr# is returned.
|
|
Packit |
df99a1 |
const char * isCharType( bool (*xiswtest)(const unsigned long wc), const char *ptr,
|
|
Packit |
df99a1 |
const bool reverse=false) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Find the next character position that passes the isCharType test.
|
|
Packit |
df99a1 |
int nextCharType(
|
|
Packit |
df99a1 |
bool (*xiswtest)(const unsigned long wc),const int from,const int len,
|
|
Packit |
df99a1 |
const bool reverse=false) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static bool giswspace(const unsigned long w);
|
|
Packit |
df99a1 |
static bool giswupper(const unsigned long w);
|
|
Packit |
df99a1 |
static bool giswlower(const unsigned long w);
|
|
Packit |
df99a1 |
static unsigned long gtowupper(const unsigned long w);
|
|
Packit |
df99a1 |
static unsigned long gtowlower(const unsigned long w);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
virtual void set_remainder( void const * const buf, const unsigned int size,
|
|
Packit |
df99a1 |
const EncodeType encodetype);
|
|
Packit |
df99a1 |
virtual void set_remainder( void const * const buf, const unsigned int size,
|
|
Packit |
df99a1 |
const GP<GStringRep> &encoding );
|
|
Packit |
df99a1 |
virtual void set_remainder ( const GP<Unicode> &remainder );
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
virtual GP<Unicode> get_remainder( void ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
/* Returns a copy of this string with characters used in XML with
|
|
Packit |
df99a1 |
'<' to "<", '>' to ">", '&' to "&" '\'' to
|
|
Packit |
df99a1 |
"'", and '\"' to """. Characters 0x01 through
|
|
Packit |
df99a1 |
0x1f are also escaped. */
|
|
Packit |
df99a1 |
GP<GStringRep> toEscaped( const bool tosevenbit ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Tests if a string is legally encoded in the current character set.
|
|
Packit |
df99a1 |
virtual bool is_valid(void) const = 0;
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
virtual int ncopy(wchar_t * const buf, const int buflen) const = 0;
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Actual string data.
|
|
Packit |
df99a1 |
int size;
|
|
Packit |
df99a1 |
char *data;
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DJVUAPI GStringRep::UTF8 : public GStringRep
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
// default constructor
|
|
Packit |
df99a1 |
UTF8(void);
|
|
Packit |
df99a1 |
// virtual destructor
|
|
Packit |
df99a1 |
virtual ~UTF8();
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Other virtual methods.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> blank(const unsigned int sz = 0) const;
|
|
Packit |
df99a1 |
virtual GP<GStringRep> append(const GP<GStringRep> &s2) const;
|
|
Packit |
df99a1 |
// Test if Native.
|
|
Packit |
df99a1 |
virtual bool isUTF8(void) const;
|
|
Packit |
df99a1 |
// Convert to Native.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> toNative(
|
|
Packit |
df99a1 |
const EscapeMode escape=UNKNOWN_ESCAPED) const;
|
|
Packit |
df99a1 |
// Convert to UTF8.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> toUTF8(const bool nothrow=false) const;
|
|
Packit |
df99a1 |
// Convert to same as current class.
|
|
Packit |
df99a1 |
virtual GP<GStringRep> toThis(
|
|
Packit |
df99a1 |
const GP<GStringRep> &rep,const GP<GStringRep> &) const;
|
|
Packit |
df99a1 |
// Compare with #s2#.
|
|
Packit |
df99a1 |
virtual int cmp(const GP<GStringRep> &s2,const int len=(-1)) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static GP<GStringRep> create(const unsigned int sz = 0);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Convert strings to numbers.
|
|
Packit |
df99a1 |
virtual int toInt(void) const;
|
|
Packit |
df99a1 |
virtual long int toLong(
|
|
Packit |
df99a1 |
const int pos, int &endpos, const int base=10) const;
|
|
Packit |
df99a1 |
virtual unsigned long toULong(
|
|
Packit |
df99a1 |
const int pos, int &endpos, const int base=10) const;
|
|
Packit |
df99a1 |
virtual double toDouble(
|
|
Packit |
df99a1 |
const int pos, int &endpos) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Create a strdup string.
|
|
Packit |
df99a1 |
static GP<GStringRep> create(const char *s);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Creates with a concat operation.
|
|
Packit |
df99a1 |
static GP<GStringRep> create(
|
|
Packit |
df99a1 |
const GP<GStringRep> &s1,const GP<GStringRep> &s2;;
|
|
Packit |
df99a1 |
static GP<GStringRep> create( const GP<GStringRep> &s1,const char *s2);
|
|
Packit |
df99a1 |
static GP<GStringRep> create( const char *s1, const GP<GStringRep> &s2;;
|
|
Packit |
df99a1 |
static GP<GStringRep> create( const char *s1,const char *s2);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Create with a strdup and substr operation.
|
|
Packit |
df99a1 |
static GP<GStringRep> create(
|
|
Packit |
df99a1 |
const char *s,const int start,const int length=(-1));
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static GP<GStringRep> create(
|
|
Packit |
df99a1 |
const uint16_t *s,const int start,const int length=(-1));
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static GP<GStringRep> create(
|
|
Packit |
df99a1 |
const uint32_t *s,const int start,const int length=(-1));
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static GP<GStringRep> create_format(const char fmt[],...);
|
|
Packit |
df99a1 |
static GP<GStringRep> create(const char fmt[],va_list& args);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
virtual unsigned char *UCS4toString(
|
|
Packit |
df99a1 |
const uint32_t w,unsigned char *ptr, mbstate_t *ps=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// Tests if a string is legally encoded in the current character set.
|
|
Packit |
df99a1 |
virtual bool is_valid(void) const;
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
virtual int ncopy(wchar_t * const buf, const int buflen) const;
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
friend class GBaseString;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
// Return the next character and increment the source pointer.
|
|
Packit |
df99a1 |
virtual uint32_t getValidUCS4(const char *&source) const;
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** General purpose character string.
|
|
Packit |
df99a1 |
Each dirivied instance of class #GBaseString# represents a
|
|
Packit |
df99a1 |
character string. Overloaded operators provide a value semantic
|
|
Packit |
df99a1 |
to #GBaseString# objects. Conversion operators and constructors
|
|
Packit |
df99a1 |
transparently convert between #GBaseString# objects and
|
|
Packit |
df99a1 |
#const char*# pointers. The #GBaseString# class has no public
|
|
Packit |
df99a1 |
constructors, since a dirived type should always be used
|
|
Packit |
df99a1 |
to specify the desired multibyte character encoding.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Functions taking strings as arguments should declare their
|
|
Packit |
df99a1 |
arguments as "#const char*#". Such functions will work equally
|
|
Packit |
df99a1 |
well with dirived #GBaseString# objects since there is a fast
|
|
Packit |
df99a1 |
conversion operator from the dirivied #GBaseString# objects
|
|
Packit |
df99a1 |
to "#const char*#". Functions returning strings should return
|
|
Packit |
df99a1 |
#GUTF8String# or #GNativeString# objects because the class will
|
|
Packit |
df99a1 |
automatically manage the necessary memory.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Characters in the string can be identified by their position. The
|
|
Packit |
df99a1 |
first character of a string is numbered zero. Negative positions
|
|
Packit |
df99a1 |
represent characters relative to the end of the string (i.e.
|
|
Packit |
df99a1 |
position #-1# accesses the last character of the string,
|
|
Packit |
df99a1 |
position #-2# represents the second last character, etc.) */
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DJVUAPI GBaseString : protected GP<GStringRep>
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
enum EscapeMode {
|
|
Packit |
df99a1 |
UNKNOWN_ESCAPED=GStringRep::UNKNOWN_ESCAPED,
|
|
Packit |
df99a1 |
IS_ESCAPED=GStringRep::IS_ESCAPED,
|
|
Packit |
df99a1 |
NOT_ESCAPED=GStringRep::NOT_ESCAPED };
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
friend class GUTF8String;
|
|
Packit |
df99a1 |
friend class GNativeString;
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
// Sets the gstr pointer;
|
|
Packit |
df99a1 |
inline void init(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
~GBaseString();
|
|
Packit |
df99a1 |
inline GBaseString &init(const GP<GStringRep> &rep;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- CONSTRUCTORS
|
|
Packit |
df99a1 |
/** Null constructor. Constructs an empty string. */
|
|
Packit |
df99a1 |
GBaseString( void );
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
// -- ACCESS
|
|
Packit |
df99a1 |
/** Converts a string into a constant null terminated character
|
|
Packit |
df99a1 |
array. This conversion operator is very efficient because
|
|
Packit |
df99a1 |
it simply returns a pointer to the internal string data. The
|
|
Packit |
df99a1 |
returned pointer remains valid as long as the string is
|
|
Packit |
df99a1 |
unmodified. */
|
|
Packit |
df99a1 |
operator const char* ( void ) const ;
|
|
Packit |
df99a1 |
/// Returns the string length.
|
|
Packit |
df99a1 |
unsigned int length( void ) const;
|
|
Packit |
df99a1 |
/** Returns true if and only if the string contains zero characters.
|
|
Packit |
df99a1 |
This operator is useful for conditional expression in control
|
|
Packit |
df99a1 |
structures.
|
|
Packit |
df99a1 |
\begin{verbatim}
|
|
Packit |
df99a1 |
if (! str) { ... }
|
|
Packit |
df99a1 |
while (!! str) { ... } -- Note the double operator!
|
|
Packit |
df99a1 |
\end{verbatim}
|
|
Packit |
df99a1 |
Class #GBaseString# does not to support syntax
|
|
Packit |
df99a1 |
"#if# #(str)# #{}#" because the required conversion operator
|
|
Packit |
df99a1 |
introduces dangerous ambiguities with certain compilers. */
|
|
Packit |
df99a1 |
bool operator! ( void ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- INDEXING
|
|
Packit |
df99a1 |
/** Returns the character at position #n#. An exception
|
|
Packit |
df99a1 |
\Ref{GException} is thrown if number #n# is not in range #-len#
|
|
Packit |
df99a1 |
to #len-1#, where #len# is the length of the string. The first
|
|
Packit |
df99a1 |
character of a string is numbered zero. Negative positions
|
|
Packit |
df99a1 |
represent characters relative to the end of the string. */
|
|
Packit |
df99a1 |
char operator[] (int n) const;
|
|
Packit |
df99a1 |
/// Returns #TRUE# if the string contains an integer number.
|
|
Packit |
df99a1 |
bool is_int(void) const;
|
|
Packit |
df99a1 |
/// Returns #TRUE# if the string contains a float number.
|
|
Packit |
df99a1 |
bool is_float(void) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Converts strings between native & UTF8 **/
|
|
Packit |
df99a1 |
GNativeString getUTF82Native( EscapeMode escape=UNKNOWN_ESCAPED ) const;
|
|
Packit |
df99a1 |
GUTF8String getNative2UTF8( void ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- ALTERING
|
|
Packit |
df99a1 |
/// Reinitializes a string with the null string.
|
|
Packit |
df99a1 |
void empty( void );
|
|
Packit |
df99a1 |
// -- SEARCHING
|
|
Packit |
df99a1 |
/** Searches character #c# in the string, starting at position
|
|
Packit |
df99a1 |
#from# and scanning forward until reaching the end of the
|
|
Packit |
df99a1 |
string. This function returns the position of the matching
|
|
Packit |
df99a1 |
character. It returns #-1# if character #c# cannot be found. */
|
|
Packit |
df99a1 |
int search(char c, int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Searches sub-string #str# in the string, starting at position
|
|
Packit |
df99a1 |
#from# and scanning forward until reaching the end of the
|
|
Packit |
df99a1 |
string. This function returns the position of the first
|
|
Packit |
df99a1 |
matching character of the sub-string. It returns #-1# if
|
|
Packit |
df99a1 |
string #str# cannot be found. */
|
|
Packit |
df99a1 |
int search(const char *str, int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Searches character #c# in the string, starting at position
|
|
Packit |
df99a1 |
#from# and scanning backwards until reaching the beginning of
|
|
Packit |
df99a1 |
the string. This function returns the position of the matching
|
|
Packit |
df99a1 |
character. It returns #-1# if character #c# cannot be found. */
|
|
Packit |
df99a1 |
int rsearch(char c, const int from=0) const;
|
|
Packit |
df99a1 |
/** Searches sub-string #str# in the string, starting at position
|
|
Packit |
df99a1 |
#from# and scanning backwards until reaching the beginning of
|
|
Packit |
df99a1 |
the string. This function returns the position of the first
|
|
Packit |
df99a1 |
matching character of the sub-string. It returns #-1# if
|
|
Packit |
df99a1 |
string #str# cannot be found. */
|
|
Packit |
df99a1 |
int rsearch(const char *str, const int from=0) const;
|
|
Packit |
df99a1 |
/** Searches for any of the specified characters in the accept
|
|
Packit |
df99a1 |
string. It returns #-1# if the none of the characters and
|
|
Packit |
df99a1 |
be found, otherwise the position of the first match. */
|
|
Packit |
df99a1 |
int contains(const char accept[], const int from=0) const;
|
|
Packit |
df99a1 |
/** Searches for any of the specified characters in the accept
|
|
Packit |
df99a1 |
string. It returns #-1# if the none of the characters and be
|
|
Packit |
df99a1 |
found, otherwise the position of the last match. */
|
|
Packit |
df99a1 |
int rcontains(const char accept[], const int from=0) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Concatenates strings. Returns a string composed by concatenating
|
|
Packit |
df99a1 |
the characters of strings #s1# and #s2#. */
|
|
Packit |
df99a1 |
GUTF8String operator+(const GUTF8String &s2) const;
|
|
Packit |
df99a1 |
GNativeString operator+(const GNativeString &s2) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns an integer. Implements i18n atoi. */
|
|
Packit |
df99a1 |
int toInt(void) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a long intenger. Implments i18n strtol. */
|
|
Packit |
df99a1 |
long toLong(const int pos, int &endpos, const int base=10) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a unsigned long integer. Implements i18n strtoul. */
|
|
Packit |
df99a1 |
unsigned long toULong(
|
|
Packit |
df99a1 |
const int pos, int &endpos, const int base=10) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a double. Implements the i18n strtod. */
|
|
Packit |
df99a1 |
double toDouble(
|
|
Packit |
df99a1 |
const int pos, int &endpos ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a long intenger. Implments i18n strtol. */
|
|
Packit |
df99a1 |
static long toLong(
|
|
Packit |
df99a1 |
const GUTF8String& src, const int pos, int &endpos, const int base=10);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static unsigned long toULong(
|
|
Packit |
df99a1 |
const GUTF8String& src, const int pos, int &endpos, const int base=10);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static double toDouble(
|
|
Packit |
df99a1 |
const GUTF8String& src, const int pos, int &endpos);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a long intenger. Implments i18n strtol. */
|
|
Packit |
df99a1 |
static long toLong(
|
|
Packit |
df99a1 |
const GNativeString& src, const int pos, int &endpos, const int base=10);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static unsigned long toULong(
|
|
Packit |
df99a1 |
const GNativeString& src, const int pos, int &endpos, const int base=10);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static double toDouble(
|
|
Packit |
df99a1 |
const GNativeString& src, const int pos, int &endpos);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- HASHING
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- COMPARISONS
|
|
Packit |
df99a1 |
/** Returns an #int#. Compares string with #s2# and returns
|
|
Packit |
df99a1 |
sorting order. */
|
|
Packit |
df99a1 |
int cmp(const GBaseString &s2, const int len=(-1)) const;
|
|
Packit |
df99a1 |
/** Returns an #int#. Compares string with #s2# and returns
|
|
Packit |
df99a1 |
sorting order. */
|
|
Packit |
df99a1 |
int cmp(const char *s2, const int len=(-1)) const;
|
|
Packit |
df99a1 |
/** Returns an #int#. Compares string with #s2# and returns
|
|
Packit |
df99a1 |
sorting order. */
|
|
Packit |
df99a1 |
int cmp(const char s2) const;
|
|
Packit |
df99a1 |
/** Returns an #int#. Compares #s2# with #s2# and returns
|
|
Packit |
df99a1 |
sorting order. */
|
|
Packit |
df99a1 |
static int cmp(const char *s1, const char *s2, const int len=(-1));
|
|
Packit |
df99a1 |
/** Returns a boolean. The Standard C strncmp takes two string and
|
|
Packit |
df99a1 |
compares the first N characters. static bool GBaseString::ncmp
|
|
Packit |
df99a1 |
will compare #s1# with #s2# with the #len# characters starting
|
|
Packit |
df99a1 |
from the beginning of the string. */
|
|
Packit |
df99a1 |
/** String comparison. Returns true if and only if character
|
|
Packit |
df99a1 |
strings #s1# and #s2# are equal (as with #strcmp#.)
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
bool operator==(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
bool operator==(const char *s2) const;
|
|
Packit |
df99a1 |
friend bool operator==(const char *s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** String comparison. Returns true if and only if character
|
|
Packit |
df99a1 |
strings #s1# and #s2# are not equal (as with #strcmp#.)
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
bool operator!=(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
bool operator!=(const char *s2) const;
|
|
Packit |
df99a1 |
friend bool operator!=(const char *s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** String comparison. Returns true if and only if character
|
|
Packit |
df99a1 |
strings #s1# is lexicographically greater than or equal to
|
|
Packit |
df99a1 |
string #s2# (as with #strcmp#.) */
|
|
Packit |
df99a1 |
bool operator>=(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
bool operator>=(const char *s2) const;
|
|
Packit |
df99a1 |
bool operator>=(const char s2) const;
|
|
Packit |
df99a1 |
friend bool operator>=(const char *s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
friend bool operator>=(const char s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** String comparison. Returns true if and only if character
|
|
Packit |
df99a1 |
strings #s1# is lexicographically less than string #s2#
|
|
Packit |
df99a1 |
(as with #strcmp#.)
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
bool operator<(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
bool operator<(const char *s2) const;
|
|
Packit |
df99a1 |
bool operator<(const char s2) const;
|
|
Packit |
df99a1 |
friend bool operator<(const char *s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
friend bool operator<(const char s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** String comparison. Returns true if and only if character
|
|
Packit |
df99a1 |
strings #s1# is lexicographically greater than string #s2#
|
|
Packit |
df99a1 |
(as with #strcmp#.)
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
bool operator> (const GBaseString &s2) const;
|
|
Packit |
df99a1 |
bool operator> (const char *s2) const;
|
|
Packit |
df99a1 |
bool operator> (const char s2) const;
|
|
Packit |
df99a1 |
friend bool operator> (const char *s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
friend bool operator> (const char s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** String comparison. Returns true if and only if character
|
|
Packit |
df99a1 |
strings #s1# is lexicographically less than or equal to string
|
|
Packit |
df99a1 |
#s2# (as with #strcmp#.)
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
bool operator<=(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
bool operator<=(const char *s2) const;
|
|
Packit |
df99a1 |
bool operator<=(const char s2) const;
|
|
Packit |
df99a1 |
friend bool operator<=(const char *s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
friend bool operator<=(const char s1, const GBaseString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns an integer. Implements a functional i18n atoi. Note
|
|
Packit |
df99a1 |
that if you pass a GBaseString that is not in Native format
|
|
Packit |
df99a1 |
the results may be disparaging. */
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a hash code for the string. This hashing function
|
|
Packit |
df99a1 |
helps when creating associative maps with string keys (see
|
|
Packit |
df99a1 |
\Ref{GMap}). This hash code may be reduced to an arbitrary
|
|
Packit |
df99a1 |
range by computing its remainder modulo the upper bound of
|
|
Packit |
df99a1 |
the range. */
|
|
Packit |
df99a1 |
friend DJVUAPI unsigned int hash(const GBaseString &ref;;
|
|
Packit |
df99a1 |
// -- HELPERS
|
|
Packit |
df99a1 |
friend class GStringRep;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Returns next non space position.
|
|
Packit |
df99a1 |
int nextNonSpace( const int from=0, const int len=(-1) ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Returns next character position.
|
|
Packit |
df99a1 |
int nextChar( const int from=0 ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Returns next non space position.
|
|
Packit |
df99a1 |
int nextSpace( const int from=0, const int len=(-1) ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// return the position after the last non-whitespace character.
|
|
Packit |
df99a1 |
int firstEndSpace( const int from=0,const int len=(-1) ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Tests if the string is legally encoded in the current codepage.
|
|
Packit |
df99a1 |
bool is_valid(void) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// copy to a wchar_t buffer
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
int ncopy(wchar_t * const buf, const int buflen) const;
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
const char *gstr;
|
|
Packit |
df99a1 |
static void throw_illegal_subscript() no_return;
|
|
Packit |
df99a1 |
static const char *nullstr;
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
GNativeString UTF8ToNative(
|
|
Packit |
df99a1 |
const bool currentlocale=false,
|
|
Packit |
df99a1 |
const EscapeMode escape=UNKNOWN_ESCAPED) const;
|
|
Packit |
df99a1 |
GUTF8String NativeToUTF8(void) const;
|
|
Packit |
df99a1 |
protected:
|
|
Packit |
df99a1 |
inline int CheckSubscript(int n) const;
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** General purpose character string.
|
|
Packit |
df99a1 |
Each instance of class #GUTF8String# represents a character
|
|
Packit |
df99a1 |
string. Overloaded operators provide a value semantic to
|
|
Packit |
df99a1 |
#GUTF8String# objects. Conversion operators and constructors
|
|
Packit |
df99a1 |
transparently convert between #GUTF8String# objects and
|
|
Packit |
df99a1 |
#const char*# pointers.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Functions taking strings as arguments should declare their
|
|
Packit |
df99a1 |
arguments as "#const char*#". Such functions will work equally
|
|
Packit |
df99a1 |
well with #GUTF8String# objects since there is a fast conversion
|
|
Packit |
df99a1 |
operator from #GUTF8String# to "#const char*#". Functions
|
|
Packit |
df99a1 |
returning strings should return #GUTF8String# or #GNativeString#
|
|
Packit |
df99a1 |
objects because the class will automatically manage the necessary
|
|
Packit |
df99a1 |
memory.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Characters in the string can be identified by their position. The
|
|
Packit |
df99a1 |
first character of a string is numbered zero. Negative positions
|
|
Packit |
df99a1 |
represent characters relative to the end of the string (i.e.
|
|
Packit |
df99a1 |
position #-1# accesses the last character of the string,
|
|
Packit |
df99a1 |
position #-2# represents the second last character, etc.) */
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DJVUAPI GUTF8String : public GBaseString
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
~GUTF8String();
|
|
Packit |
df99a1 |
inline void init(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String &init(const GP<GStringRep> &rep;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- CONSTRUCTORS
|
|
Packit |
df99a1 |
/** Null constructor. Constructs an empty string. */
|
|
Packit |
df99a1 |
GUTF8String(void);
|
|
Packit |
df99a1 |
/// Constructs a string from a character.
|
|
Packit |
df99a1 |
GUTF8String(const char dat);
|
|
Packit |
df99a1 |
/// Constructs a string from a null terminated character array.
|
|
Packit |
df99a1 |
GUTF8String(const char *str);
|
|
Packit |
df99a1 |
/// Constructs a string from a null terminated character array.
|
|
Packit |
df99a1 |
GUTF8String(const unsigned char *str);
|
|
Packit |
df99a1 |
GUTF8String(const uint16_t *dat);
|
|
Packit |
df99a1 |
GUTF8String(const uint32_t *dat);
|
|
Packit |
df99a1 |
/** Constructs a string from a character array. Elements of the
|
|
Packit |
df99a1 |
character array #dat# are added into the string until the
|
|
Packit |
df99a1 |
string length reaches #len# or until encountering a null
|
|
Packit |
df99a1 |
character (whichever comes first). */
|
|
Packit |
df99a1 |
GUTF8String(const char *dat, unsigned int len);
|
|
Packit |
df99a1 |
GUTF8String(const uint16_t *dat, unsigned int len);
|
|
Packit |
df99a1 |
GUTF8String(const uint32_t *dat, unsigned int len);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Construct from base class.
|
|
Packit |
df99a1 |
GUTF8String(const GP<GStringRep> &str);
|
|
Packit |
df99a1 |
GUTF8String(const GBaseString &str);
|
|
Packit |
df99a1 |
GUTF8String(const GUTF8String &str);
|
|
Packit |
df99a1 |
GUTF8String(const GNativeString &str);
|
|
Packit |
df99a1 |
/** Constructs a string from a character array. Elements of the
|
|
Packit |
df99a1 |
character array #dat# are added into the string until the
|
|
Packit |
df99a1 |
string length reaches #len# or until encountering a null
|
|
Packit |
df99a1 |
character (whichever comes first). */
|
|
Packit |
df99a1 |
GUTF8String(const GBaseString &gs, int from, int len);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Copy a null terminated character array. Resets this string
|
|
Packit |
df99a1 |
with the character string contained in the null terminated
|
|
Packit |
df99a1 |
character array #str#. */
|
|
Packit |
df99a1 |
GUTF8String& operator= (const char str);
|
|
Packit |
df99a1 |
GUTF8String& operator= (const char *str);
|
|
Packit |
df99a1 |
inline GUTF8String& operator= (const GP<GStringRep> &str);
|
|
Packit |
df99a1 |
inline GUTF8String& operator= (const GBaseString &str);
|
|
Packit |
df99a1 |
inline GUTF8String& operator= (const GUTF8String &str);
|
|
Packit |
df99a1 |
inline GUTF8String& operator= (const GNativeString &str);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Constructs a string with a formatted string (as in #vprintf#).
|
|
Packit |
df99a1 |
The string is re-initialized with the characters generated
|
|
Packit |
df99a1 |
according to the specified format #fmt# and using the optional
|
|
Packit |
df99a1 |
arguments. See the ANSI-C function #vprintf()# for more
|
|
Packit |
df99a1 |
information. The current implementation will cause a
|
|
Packit |
df99a1 |
segmentation violation if the resulting string is longer
|
|
Packit |
df99a1 |
than 32768 characters. */
|
|
Packit |
df99a1 |
GUTF8String(const GUTF8String &fmt, va_list &args);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Constructs a string from a character.
|
|
Packit |
df99a1 |
/** Constructs a string with a human-readable representation of
|
|
Packit |
df99a1 |
integer #number#. The format is similar to format #"%d"# in
|
|
Packit |
df99a1 |
function #printf#. */
|
|
Packit |
df99a1 |
GUTF8String(const int number);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Constructs a string with a human-readable representation of
|
|
Packit |
df99a1 |
floating point number #number#. The format is similar to
|
|
Packit |
df99a1 |
format #"%f"# in function #printf#. */
|
|
Packit |
df99a1 |
GUTF8String(const double number);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Initializes a string with a formatted string (as in #printf#).
|
|
Packit |
df99a1 |
The string is re-initialized with the characters generated
|
|
Packit |
df99a1 |
according to the specified format #fmt# and using the optional
|
|
Packit |
df99a1 |
arguments. See the ANSI-C function #printf()# for more
|
|
Packit |
df99a1 |
information. The current implementation will cause a
|
|
Packit |
df99a1 |
segmentation violation if the resulting string is longer
|
|
Packit |
df99a1 |
than 32768 characters. */
|
|
Packit |
df99a1 |
GUTF8String &format(const char *fmt, ... );
|
|
Packit |
df99a1 |
/** Initializes a string with a formatted string (as in #vprintf#).
|
|
Packit |
df99a1 |
The string is re-initialized with the characters generated
|
|
Packit |
df99a1 |
according to the specified format #fmt# and using the optional
|
|
Packit |
df99a1 |
arguments. See the ANSI-C function #vprintf()# for more
|
|
Packit |
df99a1 |
information. The current implementation will cause a
|
|
Packit |
df99a1 |
segmentation violation if the resulting string is longer
|
|
Packit |
df99a1 |
than 32768 characters. */
|
|
Packit |
df99a1 |
GUTF8String &vformat(const GUTF8String &fmt, va_list &args);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a copy of this string with characters used in XML with
|
|
Packit |
df99a1 |
'<' to "<", '>' to ">", '&' to "&" '\'' to
|
|
Packit |
df99a1 |
"'", and '\"' to """. Characters 0x01 through
|
|
Packit |
df99a1 |
0x1f are also escaped. */
|
|
Packit |
df99a1 |
GUTF8String toEscaped( const bool tosevenbit=false ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Converts strings containing HTML/XML escaped characters into
|
|
Packit |
df99a1 |
their unescaped forms. Numeric representations of characters
|
|
Packit |
df99a1 |
(e.g., "&" or "&" for "*") are the only forms
|
|
Packit |
df99a1 |
converted by this function. */
|
|
Packit |
df99a1 |
GUTF8String fromEscaped( void ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Converts strings containing HTML/XML escaped characters
|
|
Packit |
df99a1 |
(e.g., "<" for "<") into their unescaped forms. The
|
|
Packit |
df99a1 |
conversion is partially defined by the ConvMap argument which
|
|
Packit |
df99a1 |
specifies the conversion strings to be recognized. Numeric
|
|
Packit |
df99a1 |
representations of characters (e.g., "&" or "&"
|
|
Packit |
df99a1 |
for "*") are always converted. */
|
|
Packit |
df99a1 |
GUTF8String fromEscaped(
|
|
Packit |
df99a1 |
const GMap<GUTF8String,GUTF8String> ConvMap ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// -- CONCATENATION
|
|
Packit |
df99a1 |
/// Appends character #ch# to the string.
|
|
Packit |
df99a1 |
GUTF8String& operator+= (char ch);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Appends the null terminated character array #str# to the string.
|
|
Packit |
df99a1 |
GUTF8String& operator+= (const char *str);
|
|
Packit |
df99a1 |
/// Appends the specified GBaseString to the string.
|
|
Packit |
df99a1 |
GUTF8String& operator+= (const GBaseString &str);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a sub-string. The sub-string is composed by copying
|
|
Packit |
df99a1 |
#len# characters starting at position #from# in this string.
|
|
Packit |
df99a1 |
The length of the resulting string may be smaller than #len#
|
|
Packit |
df99a1 |
if the specified range is too large. */
|
|
Packit |
df99a1 |
GUTF8String substr(int from, int len/*=(-1)*/) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns an upper case copy of this string. The returned string
|
|
Packit |
df99a1 |
contains a copy of the current string with all letters turned
|
|
Packit |
df99a1 |
into upper case letters. */
|
|
Packit |
df99a1 |
GUTF8String upcase( void ) const;
|
|
Packit |
df99a1 |
/** Returns an lower case copy of this string. The returned string
|
|
Packit |
df99a1 |
contains a copy of the current string with all letters turned
|
|
Packit |
df99a1 |
into lower case letters. */
|
|
Packit |
df99a1 |
GUTF8String downcase( void ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Concatenates strings. Returns a string composed by concatenating
|
|
Packit |
df99a1 |
the characters of strings #s1# and #s2#.
|
|
Packit |
df99a1 |
*/
|
|
Packit |
df99a1 |
GUTF8String operator+(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
GUTF8String operator+(const GUTF8String &s2) const;
|
|
Packit |
df99a1 |
GUTF8String operator+(const GNativeString &s2) const;
|
|
Packit |
df99a1 |
GUTF8String operator+(const char *s2) const;
|
|
Packit |
df99a1 |
friend DJVUAPI GUTF8String operator+(const char *s1, const GUTF8String &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Provides a direct access to the string buffer. Returns a
|
|
Packit |
df99a1 |
pointer for directly accessing the string buffer. This pointer
|
|
Packit |
df99a1 |
valid remains valid as long as the string is not modified by
|
|
Packit |
df99a1 |
other means. Positive values for argument #n# represent the
|
|
Packit |
df99a1 |
length of the returned buffer. The returned string buffer will
|
|
Packit |
df99a1 |
be large enough to hold at least #n# characters plus a null
|
|
Packit |
df99a1 |
character. If #n# is positive but smaller than the string
|
|
Packit |
df99a1 |
length, the string will be truncated to #n# characters. */
|
|
Packit |
df99a1 |
char *getbuf(int n = -1);
|
|
Packit |
df99a1 |
/** Set the character at position #n# to value #ch#. An exception
|
|
Packit |
df99a1 |
\Ref{GException} is thrown if number #n# is not in range #-len#
|
|
Packit |
df99a1 |
to #len#, where #len# is the length of the string. If character
|
|
Packit |
df99a1 |
#ch# is zero, the string is truncated at position #n#. The
|
|
Packit |
df99a1 |
first character of a string is numbered zero. Negative
|
|
Packit |
df99a1 |
positions represent characters relative to the end of the
|
|
Packit |
df99a1 |
string. If position #n# is equal to the length of the string,
|
|
Packit |
df99a1 |
this function appends character #ch# to the end of the string. */
|
|
Packit |
df99a1 |
void setat(const int n, const char ch);
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
typedef enum GStringRep::EncodeType EncodeType;
|
|
Packit |
df99a1 |
static GUTF8String create(void const * const buf,
|
|
Packit |
df99a1 |
const unsigned int size,
|
|
Packit |
df99a1 |
const EncodeType encodetype, const GUTF8String &encoding);
|
|
Packit |
df99a1 |
static GUTF8String create( void const * const buf,
|
|
Packit |
df99a1 |
unsigned int size, const EncodeType encodetype );
|
|
Packit |
df99a1 |
static GUTF8String create( void const * const buf,
|
|
Packit |
df99a1 |
const unsigned int size, const GUTF8String &encoding );
|
|
Packit |
df99a1 |
static GUTF8String create( void const * const buf,
|
|
Packit |
df99a1 |
const unsigned int size, const GP<GStringRep::Unicode> &remainder);
|
|
Packit |
df99a1 |
GP<GStringRep::Unicode> get_remainder(void) const;
|
|
Packit |
df99a1 |
static GUTF8String create( const char *buf, const unsigned int bufsize );
|
|
Packit |
df99a1 |
static GUTF8String create( const uint16_t *buf, const unsigned int bufsize );
|
|
Packit |
df99a1 |
static GUTF8String create( const uint32_t *buf, const unsigned int bufsize );
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if !HAS_WCHAR
|
|
Packit |
df99a1 |
#define GBaseString GUTF8String
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** General purpose character string.
|
|
Packit |
df99a1 |
Each instance of class #GNativeString# represents a character
|
|
Packit |
df99a1 |
string. Overloaded operators provide a value semantic to
|
|
Packit |
df99a1 |
#GNativeString# objects. Conversion operators and constructors
|
|
Packit |
df99a1 |
transparently convert between #GNativeString# objects and
|
|
Packit |
df99a1 |
#const char*# pointers.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Functions taking strings as arguments should declare their
|
|
Packit |
df99a1 |
arguments as "#const char*#". Such functions will work equally
|
|
Packit |
df99a1 |
well with #GNativeString# objects since there is a fast conversion
|
|
Packit |
df99a1 |
operator from #GNativeString# to "#const char*#". Functions
|
|
Packit |
df99a1 |
returning strings should return #GUTF8String# or #GNativeString#
|
|
Packit |
df99a1 |
objects because the class will automatically manage the necessary
|
|
Packit |
df99a1 |
memory.
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
Characters in the string can be identified by their position. The
|
|
Packit |
df99a1 |
first character of a string is numbered zero. Negative positions
|
|
Packit |
df99a1 |
represent characters relative to the end of the string (i.e.
|
|
Packit |
df99a1 |
position #-1# accesses the last character of the string,
|
|
Packit |
df99a1 |
position #-2# represents the second last character, etc.) */
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
class DJVUAPI GNativeString : public GBaseString
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
public:
|
|
Packit |
df99a1 |
~GNativeString();
|
|
Packit |
df99a1 |
// -- CONSTRUCTORS
|
|
Packit |
df99a1 |
/** Null constructor. Constructs an empty string. */
|
|
Packit |
df99a1 |
GNativeString(void);
|
|
Packit |
df99a1 |
/// Constructs a string from a character.
|
|
Packit |
df99a1 |
GNativeString(const char dat);
|
|
Packit |
df99a1 |
/// Constructs a string from a null terminated character array.
|
|
Packit |
df99a1 |
GNativeString(const char *str);
|
|
Packit |
df99a1 |
/// Constructs a string from a null terminated character array.
|
|
Packit |
df99a1 |
GNativeString(const unsigned char *str);
|
|
Packit |
df99a1 |
GNativeString(const uint16_t *str);
|
|
Packit |
df99a1 |
GNativeString(const uint32_t *str);
|
|
Packit |
df99a1 |
/** Constructs a string from a character array. Elements of the
|
|
Packit |
df99a1 |
character array #dat# are added into the string until the
|
|
Packit |
df99a1 |
string length reaches #len# or until encountering a null
|
|
Packit |
df99a1 |
character (whichever comes first). */
|
|
Packit |
df99a1 |
GNativeString(const char *dat, unsigned int len);
|
|
Packit |
df99a1 |
GNativeString(const uint16_t *dat, unsigned int len);
|
|
Packit |
df99a1 |
GNativeString(const uint32_t *dat, unsigned int len);
|
|
Packit |
df99a1 |
/// Construct from base class.
|
|
Packit |
df99a1 |
GNativeString(const GP<GStringRep> &str);
|
|
Packit |
df99a1 |
GNativeString(const GBaseString &str);
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
GNativeString(const GUTF8String &str);
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
GNativeString(const GNativeString &str);
|
|
Packit |
df99a1 |
/** Constructs a string from a character array. Elements of the
|
|
Packit |
df99a1 |
character array #dat# are added into the string until the
|
|
Packit |
df99a1 |
string length reaches #len# or until encountering a null
|
|
Packit |
df99a1 |
character (whichever comes first). */
|
|
Packit |
df99a1 |
GNativeString(const GBaseString &gs, int from, int len);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Constructs a string with a formatted string (as in #vprintf#).
|
|
Packit |
df99a1 |
The string is re-initialized with the characters generated
|
|
Packit |
df99a1 |
according to the specified format #fmt# and using the optional
|
|
Packit |
df99a1 |
arguments. See the ANSI-C function #vprintf()# for more
|
|
Packit |
df99a1 |
information. The current implementation will cause a
|
|
Packit |
df99a1 |
segmentation violation if the resulting string is longer than
|
|
Packit |
df99a1 |
32768 characters. */
|
|
Packit |
df99a1 |
GNativeString(const GNativeString &fmt, va_list &args);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Constructs a string with a human-readable representation of
|
|
Packit |
df99a1 |
integer #number#. The format is similar to format #"%d"# in
|
|
Packit |
df99a1 |
function #printf#. */
|
|
Packit |
df99a1 |
GNativeString(const int number);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Constructs a string with a human-readable representation of
|
|
Packit |
df99a1 |
floating point number #number#. The format is similar to
|
|
Packit |
df99a1 |
format #"%f"# in function #printf#. */
|
|
Packit |
df99a1 |
GNativeString(const double number);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if !HAS_WCHAR
|
|
Packit |
df99a1 |
#undef GBaseString
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
/// Initialize this string class
|
|
Packit |
df99a1 |
void init(void);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Initialize this string class
|
|
Packit |
df99a1 |
GNativeString &init(const GP<GStringRep> &rep;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Copy a null terminated character array. Resets this string with
|
|
Packit |
df99a1 |
the character string contained in the null terminated character
|
|
Packit |
df99a1 |
array #str#. */
|
|
Packit |
df99a1 |
GNativeString& operator= (const char str);
|
|
Packit |
df99a1 |
GNativeString& operator= (const char *str);
|
|
Packit |
df99a1 |
inline GNativeString& operator= (const GP<GStringRep> &str);
|
|
Packit |
df99a1 |
inline GNativeString& operator= (const GBaseString &str);
|
|
Packit |
df99a1 |
inline GNativeString& operator= (const GUTF8String &str);
|
|
Packit |
df99a1 |
inline GNativeString& operator= (const GNativeString &str);
|
|
Packit |
df99a1 |
// -- CONCATENATION
|
|
Packit |
df99a1 |
/// Appends character #ch# to the string.
|
|
Packit |
df99a1 |
GNativeString& operator+= (char ch);
|
|
Packit |
df99a1 |
/// Appends the null terminated character array #str# to the string.
|
|
Packit |
df99a1 |
GNativeString& operator+= (const char *str);
|
|
Packit |
df99a1 |
/// Appends the specified GBaseString to the string.
|
|
Packit |
df99a1 |
GNativeString& operator+= (const GBaseString &str);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a sub-string. The sub-string is composed by copying
|
|
Packit |
df99a1 |
#len# characters starting at position #from# in this string.
|
|
Packit |
df99a1 |
The length of the resulting string may be smaller than #len#
|
|
Packit |
df99a1 |
if the specified range is too large. */
|
|
Packit |
df99a1 |
GNativeString substr(int from, int len/*=(-1)*/) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns an upper case copy of this string. The returned
|
|
Packit |
df99a1 |
string contains a copy of the current string with all letters
|
|
Packit |
df99a1 |
turned into upper case letters. */
|
|
Packit |
df99a1 |
GNativeString upcase( void ) const;
|
|
Packit |
df99a1 |
/** Returns an lower case copy of this string. The returned
|
|
Packit |
df99a1 |
string contains a copy of the current string with all letters
|
|
Packit |
df99a1 |
turned into lower case letters. */
|
|
Packit |
df99a1 |
GNativeString downcase( void ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
GNativeString operator+(const GBaseString &s2) const;
|
|
Packit |
df99a1 |
GNativeString operator+(const GNativeString &s2) const;
|
|
Packit |
df99a1 |
GUTF8String operator+(const GUTF8String &s2) const;
|
|
Packit |
df99a1 |
GNativeString operator+(const char *s2) const;
|
|
Packit |
df99a1 |
friend DJVUAPI GNativeString operator+(const char *s1, const GNativeString &s2;;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Initializes a string with a formatted string (as in #printf#).
|
|
Packit |
df99a1 |
The string is re-initialized with the characters generated
|
|
Packit |
df99a1 |
according to the specified format #fmt# and using the optional
|
|
Packit |
df99a1 |
arguments. See the ANSI-C function #printf()# for more
|
|
Packit |
df99a1 |
information. The current implementation will cause a
|
|
Packit |
df99a1 |
segmentation violation if the resulting string is longer than
|
|
Packit |
df99a1 |
32768 characters. */
|
|
Packit |
df99a1 |
GNativeString &format(const char *fmt, ... );
|
|
Packit |
df99a1 |
/** Initializes a string with a formatted string (as in #vprintf#).
|
|
Packit |
df99a1 |
The string is re-initialized with the characters generated
|
|
Packit |
df99a1 |
according to the specified format #fmt# and using the optional
|
|
Packit |
df99a1 |
arguments. See the ANSI-C function #vprintf()# for more
|
|
Packit |
df99a1 |
information. The current implementation will cause a
|
|
Packit |
df99a1 |
segmentation violation if the resulting string is longer than
|
|
Packit |
df99a1 |
32768 characters. */
|
|
Packit |
df99a1 |
GNativeString &vformat(const GNativeString &fmt, va_list &args);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a copy of this string with characters used in XML with
|
|
Packit |
df99a1 |
'<' to "<", '>' to ">", '&' to "&" '\'' to
|
|
Packit |
df99a1 |
"'", and '\"' to """. Characters 0x01 through
|
|
Packit |
df99a1 |
0x1f are also escaped. */
|
|
Packit |
df99a1 |
GNativeString toEscaped( const bool tosevenbit=false ) const;
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Provides a direct access to the string buffer. Returns a
|
|
Packit |
df99a1 |
pointer for directly accessing the string buffer. This
|
|
Packit |
df99a1 |
pointer valid remains valid as long as the string is not
|
|
Packit |
df99a1 |
modified by other means. Positive values for argument #n#
|
|
Packit |
df99a1 |
represent the length of the returned buffer. The returned
|
|
Packit |
df99a1 |
string buffer will be large enough to hold at least #n#
|
|
Packit |
df99a1 |
characters plus a null character. If #n# is positive but
|
|
Packit |
df99a1 |
smaller than the string length, the string will be truncated
|
|
Packit |
df99a1 |
to #n# characters. */
|
|
Packit |
df99a1 |
char *getbuf(int n = -1);
|
|
Packit |
df99a1 |
/** Set the character at position #n# to value #ch#. An exception
|
|
Packit |
df99a1 |
\Ref{GException} is thrown if number #n# is not in range #-len#
|
|
Packit |
df99a1 |
to #len#, where #len# is the length of the string. If
|
|
Packit |
df99a1 |
character #ch# is zero, the string is truncated at position
|
|
Packit |
df99a1 |
#n#. The first character of a string is numbered zero.
|
|
Packit |
df99a1 |
Negative positions represent characters relative to the end of
|
|
Packit |
df99a1 |
the string. If position #n# is equal to the length of the
|
|
Packit |
df99a1 |
string, this function appends character #ch# to the end of the
|
|
Packit |
df99a1 |
string. */
|
|
Packit |
df99a1 |
void setat(const int n, const char ch);
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
static GNativeString create( const char *buf, const unsigned int bufsize );
|
|
Packit |
df99a1 |
static GNativeString create( const uint16_t *buf, const unsigned int bufsize );
|
|
Packit |
df99a1 |
static GNativeString create( const uint32_t *buf, const unsigned int bufsize );
|
|
Packit |
df99a1 |
#endif // WinCE
|
|
Packit |
df99a1 |
};
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
//@}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GBaseString::operator const char* ( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return ptr?(*this)->data:nullstr;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline unsigned int
|
|
Packit |
df99a1 |
GBaseString::length( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return ptr ? (*this)->size : 0;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator! ( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return !ptr;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String
|
|
Packit |
df99a1 |
GUTF8String::upcase( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (ptr) return (*this)->upcase();
|
|
Packit |
df99a1 |
return *this;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String
|
|
Packit |
df99a1 |
GUTF8String::downcase( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (ptr) return (*this)->downcase();
|
|
Packit |
df99a1 |
return *this;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline void
|
|
Packit |
df99a1 |
GUTF8String::init(void)
|
|
Packit |
df99a1 |
{ GBaseString::init(); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String &
|
|
Packit |
df99a1 |
GUTF8String::init(const GP<GStringRep> &rep)
|
|
Packit |
df99a1 |
{ GP<GStringRep>::operator=(rep?rep->toUTF8(true):rep); init(); return *this; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String &
|
|
Packit |
df99a1 |
GUTF8String::vformat(const GUTF8String &fmt, va_list &args)
|
|
Packit |
df99a1 |
{ return (*this = (fmt.ptr?GUTF8String(fmt,args):fmt)); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String
|
|
Packit |
df99a1 |
GUTF8String::toEscaped( const bool tosevenbit ) const
|
|
Packit |
df99a1 |
{ return ptr?GUTF8String((*this)->toEscaped(tosevenbit)):(*this); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GP<GStringRep::Unicode>
|
|
Packit |
df99a1 |
GUTF8String::get_remainder(void) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
GP<GStringRep::Unicode> retval;
|
|
Packit |
df99a1 |
if(ptr)
|
|
Packit |
df99a1 |
retval=((*this)->get_remainder());
|
|
Packit |
df99a1 |
return retval;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GUTF8String::GUTF8String(const GNativeString &str)
|
|
Packit |
df99a1 |
{ init(str.length()?(str->toUTF8(true)):(GP<GStringRep>)str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GUTF8String::GUTF8String(const GP<GStringRep> &str)
|
|
Packit |
df99a1 |
{ init(str?(str->toUTF8(true)):str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GUTF8String::GUTF8String(const GBaseString &str)
|
|
Packit |
df99a1 |
{ init(str.length()?(str->toUTF8(true)):(GP<GStringRep>)str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline void
|
|
Packit |
df99a1 |
GBaseString::init(void)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
gstr=ptr?((*this)->data):nullstr;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
/** Returns an integer. Implements i18n atoi. */
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::toInt(void) const
|
|
Packit |
df99a1 |
{ return ptr?(*this)->toInt():0; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a long intenger. Implments i18n strtol. */
|
|
Packit |
df99a1 |
inline long
|
|
Packit |
df99a1 |
GBaseString::toLong(const int pos, int &endpos, const int base) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
long int retval=0;
|
|
Packit |
df99a1 |
if(ptr)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
retval=(*this)->toLong(pos, endpos, base);
|
|
Packit |
df99a1 |
}else
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
endpos=(-1);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
return retval;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline long
|
|
Packit |
df99a1 |
GBaseString::toLong(
|
|
Packit |
df99a1 |
const GUTF8String& src, const int pos, int &endpos, const int base)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return src.toLong(pos,endpos,base);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline long
|
|
Packit |
df99a1 |
GBaseString::toLong(
|
|
Packit |
df99a1 |
const GNativeString& src, const int pos, int &endpos, const int base)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return src.toLong(pos,endpos,base);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a unsigned long integer. Implements i18n strtoul. */
|
|
Packit |
df99a1 |
inline unsigned long
|
|
Packit |
df99a1 |
GBaseString::toULong(const int pos, int &endpos, const int base) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
unsigned long retval=0;
|
|
Packit |
df99a1 |
if(ptr)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
retval=(*this)->toULong(pos, endpos, base);
|
|
Packit |
df99a1 |
}else
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
endpos=(-1);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
return retval;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline unsigned long
|
|
Packit |
df99a1 |
GBaseString::toULong(
|
|
Packit |
df99a1 |
const GUTF8String& src, const int pos, int &endpos, const int base)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return src.toULong(pos,endpos,base);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline unsigned long
|
|
Packit |
df99a1 |
GBaseString::toULong(
|
|
Packit |
df99a1 |
const GNativeString& src, const int pos, int &endpos, const int base)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return src.toULong(pos,endpos,base);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/** Returns a double. Implements the i18n strtod. */
|
|
Packit |
df99a1 |
inline double
|
|
Packit |
df99a1 |
GBaseString::toDouble(
|
|
Packit |
df99a1 |
const int pos, int &endpos ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
double retval=(double)0;
|
|
Packit |
df99a1 |
if(ptr)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
retval=(*this)->toDouble(pos, endpos);
|
|
Packit |
df99a1 |
}else
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
endpos=(-1);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
return retval;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline double
|
|
Packit |
df99a1 |
GBaseString::toDouble(
|
|
Packit |
df99a1 |
const GUTF8String& src, const int pos, int &endpos)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return src.toDouble(pos,endpos);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline double
|
|
Packit |
df99a1 |
GBaseString::toDouble(
|
|
Packit |
df99a1 |
const GNativeString& src, const int pos, int &endpos)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return src.toDouble(pos,endpos);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GBaseString &
|
|
Packit |
df99a1 |
GBaseString::init(const GP<GStringRep> &rep)
|
|
Packit |
df99a1 |
{ GP<GStringRep>::operator=(rep); init(); return *this;}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline char
|
|
Packit |
df99a1 |
GBaseString::operator[] (int n) const
|
|
Packit |
df99a1 |
{ return ((n||ptr)?((*this)->data[CheckSubscript(n)]):0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::search(char c, int from) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->search(c,from)):(-1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::search(const char *str, int from) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->search(str,from)):(-1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::rsearch(char c, const int from) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->rsearch(c,from)):(-1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::rsearch(const char *str, const int from) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->rsearch(str,from)):(-1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::contains(const char accept[], const int from) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->contains(accept,from)):(-1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::rcontains(const char accept[], const int from) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->rcontains(accept,from)):(-1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::cmp(const GBaseString &s2, const int len) const
|
|
Packit |
df99a1 |
{ return GStringRep::cmp(*this,s2,len); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::cmp(const char *s2, const int len) const
|
|
Packit |
df99a1 |
{ return GStringRep::cmp(*this,s2,len); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::cmp(const char s2) const
|
|
Packit |
df99a1 |
{ return GStringRep::cmp(*this,&s2,1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::cmp(const char *s1, const char *s2, const int len)
|
|
Packit |
df99a1 |
{ return GStringRep::cmp(s1,s2,len); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator==(const GBaseString &s2) const
|
|
Packit |
df99a1 |
{ return !cmp(s2); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator==(const char *s2) const
|
|
Packit |
df99a1 |
{ return !cmp(s2); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator!=(const GBaseString &s2) const
|
|
Packit |
df99a1 |
{ return !!cmp(s2); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator!=(const char *s2) const
|
|
Packit |
df99a1 |
{ return !!cmp(s2); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator>=(const GBaseString &s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)>=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator>=(const char *s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)>=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator>=(const char s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)>=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator<(const GBaseString &s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)<0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator<(const char *s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)<0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator<(const char s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)<0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator> (const GBaseString &s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)>0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator> (const char *s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)>0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator> (const char s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)>0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator<=(const GBaseString &s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)<=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator<=(const char *s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)<=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::operator<=(const char s2) const
|
|
Packit |
df99a1 |
{ return (cmp(s2)<=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::nextNonSpace( const int from, const int len ) const
|
|
Packit |
df99a1 |
{ return ptr?(*this)->nextNonSpace(from,len):0; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::nextChar( const int from ) const
|
|
Packit |
df99a1 |
{ return ptr?(*this)->nextChar(from):0; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::nextSpace( const int from, const int len ) const
|
|
Packit |
df99a1 |
{ return ptr?(*this)->nextSpace(from,len):0; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::firstEndSpace( const int from,const int len ) const
|
|
Packit |
df99a1 |
{ return ptr?(*this)->firstEndSpace(from,len):0; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
GBaseString::is_valid(void) const
|
|
Packit |
df99a1 |
{ return ptr?((*this)->is_valid()):true; }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::ncopy(wchar_t * const buf, const int buflen) const
|
|
Packit |
df99a1 |
{if(buf&&buflen)buf[0]=0;return ptr?((*this)->ncopy(buf,buflen)):0;}
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline int
|
|
Packit |
df99a1 |
GBaseString::CheckSubscript(int n) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if(n)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (n<0 && ptr)
|
|
Packit |
df99a1 |
n += (*this)->size;
|
|
Packit |
df99a1 |
if (n<0 || !ptr || n > (int)(*this)->size)
|
|
Packit |
df99a1 |
throw_illegal_subscript();
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
return n;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GBaseString::GBaseString(void) { init(); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String::GUTF8String(void) { }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String::GUTF8String(const GUTF8String &str)
|
|
Packit |
df99a1 |
{ init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String& GUTF8String::operator= (const GP<GStringRep> &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String& GUTF8String::operator= (const GBaseString &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String& GUTF8String::operator= (const GUTF8String &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String& GUTF8String::operator= (const GNativeString &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String
|
|
Packit |
df99a1 |
GUTF8String::create( const char *buf, const unsigned int bufsize )
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
#if HAS_WCHAR
|
|
Packit |
df99a1 |
return GNativeString(buf,bufsize);
|
|
Packit |
df99a1 |
#else
|
|
Packit |
df99a1 |
return GUTF8String(buf,bufsize);
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String
|
|
Packit |
df99a1 |
GUTF8String::create( const uint16_t *buf, const unsigned int bufsize )
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return GUTF8String(buf,bufsize);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GUTF8String
|
|
Packit |
df99a1 |
GUTF8String::create( const uint32_t *buf, const unsigned int bufsize )
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return GUTF8String(buf,bufsize);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString::GNativeString(void) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#if !HAS_WCHAR
|
|
Packit |
df99a1 |
// For Windows CE, GNativeString is essentially GUTF8String
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GUTF8String &str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GP<GStringRep> &str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const char dat)
|
|
Packit |
df99a1 |
: GUTF8String(dat) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const char *str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const unsigned char *str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const uint16_t *str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const uint32_t *str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const char *dat, unsigned int len)
|
|
Packit |
df99a1 |
: GUTF8String(dat,len) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const uint16_t *dat, unsigned int len)
|
|
Packit |
df99a1 |
: GUTF8String(dat,len) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const uint32_t *dat, unsigned int len)
|
|
Packit |
df99a1 |
: GUTF8String(dat,len) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GNativeString &str)
|
|
Packit |
df99a1 |
: GUTF8String(str) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const int number)
|
|
Packit |
df99a1 |
: GUTF8String(number) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const double number)
|
|
Packit |
df99a1 |
: GUTF8String(number) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GNativeString &fmt, va_list &args)
|
|
Packit |
df99a1 |
: GUTF8String(fmt,args) {}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#else // HAS_WCHAR
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Initialize this string class
|
|
Packit |
df99a1 |
inline void
|
|
Packit |
df99a1 |
GNativeString::init(void)
|
|
Packit |
df99a1 |
{ GBaseString::init(); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
/// Initialize this string class
|
|
Packit |
df99a1 |
inline GNativeString &
|
|
Packit |
df99a1 |
GNativeString::init(const GP<GStringRep> &rep)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
GP<GStringRep>::operator=(rep?rep->toNative(GStringRep::NOT_ESCAPED):rep);
|
|
Packit |
df99a1 |
init();
|
|
Packit |
df99a1 |
return *this;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::substr(int from, int len) const
|
|
Packit |
df99a1 |
{ return GNativeString(*this, from, len); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString &
|
|
Packit |
df99a1 |
GNativeString::vformat(const GNativeString &fmt, va_list &args)
|
|
Packit |
df99a1 |
{ return (*this = (fmt.ptr?GNativeString(fmt,args):fmt)); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::toEscaped( const bool tosevenbit ) const
|
|
Packit |
df99a1 |
{ return ptr?GNativeString((*this)->toEscaped(tosevenbit)):(*this); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GUTF8String &str)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (str.length())
|
|
Packit |
df99a1 |
init(str->toNative(GStringRep::NOT_ESCAPED));
|
|
Packit |
df99a1 |
else
|
|
Packit |
df99a1 |
init((GP<GStringRep>)str);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GP<GStringRep> &str)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (str)
|
|
Packit |
df99a1 |
init(str->toNative(GStringRep::NOT_ESCAPED));
|
|
Packit |
df99a1 |
else
|
|
Packit |
df99a1 |
init(str);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GBaseString &str)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (str.length())
|
|
Packit |
df99a1 |
init(str->toNative(GStringRep::NOT_ESCAPED));
|
|
Packit |
df99a1 |
else
|
|
Packit |
df99a1 |
init((GP<GStringRep>)str);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline
|
|
Packit |
df99a1 |
GNativeString::GNativeString(const GNativeString &fmt, va_list &args)
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (fmt.ptr)
|
|
Packit |
df99a1 |
init(fmt->vformat(args));
|
|
Packit |
df99a1 |
else
|
|
Packit |
df99a1 |
init(fmt);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::create( const char *buf, const unsigned int bufsize )
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return GNativeString(buf,bufsize);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::create( const uint16_t *buf, const unsigned int bufsize )
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return GNativeString(buf,bufsize);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::create( const uint32_t *buf, const unsigned int bufsize )
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
return GNativeString(buf,bufsize);
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString&
|
|
Packit |
df99a1 |
GNativeString::operator= (const GP<GStringRep> &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString&
|
|
Packit |
df99a1 |
GNativeString::operator= (const GBaseString &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString&
|
|
Packit |
df99a1 |
GNativeString::operator= (const GUTF8String &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString&
|
|
Packit |
df99a1 |
GNativeString::operator= (const GNativeString &str)
|
|
Packit |
df99a1 |
{ return init(str); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::upcase( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (ptr) return (*this)->upcase();
|
|
Packit |
df99a1 |
return *this;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline GNativeString
|
|
Packit |
df99a1 |
GNativeString::downcase( void ) const
|
|
Packit |
df99a1 |
{
|
|
Packit |
df99a1 |
if (ptr) return (*this)->downcase();
|
|
Packit |
df99a1 |
return *this;
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#endif // HAS_WCHAR
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator==(const char *s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return !s2.cmp(s1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator!=(const char *s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return !!s2.cmp(s1); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator>=(const char *s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return (s2.cmp(s1)<=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator>=(const char s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return (s2.cmp(s1)<=0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator<(const char *s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return (s2.cmp(s1)>0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator<(const char s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return (s2.cmp(s1)>0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator> (const char *s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return (s2.cmp(s1)<0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator> (const char s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return (s2.cmp(s1)<0); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator<=(const char *s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return !(s1>s2); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
inline bool
|
|
Packit |
df99a1 |
operator<=(const char s1, const GBaseString &s2)
|
|
Packit |
df99a1 |
{ return !(s1>s2); }
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
// ------------------- The end
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
|
|
Packit |
df99a1 |
#ifdef HAVE_NAMESPACES
|
|
Packit |
df99a1 |
}
|
|
Packit |
df99a1 |
# ifndef NOT_USING_DJVU_NAMESPACE
|
|
Packit |
df99a1 |
using namespace DJVU;
|
|
Packit |
df99a1 |
# endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
#endif
|
|
Packit |
df99a1 |
|