2005/5/9

     
 

class String

artefaktur
Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members   Related Pages  

acdk::lang::String Class Reference
[ACDK String macros/function/classes]

#include <String.h>

Inheritance diagram for acdk::lang::String:

acdk::lang::Object acdk::lang::Comparable acdk::lang::Cloneable acdk::lang::ObjectBase acdk::lang::dmi::StdDispatch List of all members.

Detailed Description

Similar to Java but extended Some extional function are inspired by the org.apache.commons.lang.StringUtils class.

See also:
For more details see  String
Author:
Roger Rene Kommer
Version:
Revision
1.73
Date:
Date
2005/04/28 11:13:07


Public Types

typedef int(* CharConvertFunc )(int c)
typedef bytebyte_iterator
 standard iterator over single byte chars

typedef unsigned short StringFlags
typedef StringIterator iterator

Public Member Functions

 String ()
 constructs an empty string

 String (IN(RString) str, int start=0, int length=-1)
 Creates a Substring from given str.

 String (const String &str, int start, int length=-1)
 Creates a Substring from given str.

 String (StringBuffer &buf, int start=0, int end=-1)
 Creates a Substring from given str.

 String (IN(RStringBuffer) buf, int start=0, int end=-1)
 Creates a Substring from given str.

 String (const char *ptr, int flags=ConstSST|CCAscii)
 Create instance of given C-str.

 String (const uc2char *ptr, int flags=ConstSST|CCUcs2)
 initialize with const wide char character

 String (const uc4char *ptr)
 initialize with a 4 byte unicode character will be converted to a uc2char internally

 String (const char *ptr, int length, int flags)
 Create instance of given C-str.

 String (const uc2char *ptr, int length, int flags)
 using wide character to initilize

 String (IN(RbyteArray) ba, int offset=0, int size=-1)
 String (IN(RbyteArray) ba, IN(acdk::locale::RDecoder) decoder, int offset=0, int size=-1)
 String (const byte *cptr, IN(acdk::locale::RDecoder) decoder, int offset=0, int size=-1)
 String (IN(RcharArray) ba, int offset=0, int size=-1)
 initilize string with UTF8 or ASCII character stream

 String (IN(RuccharArray) ba, int offset=0, int size=-1)
 initialize with unicode character array

 String (byte *buffer, int bufferlength, byte_iterator begin, byte_iterator end, StringFlags flags)
 internal constructor to create string with prepared stream

 String (const StaticAsciiLiteral &strLit)
 String (String *parent, byte_iterator bit, byte_iterator eit)
 Construct a new Substring.

 String (iterator begin, iterator end)
 creates new string

 String (int buffersize)
 Constructs a Normal string with a internal buffer of buffersize _buffer = _begin = _end.

virtual ~String ()
StringStorageType storageType () const throw ()
CharacterClass characterClass () const throw ()
CodePage codePage () const throw ()
StringFlags characterEncoding () const throw ()
StringFlags stringFlags () const throw ()
bool isCharacterClass (CharacterClass cc) const throw ()
byte_iterator buffer () const throw ()
byte_iterator byte_begin () const throw ()
byte_iterator byte_end () const throw ()
int bufferLength () const throw ()
 returns the length of the stored bytes (not character)

iterator begin () const
iterator end () const
void _set (int flags, byte *buffer, int bufs, byte_iterator b, byte_iterator e)
void _setEnd (byte_iterator e)
RString toString ()
 return a string representation of this object Object::toString() return getName() by default

RObject clone (sys::Allocator *alc)
 reimplemented from Object

RObject clone ()
 reimplemented from Object

bool equals (IN(RObject) o)
 return false if object is not a string instance, or string does not have same content

bool equals (IN(RString) str)
bool equals (const char *cstr)
 compare with null terminated native string

bool equals (const char *cstr, int len)
 compare with native string on given length

bool equalsWithHash (const char *cstr, int hashCode)
 if given hasCode is not equal to hashCode of this string return false, othewise use equals()

