/* * Jakelib2 - General purpose C++ library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: ZString.h,v 1.3 2002/09/16 18:39:16 gcc3 Exp $ */ class ZObject; class ZHashtable; #undef printf /** * The class ZString includes methods for examining * individual characters of the sequence, for comparing strings, for * searching strings, for extracting substrings, and for * converting strings to upper or lower case. * * @package jakelib.lang * @version $Id: ZString.h,v 1.3 2002/09/16 18:39:16 gcc3 Exp $ * @author Florian 'Overflo' Wolff (florian@donuz.de) */ class ZString : public ZObject { public: /** * Use printf instead! Constructs a new string from a printf-style format string. * The first argument is just a dummy to allow the compiler to * distinguish between the different constructors. * * @param dummy May be any int value * @param fstring A printf-style format string * @param ... Arguments to be inserted as defined by the format string * @deprecated */ ZString(int dummy, const char* fstring, ...); /** * Constructs a new string as a copy of a given string. * * @param str The string to be copied */ ZString(const ZString& str); /** * Constructs a new string from a given array of characters ( char* ). * * @param str The C-style string */ ZString(const char* str); /** * Constructs a new string as a copy of a given string. * * @param str The string to be copied */ ZString(ZString* str); /** * Constructs a new and empty string. */ ZString(); /** *

Constructs a new "Null" or "normal" string. A "Null" string may be usefull * if a function returns a string by value and in some cases should return * some kind of invalid string.

*

Whether a given string is a "Null" string or not can be determined by * isNull. * * @param isNullString If TRUE a "Null" string is created, otherwise a normal string is created. */ ZString(boolean isNullString); /** * Guess what: This is just a lousy destructor! */ ~ZString(); /** * Returns a pointer to a copy of this string object. * * @return ZString* */ // ZString clone(); /** * Returns a hashcode for this string. The hashcode for a * String object is computed as *

 
   * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
   * 
* using int arithmetic, where s[i] is the * ith character of the string, n is the length of * the string, and ^ indicates exponentiation. * (The hash value of the empty string is zero.) */ int hashCode(); /** * Returns the length of this string. * * @return The length of the sequence of characters represented by this object. */ int length(); /** * Return the string. */ ZString toString(); /** * Compares this object to the specified object. * The result is TRUE if and only if the argument is not * NULL and is a ZString object that contains * the same string value as this object. * * @param obj The object to compare with. * @return TRUE if the objects are the same; FALSE otherwise. */ boolean equals(ZObject* obj); /** * Compares this string to the specified C-style string. * The result is TRUE if and only if the argument is not * NULL and contains the same character sequence * as this string. * * @param str The C-style string to compare with. * @return TRUE if the strings are equal; FALSE otherwise. */ boolean equals(const char* str); /** * Compares this string case-insensitively to the specified C-style string. * The result is TRUE if and only if the argument is not * NULL and contains the same character sequence * as this string. * * @param str The C-style string to compare with. * @return TRUE if the strings are equal; FALSE otherwise. */ boolean equalsIgnoreCase(const char* str); /** * Returns a copy of this string where some character substitutions * have been made.
* <nl> => \n
* <rt> => \r
* \ => \\
* <tab> => \t
* " => \"
*/ ZString toCppString(); ZString parseCppString(); /** * Removes all preceeding blanks. */ ZString& ltrim(); /** * Removes all trailing blanks. */ ZString& rtrim(); /** * Removes blanks from both ends of the string. */ ZString& trim(); /** * Returns the integer value of the string. * * @return Integer value */ int toInt(); /** * Returns the long integer value of the string. * * @return Integer value */ long toLong(); /** * Returns a pointer to the array of characters in this string. * * @return Pointer to the internal array of characters. */ const char* getChars(); /** * Returns a pointer to the array of characters in this string. * * @param index The start index * @return Pointer to the internal array of characters. * @throws IllegalArgumentException If index is greater than the length of the string. */ const char* getChars(int index); int indexOf(ZString* str); int indexOf(const char* str); int indexOf(char c); int indexOf(ZString* str, int fromIndex); int indexOf(const char* str, int fromIndex); int lastIndexOf(ZString* str); int lastIndexOf(const char*); /** * Tests if this string starts with the specified prefix. * * @param prefix The prefix. * @return TRUE if the character sequence represented by the * argument is a prefix of the character sequence represented by * this string; FALSE otherwise. * Note also that TRUE will be returned if the * argument is an empty string or is equal to this * string object. */ boolean endsWith(ZString* prefix); boolean endsWith(const char* prefix); boolean endsWithIgnoreCase(const char* prefix); /** * Tests if this string ends with the specified suffix. * * @param suffix The suffix. * @return TRUE if the character sequence represented by the * argument is a suffix of the character sequence represented by * this string; FALSE otherwise. * Note also that TRUE will be returned if the * argument is an empty string or is equal to this * string object. */ boolean startsWith(ZString* suffix); boolean startsWith(const char* suffix); boolean startsWithIgnoreCase(const char* suffix); ZString substring(int beginIndex, int endIndex); ZString substring(int beginIndex); char charAt(int index); ZString& setChar(int index, char c); /** *

Converts all characters in this string to lower case. * Unlike the corresponding Java method * (java.lang.String.toLowerCase), the string itself is * modified!!

*

If you want the more java-like behaviour use getLowerCase.

* * @return A Reference to the string itself. */ ZString& toLowerCase(); /** *

Converts all characters in this string to upper case. * Unlike the corresponding Java method * (java.lang.String.toUpperCase), the string itself is * modified!

*

If you want the more java-like behaviour use getUpperCase.

* * @return A Reference to the string itself. */ ZString& toUpperCase(); ZString getLowerCase(); ZString getUpperCase(); ZString& replace(char oldChar, char newChar); //ZString* soundex(); ZString& remove(int beginIndex, int endIndex); ZString& remove(int beginIndex); ZString& append(const ZString* str); ZString& append(const char* str); ZString& append(char c); boolean isNull(); ZString& insert(int index, char c); //void insert(int index, ZString& str); ZString& insert(int index, const char* str); ZString& clear(); void ensureCapacity(int minimumCapacity); ZString& replaceStrings(const char* leftBrace, const char* rightBrace, ZHashtable* hash); ZString& operator = (const ZString& str); ZString& operator = (const char* str); ZString& operator += (const ZString& str); ZString& operator += (const char* str); int compareTo(ZObject* o); /** * @param fstring A printf-style format string * @param ... Arguments to be inserted as defined by the format string */ ZString& printf(const char * fstring, ...); protected: boolean isNullString; /** Contains the length of the string in characters. */ int len; /** Contains the max. capacity of the string in characters. */ int capacity; /** Contains a pointer the the array of charaters containing the string data. */ char* buffer; static int initialCapacity; static int increment; void init(int initialCapacity); }; #ifndef HAVE_ITOA char *itoa (int value, char *string, int radix); #endif