bool equalsWithHash (const char *cstr, int len, int hashCode)
 if given hasCode is not equal to hashCode of this string return false, othewise use equals()

bool equals (const StaticAsciiLiteral &slit)
 if given hasCode is not equal to hashCode of this string return false, othewise use equals()

bool equals (const uc2char *cstr)
 compare with null terminated native string

bool equals (const String &str)
bool equalsNoHash (const String &str)
 traditional hashing

bool equalsIgnoreCase (IN(RString) other) const
 compare 2 string ignore case.

bool equalsIgnoreCase (const char *other) const
 compare 2 string ignore case.

bool equalsIgnoreCase (const uc2char *other) const
 compare 2 string ignore case.

bool equalsIgnoreCase (const String &o) const
int compareTo (IN(RObject) o)
 API: JDK / reimplemented from Object.

int compareTo (IN(RString) s)
 compare two string lexically.

int compareTo (const char *cstr)
 compare two string lexically.

int compareTo (const uc2char *cstr)
 compare two string lexically.

int compareTo (const String &other)
int compareToIgnoreCase (const String &other) const
int compareToIgnoreCase (IN(RString) other) const
 compare two string lexically.

int compareToIgnoreCase (const char *other) const
 compare two string lexically.

int compareToIgnoreCase (const uc2char *other) const
 compare two string lexically.

uc2char charAt (int idx) const
 return character at given offset
Exceptions:
StringIndexOutOfBoundsException 



int hashCode ()
 return the hash code of this string the String does cache the hash code for performance reasons

int length () const
 return the count of contained characters

const char * c_str () const
 return the underlying character stream throws exception if not compatible stream

const uc2charuc2c_str () const
 return the underlying character stream throws exception if not compatible stream

const uc2charnative_c_str () const
RString concat (IN(RString) o) const
 Append param o to this string an return the concated string.

RString concat (const String &str) const
RString concat (const char *str) const
RString concat (const uc2char *str) const
bool startsWith (IN(RString) prefix, int toffset=0) const
 return true if prefix starts at offset of this string

bool startsWith (const char *prefix, int toffset=0) const
bool startsWith (const uc2char *prefix, int toffset=0) const
bool startsWith (const String &prefix, int toffset=0) const
bool endsWith (IN(RString) suffix) const
 return true if this string ends with suffix string

bool endsWith (const char *text) const
bool endsWith (const uc2char *text) const
bool endsWith (const String &suffix) const
bool regionMatches (int toffset, IN(RString) other, int otheroffset=0, int len=-1, bool ignoreCase=false) const
bool regionMatches (int toffset, const char *other, int otheroffset=0, int len=-1, bool ignoreCase=false) const
bool regionMatches (int toffset, const uc2char *other, int otheroffset=0, int len=-1, bool ignoreCase=false) const
bool regionMatches (int toffset, const String &other, int otheroffset=0, int len=-1, bool ignoreCase=false) const
int indexOf (char ch, int fromIndex=0) const
 Search an character in this string starting at fromIndex.

int indexOf (uc2char ch, int fromIndex=0) const
 Search an character in this string starting at fromIndex.

int lastIndexOf (char ch, int fromIndex=-1) const
 Search an character from back in this string starting at fromIndex.

int lastIndexOf (uc2char ch, int fromIndex=-1) const
int indexOf (IN(RString) str, int fromIndex=0) const
 Find sub string in this string starting at fromIndex.

int indexOf (const char *str, int fromIndex=0) const
int indexOf (const uc2char *str, int fromIndex=0) const
int indexOf (const String &str, int fromIndex=0) const
int lastIndexOf (IN(RString) str, int fromIndex=-1) const
 Find substring from back in this string.

int lastIndexOf (const char *str, int fromIndex=-1) const
int lastIndexOf (const uc2char *str, int fromIndex=-1) const
int lastIndexOf (const String &str, int fromIndex=-1) const
void getChars (int srcBegin, int srcEnd, IN(RcharArray) dst, int dstBegin, IN(acdk::locale::REncoder) enc) const
 copy utf8 stream character into dst

void getUc2Chars (int srcBegin, int srcEnd, IN(RuccharArray) dst, int dstBegin) const
 copy ucchar into dst

RcharArray getChars () const
 The corresponding getByte functions are superflous.

RbyteArray getBytes () const
 return the bytes in current internal encoding

RbyteArray getBytes (IN(RString) enc) const
 return the bytes of this string using the given encoder

RbyteArray getBytes (IN(acdk::locale::REncoder) enc) const
 return the bytes of this string using the given encoder

RcharArray getChars (IN(acdk::locale::REncoder) enc) const
 return the bytes of this string using the given encoder Better to use getBytes()

RuccharArray getUcChars () const
 return the bytes as unicode

RcharArray tocharArray () const
 Does the same as: RcharArray getChars();.

RString substr (int startidx, int endidx=-1) const
 Just an alias to substring().

RString substring (int startidx, int endidx=-1) const
 create a substring of this string.

RString left (int len) const
 return a substring with len characters from left if len > length() return the complete string returns substr(0, len)

RString right (int len) const
 return substring from right if len > length() return the complete string returns substr(len);

RString mid (int start, int len) const
 return a substr(start, start + len) if start > length() return empty string if start + len > length() return substr(start)

RString substringBefore (IN(RString) find) const
 return the string before the first occourence of find if find is Nil return the this if find cannot be found return this

RString substringAfter (IN(RString) find) const
 return the string after the first found find string if find is Nil return empty string if find cannot be found return empty string if found index + length of find > as length() return empty string

RString substringBeforeLast (IN(RString) find) const
 see substringBefore but relation used lastIndexOf instead of indexOf

RString substringAfterLast (IN(RString) find) const
 see substringAfter but relation used lastIndexOf instead of indexOf

RString toLowerCase () const
 return a new string with lowercase character.

bool isLowerCase () const
 return true, if all character has lowercase or non-letter types

RString toUpperCase () const
 return a new string with upper case character.

bool isUpperCase () const
 return true, if all character has upper case or non-letter types

RString trim (int trimflags=TrimBoth|TrimWhiteSpace) const
 Cut whitespaces from the end of the string.

RString intern () const
 put it into a weak hashmap.

RString replace (char oldChar, char newChar) const
 replaces all appeariances of oldChar with newChar

RString replace (uc2char oldChar, uc2char newChar) const
 unicode variant of character replacemant

RString replace (IN(RString) find, IN(RString) repl) const
 replace every string find with repl string.

RString replace (const char *find, const char *repl) const
RString replace (const uc2char *find, const uc2char *repl) const
RString replace (const String &find, const String &repl) const
RString replace (int startidx, int endidx, IN(RString) str) const
 Cut text from startidx to endix and replace this text with str Different to the other replace function this is (naturally) not recursiv.

RString replace (int startidx, int endidx, const String &str) const
int elementCount (char c) const
 returns how often the caracter can be found in String.

int elementCount (uc2char c) const
int elementCount (IN(RString) str) const
 API: ACDK return how often the string occurs in the String.

int elementCount (const String &str) const
int elementCount (const char *str) const
int elementCount (const uc2char *str) const
int getFirstIndexOf (IN(RString) chars) const
 find the first of one of the chars

RString peekLine (int lineNo) const
 return the nth line of this string

char * c_strdup (sys::Allocator *allocator=0) const
 returns a copy of the String undlying char* buffer.

RString convert (int flags, acdk::locale::CodingErrorAction onMalformed, acdk::locale::CodingErrorAction onUnmappable) const
 convert current string to another CharacterClass

RString convert (int flags) const
 convert the string on given flags.

RString convertToNative () const
 convert string to native underlying operation system calls.

RString narrow () const
 Try to narrow the string to the smallest possible character set.

RString getNormalized () const
 In case this string doesn't own the string buffer (but is substring or a const string, it return a new string which owns the buffer.

RStringArray split () const
 return a StringArray splitted.

RStringArray split (uc2char delimiter) const
 basically calls: StringTokenizer(this, delimiter)->allToken()

RStringArray split (IN(RString) delimiterChars) const
 basically calls: StringTokenizer(this, delimiterChars)->allToken()

RString repeat (int ntimes) const
 repeat this string n times

RString rightPad (int size, uc2char padchar= ' ') const
 padd the this text on the right with paddchar (default is space ' ') if length of this string is less or equal size return this string

RString leftPad (int size, uc2char padchar= ' ') const
 see rightPad

RString center (int size, uc2char padchar= ' ') const
 center this string in screen with size wide

RString operator+ (IN(RString) other) const
RString operator+ (IN(RObject) o) const
RString operator+ (bool v) const
RString operator+ (char v) const
RString operator+ (uc2char v) const
RString operator+ (short v) const
RString operator+ (int v) const
RString operator+ (jlong v) const
RString operator+ (float v) const
RString operator+ (double v) const
RString operator+ (const char *text) const
RString operator+ (char *text) const
RString operator+ (const uc2char *text) const
RString operator+ (uc2char *text) const
bool isCChar () const
 return true if this string holds the characters in 8 bit

bool isUc2Char () const
 return true if this string holds the characters in 16 bit

bool isUc4Char () const
 return true if this string holds the characters in 32 bit

bool isUtf8Char () const
 return true if this string holds the characters in UTF8 encoding (variable bits per character)

int getMaxCharacterSize () const
 return the maximum byte storage for a character may used for buffer allocation

int getCharCapacity () const
 return size of capacity in chars of the underlying string this is not related to length(), may be greater or lesser

void setEnd (byte_iterator it)
String_getSubstrBase () throw ()
 return the real holding substr String instance

const String_getSubstrBase () const throw ()
RString decodeAscUnicode ()
 Asuming in the character are embedded \uABCD token.

RString encodeAscUnicode ()
 encode the current string ascii with \uABCD The resulting string has always the characterClass CCAscii


Static Public Member Functions

RObject create_instance ()
bool isCharacterClass (int flags, CharacterClass cc) throw ()
StringStorageType storageType (StringFlags flags) throw ()
CharacterClass characterClass (StringFlags flags) throw ()
CodePage codePage (StringFlags flags) throw ()
bool hashCodeCompatible (CharacterClass first, CharacterClass second)
 return true if 2 string character classes are hash-compatible

RString copyValueOf (IN(RcharArray) data, int offset=0, int count=-1)
RString valueOf (bool z)
 render the given value to a string

RString valueOf (int z)
 render the given value to a string

RString valueOf (char z)
 render the given value to a string

RString valueOf (uc2char z)
 render the given value to a string

RString valueOf (jlong z)
 render the given value to a string

RString valueOf (float z)
 render the given value to a string

RString valueOf (double z)
 render the given value to a string

RString valueOf (IN(RObject) obj)
 render the given value to a string

RString valueOf (char *ptr)
 render the given value to a string

RString valueOf (const char *ptr)
 render the given value to a string

RString valueOf (uc2char *ptr)
 render the given value to a string

RString valueOf (const uc2char *ptr)
 render the given value to a string

RString valueOf (void *ptr)
 render the given value to a string

RString valueOf (size_t s)
 render the given value to a string

RString valueOf (const String &s)
 render the given value to a string

RString _itoa (int i, int radix)
RString _jltoa (jlong i, int radix)
 OUT (RString) emptyString()
RString getEmptyString ()
 return an empty String

RString defaultString (IN(RString) str)
 return if String is Nil otherwise the String itself

RString defaultString (IN(RString) str, IN(RString) defaultString)
 return defaultString if str is nil otherwise str

bool isEmpty (IN(RString) str)
 return true if str is Nil or length == 0

bool isNotEmpty (IN(RString) str)
 return true if str is not Nil and length > 0

bool isBlank (IN(RString) str)
 return true if str is Nil or empty or all characters of str are white spaces

bool isNotBlank (IN(RString) str)
 return not isBlank(str)

bool isAlpha (IN(RString) str)
 return true if all characters are alph if Nil returns false if string is empty returns true

bool isAlphaSpace (IN(RString) str)
 return true if all characters of str are spaces or letters return false if str is nil return true if str length is 0

bool isAlphanumeric (IN(RString) str)
 return true if all characters of str are letters or numbers return false if str is nil return true if str length is 0

bool isAlphanumericSpace (IN(RString) str)
 return true if all characters of str are letters or numbers or spaces return false if str is nil return true if str length is 0

bool isNumeric (IN(RString) str)
 return true if all characters of str are numbers return false if str is nil return true if str length is 0

bool isNumericSpace (IN(RString) str)
 return true if all characters of str are numbers or white spaces return false if str is nil return true if str length is 0

bool contains (IN(RString) str, uc2char c)
 return false if str is Nil or str->indexOf(c) == -1

bool contains (IN(RString) str, IN(RString) find)
 return false if str is Nil or str->indexOf(find) == -1

bool containsNone (IN(RString) str, IN(RString) chars)
 return true if str or chars is Nil returns true if none of the characters in chars can be found in str otherwise return false

bool containsOnly (IN(RString) str, IN(RString) chars)
 return false if str or chars is Nil return true if in str only characters, which defined in chars

int indexOfAny (IN(RString) str, IN(RuccharArray) chars)
 find the first index of one of the characters if str or chars is Nil return -1 otherwise find the lower index of one of the characters in chars

int indexOfAny (IN(RString) str, IN(RString) chars)
 find the first index of one of the characters in chars if str or chars is Nil return -1 otherwise find the lower index of one of the characters in chars

int indexOfAny (IN(RString) str, IN(RStringArray) strings)
 find the first index of one of the String in strings if str or strings is Nil return -1 otherwise find the lower index of one of the strings

int lastIndexOfAny (IN(RString) str, IN(RString) chars)
 find the last index of chars in str return -1 if str or chars is Nil otherwise return largest index found of one out chars in str if non found return -1

int lastIndexOfAny (IN(RString) str, IN(RuccharArray) chars)
 find the last index of chars in str return -1 if str or chars is Nil otherwise return largest index found of one out chars in str if non found return -1

int lastIndexOfAny (IN(RString) str, IN(RStringArray) strings)
 find the last index of strings in str return -1 if str or strings is Nil otherwise return largest index found of one out strings in str if non found return -1

RString join (IN(acdk::util::RIterator) it)
 concat each element from iterator with character if iterator it is Nil return Nil for each element returned by the iterator toString() will be called if the element is Nil add nothing to the joined string

RString join (IN(acdk::util::RIterator) it, uc2char delimiter)
 concat each element from iterator with character if iterator it is Nil return Nil for each element returned by the iterator toString() will be called if the element is Nil add nothing to the joined At beginning and end are no delimiter

RString join (IN(acdk::util::RIterator) it, IN(RString) delimiter)
RString join (IN(RObjectArray) oa)
 concats each element of the array to a string calls join(oa, String::emptyString()) see join(IN(RObjectArray) oa, IN(RString) delimiter)

RString join (IN(RObjectArray) oa, uc2char delimiter)
 see join(IN(RObjectArray) oa, IN(RString) delimiter)

RString join (IN(RObjectArray) oa, IN(RString) delimiter)
RString deleteWhitespace (IN(RString) str)
 return all whitespace characters from string if str is Nil returns Nil

int indexOfDifference (IN(RString) first, IN(RString) second)
 returns the index position where first differs to second if no difference was found return -1 if first or second is Nil return -1

int getDistance (IN(RString) first, IN(RString) second)
 calculate a distance between 2 string corresponding to the Levenshtein Distance first and second must not Nil The (slitly transformed) code is from (http://www.merriampark.com/ld.htm).

RString fomUtfEscapedLiteral (const char *text)
 Convert string from escaped const char* string, which contains escapes.

RString fomUtfEscapedLiteral (const uc2char *text)
 Convert string from escaped const uc2char* string, which contains escapes.

RString decodeAscUnicode (const char *source, const char *end)
 Convert a ascii stream with utf escape codes use this function only with literal string.

RString decodeAscUnicode (const char *source)
 Convert a ascii stream with utf escape codes use this function only with literal string.

uc2char decodeAscUnicodeCharacter (const char *source)
int calcHashCode (const char *t)
 calculate hascode from 0 terminated string

int calcHashCode (const char *t, int len)
 calculate hascode from string with len

RString _decodeAscUnicode (const char *source, const char *end)
uc2char _decodeAscUnicodeCharacter (const char *source)
void _throwIncompatibleString (const String &s)

Private Member Functions

void _init (const String &str, int start, int end)
 initialization for sub string constructor

void _init (const char *ptr, int length, int flags)
 initialization with ASCII or Ansi stream

void _init (const uc2char *ptr, int length, int flags)
 initialization with UCS-2 stream

char * _init (const uc2char *ptr, int length, const byte *buffer, byte *&end, int targetoffset)
void _init (byte_iterator sit, byte_iterator eit, acdk::locale::Decoder &decoder)
 initialize string with given byte char stream using the decoder

void normalize () const
void _normalize ()
RString _convert (int flags, acdk::locale::CodingErrorAction onMalformed, acdk::locale::CodingErrorAction onUnmappable) const
RString _narrow () const
void _throwIndexOutOfBound (const char *text, int idx, int max)
 Used as optimized version in case target and source has same length.

void _throwIndexOutOfBound (const uc2char *text, int idx, int max)
void _calcHashCode ()

Private Attributes

StringFlags _stringFlags
 a bit combination of StorageType, CharacterClass and CodePage

byte_buffer
 used to store buffer

int _bufferLength
 length of byte buffer

byte_iterator _begin
 first byte char

byte_iterator _end
 byte char behind last char.

int _hashCode
 backuped hasCode


Friends

class StringBuffer


Member Typedef Documentation

typedef byte* acdk::lang::String::byte_iterator
 

standard iterator over single byte chars

typedef int(* acdk::lang::String::CharConvertFunc)(int c)
 

typedef StringIterator acdk::lang::String::iterator
 

typedef unsigned short acdk::lang::String::StringFlags
 


Constructor & Destructor Documentation

acdk::lang::String::String  ) 
 

constructs an empty string

acdk::lang::String::String IN(RString str,
int  start = 0,
int  length = -1
[inline, explicit]
 

Creates a Substring from given str.

Parameters:
str parent string
start byte char position
length of string (endpos = start + offset. if length == -1 until end of parent string

acdk::lang::String::String const String str,
int  start,
int  length = -1
[inline, explicit]
 

Creates a Substring from given str.

Parameters:
start byte char position
end byte char position

acdk::lang::String::String StringBuffer buf,
int  start = 0,
int  end = -1
[explicit]
 

Creates a Substring from given str.

Parameters:
start byte char position
end byte char position

acdk::lang::String::String IN(RStringBuffer buf,
int  start = 0,
int  end = -1
[explicit]
 

Creates a Substring from given str.

Parameters:
start byte char position
end byte char position

acdk::lang::String::String const char *  ptr,
int  flags = ConstSST|CCAscii
[explicit]
 

Create instance of given C-str.

Parameters:
ptr the null terminated C-str.
flags Type to create. Valid types are Normal, Const, Hash Explicit encoding Ascii or Utf can also be provided

acdk::lang::String::String const uc2char ptr,
int  flags = ConstSST|CCUcs2
[explicit]
 

initialize with const wide char character

acdk::lang::String::String const uc4char ptr  ) 
 

initialize with a 4 byte unicode character will be converted to a uc2char internally

acdk::lang::String::String const char *  ptr,
int  length,
int  flags
 

Create instance of given C-str.

Parameters:
ptr the null terminated C-str.
length length of C-string not including ending ''
typ Type to create. Valid types are Normal, Const, Hash Explicit encoding Ascii or Utf can also be provided

acdk::lang::String::String const uc2char ptr,
int  length,
int  flags
 

using wide character to initilize

acdk::lang::String::String IN(RbyteArray ba,
int  offset = 0,
int  size = -1