Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::String Class Reference

String is an abstract representation of textual string. More...

#include <String.h>

Inheritance diagram for Core::String:

Inheritance graph
[legend]
Collaboration diagram for Core::String:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 String (long size=0)
 Creates new empty string with specified size.
 String (const char *str)
 Creates new string from C-string.
 String (const ByteArray *byteArray)
virtual ~String (void)
 String (const String &origin)
virtual StringclassName (void) const
 Answer receiver class name.
virtual Objectat (int index) const
virtual void put (int index, Object *obj)
virtual void put (int index, char obj)
virtual long size (void) const
 Answer how many elements the collection includes.
virtual long indexOf (Object *obj) const
 Finds first index of element in a collection.
virtual long indexOf (const char obj) const
virtual long lastIndexOf (Object *obj) const
 Finds last index of element in a collection.
virtual long lastIndexOf (const char obj) const
virtual long nextIndexOf (Object *element, long startIndex, long stopIndex) const
virtual long nextIndexOf (const char element, long startIndex, long stopIndex) const
virtual long prevIndexOf (Object *element, long startIndex, long stopIndex) const
virtual long prevIndexOf (const char element, long startIndex, long stopIndex) const
virtual void add (Object *obj)
virtual void changeSize (long newSize)
virtual long hash (void) const
 Answer object hash value.
virtual bool isEqual (const Object *object) const
 Compare receiver with given object.
virtual bool isEqual (const Object &object) const
 Compare receiver with given object.
virtual bool isEqual (const char *string) const
virtual bool match (String *string)
 Answer whether a String matches the pattern in the receiver.
virtual bool match (const char *string)
virtual bool match (String *string, bool ignoreCase)
virtual bool match (const char *string, bool ignoreCase)
virtual bool matchesPattern (String *string, bool ignoreCase)
virtual char * asCString (void) const
 Returns C-string, ie.
virtual operator char * (void) const
virtual ArrayasArrayOfSubstrings (void)
 Answer Array of substrings separated by one or more spaces.
virtual ArrayasArrayOfSubstringsSeparatedBy (Character *ch)
 Answers Array of substrings separated by one or more occurences of given character.
virtual ArrayasArrayOfSubstringsSeparatedBy (const char ch)
virtual ByteArrayasByteArray (void) const
virtual ByteArrayasByteArrayEncoding (String *encoding) const
virtual ByteArrayasByteArrayEncoding (const char *encoding) const
virtual StringasLowercase (void)
virtual NumberasNumber (void)
virtual NumberasNumberRadix (int radix)
virtual StringasUppercase (void)
virtual StringasUppercaseFirst (void)
virtual StringasString (void)
virtual Objectcopy (void)
virtual Objectcopy (long from, long to)
 Returns a new collection with the same items as the specified portion of this collection.
virtual ObjectcopyEmpty (long size)
virtual SequenceableCollectionoperator+ (SequenceableCollection &collection)
virtual Stringoperator+ (const char *string)
virtual StringconcatenateWith (String *string)
virtual StringconcatenateWith (const char *string)
virtual void printOn (Stream *stream) const
 Print object identification into the stream.
virtual bool includes (Object *object)
virtual bool includes (const char element)
virtual bool includesSubcollection (SequenceableCollection *coll) const
virtual bool includesSubcollection (const char *coll) const
virtual bool isString (void) const
 Answer if the receiver is a String.
virtual bool isByteString (void) const
virtual bool isTwoByteString (void) const
virtual bool isCharacterArray (void) const
virtual bool isDigitString (void)
 Answers if the string contains only decimal digits.
virtual bool startsWith (SequenceableCollection *coll) const
virtual bool startsWith (const char *str) const
virtual bool endsWith (SequenceableCollection *coll) const
virtual bool endsWith (const char *str) const
virtual StringtrimBlanks (void)
virtual StringdemangleMethodName (void)
virtual void visitBy (Visitor *visitor)

Static Public Member Functions

static Stringformat (const String *format,...)
 Creates new String instace from formatted string.
static Stringformat (const char *format,...)
 Same as format(const String* format, .
static Stringwith (Character *object)
static Stringwith (Character *obj1, Character *obj2)
static Stringwith (Character *obj1, Character *obj2, Character *obj3)
static Stringwith (Character *obj1, Character *obj2, Character *obj3, Character *obj4)
static StringwithAll (Collection *coll)

Protected Member Functions

virtual void changeWideToFit (int width)

Static Protected Member Functions

static StringformatArgumentsIntoString (const char *format, va_list args)

Protected Attributes

StringImplimplementor

Detailed Description

String is an abstract representation of textual string.

The characters themself are held by one of StringImpl subclasses.

Although could use different character sizes, it uses just ByteString implementor for now. So all strings are held in encoding depending on machine setup.

Definition at line 47 of file String.h.


Constructor & Destructor Documentation

String::String long  size = 0  ) 
 

Creates new empty string with specified size.

  • size - number of Characters which can be stored.

Definition at line 44 of file String.cc.

References implementor.

Referenced by add(), asByteArrayEncoding(), className(), concatenateWith(), copy(), copyEmpty(), demangleMethodName(), endsWith(), includesSubcollection(), match(), put(), startsWith(), String(), trimBlanks(), with(), and withAll().

00045 {
00046     if (size < 0) {
00047         fprintf(stderr, "Warning: Constructing String with negative size. Creating empty.\n");
00048         size = 0;
00049     }
00050     implementor = new ByteString(size);
00051 }

String::String const char *  str  ) 
 

Creates new string from C-string.

  • str - new string content.

Definition at line 53 of file String.cc.

References implementor, Core::StringImpl::put(), String(), and Core::Character::value().

00054 {
00055     if (str == NULL) {
00056         fprintf(stderr, "Warning: Constructing String from NULL argument. Creating empty.\n");
00057         implementor = new ByteString(0);
00058     } else {
00059         int length = strlen(str);
00060         implementor = new ByteString(length);
00061         for (int i = 0; i < length; i++) {
00062             if (str[i] < 0) {
00063                 (new Error(new String("Illegal character. 7-bit only accepted."),
00064                            new String(__PRETTY_FUNCTION__)))->raise();
00065             }
00066             implementor->put(i, Character::value((unsigned char) str[i]));
00067         }
00068     }
00069 }

String::String const ByteArray byteArray  ) 
 

Definition at line 71 of file String.cc.

References implementor, Core::StringImpl::put(), and Core::Character::value().

00072 {
00073     long length = byteArray->size();
00074     const unsigned char *ba = byteArray->rawBytesReadOnly();
00075     implementor = new ByteString(length);
00076     for (long i = 0; i < length; i++) {
00077         implementor->put(i, Character::value(ba[i]));
00078     }
00079 }

String::~String void   )  [virtual]
 

Definition at line 81 of file String.cc.

References implementor.

00082 {
00083     delete implementor;
00084 }

String::String const String origin  ) 
 

Definition at line 87 of file String.cc.

References at(), implementor, put(), and size().

00088 {
00089     long tally = origin.size();
00090     implementor = new ByteString(tally);
00091     for (long i = 0; i < tally; i++) {
00092                 put(i, dynamic_cast<Character *>(origin.at(i)));
00093     }
00094 }


Member Function Documentation

void String::add Object obj  )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 206 of file String.cc.

References Core::Object::shouldNotImplement(), and String().

00207 {
00208     shouldNotImplement(new String(__PRETTY_FUNCTION__));
00209 }

Array * String::asArrayOfSubstrings void   )  [virtual]
 

Answer Array of substrings separated by one or more spaces.

Definition at line 381 of file String.cc.

References asArrayOfSubstringsSeparatedBy(), and Core::Character::space().

00382 {
00383     return asArrayOfSubstringsSeparatedBy(Character::space());
00384 }

Array * String::asArrayOfSubstringsSeparatedBy const char  ch  )  [virtual]
 

Definition at line 408 of file String.cc.

References asArrayOfSubstringsSeparatedBy(), and Core::Character::value().

00409 {
00410     return asArrayOfSubstringsSeparatedBy(Character::value(ch));
00411 }

Array * String::asArrayOfSubstringsSeparatedBy Character ch  )  [virtual]
 

Answers Array of substrings separated by one or more occurences of given character.

Definition at line 386 of file String.cc.

References Core::OrderedCollection::add(), Core::SequenceableCollection::asArray(), at(), copy(), and size().

Referenced by asArrayOfSubstrings(), asArrayOfSubstringsSeparatedBy(), and Net::IPSocketAddress::stringToBytes().

00387 {
00388     OrderedCollection *answer = new OrderedCollection;
00389     long startIndex = 0, stopIndex;
00390     long length = size();
00391 
00392     while (startIndex < length) {
00393         while (startIndex < length && at(startIndex) == ch) {
00394             startIndex++;
00395         }
00396         stopIndex = startIndex;
00397         while (stopIndex < length && at(stopIndex) != ch) {
00398             stopIndex++;
00399         }
00400         if (stopIndex > startIndex) {
00401             answer->add(copy(startIndex, stopIndex));
00402             startIndex = stopIndex;
00403         }
00404     }
00405     return answer->asArray();
00406 }

ByteArray * String::asByteArray void   )  const [virtual]
 

Definition at line 413 of file String.cc.

References asByteArrayEncoding().

00414 {
00415     return asByteArrayEncoding("default");
00416 }

ByteArray * String::asByteArrayEncoding const char *  encoding  )  const [virtual]
 

Definition at line 423 of file String.cc.

References asByteArrayEncoding(), and String().

00424 {
00425     return asByteArrayEncoding(new String(encoding));
00426 }

ByteArray * String::asByteArrayEncoding String encoding  )  const [virtual]
 

Definition at line 418 of file String.cc.

References Core::ByteArray::fromStringEncoding().

Referenced by asByteArray(), and asByteArrayEncoding().

00419 {
00420     return ByteArray::fromStringEncoding(this, encoding);
00421 }

char * String::asCString void   )  const [virtual]
 

Returns C-string, ie.

pointer to char array terminated by NULL. Returned string is managed by garbage collector.

Definition at line 339 of file String.cc.

References at(), Core::Stream::contents(), Core::Stream::nextPut(), and size().

Referenced by External::ExternalInterface::ExternalInterface(), Core::FileAccessor::FileAccessor(), Tools::Filename::Filename(), Tools::CommandLineArgument::fillGetOptLongOption(), format(), Core::Number::fromStringRadix(), OS::Environment::getEnv(), Net::IPSocketAddress::hostAddressByName(), OS::MessageQueue::open(), operator char *(), OS::Process::privateExecuteJob(), Tools::Daemon::runUnderUserNamed(), OS::Environment::setEnv(), and External::ExternalInterface::symbol().

00340 {
00341     Stream *stream = (new ByteArray(size()))->withEncoding("default")->writeStream();
00342     for (int i = 0; i < size(); i++) {
00343         try {
00344             stream->nextPut(at(i));
00345         }
00346         catch (Error *ex) {
00347             stream->nextPut('?');
00348         }
00349     }
00350     return dynamic_cast<ByteArray *>(stream->contents())->asCString();
00351 }

String * String::asLowercase void   )  [virtual]
 

Definition at line 428 of file String.cc.

References at(), copyEmpty(), put(), and size().

Referenced by asUppercaseFirst(), and Core::EncodedStreamFactory::EncodedStreamFactory().

00429 {
00430     long length = size();
00431     String *newString = (String *) copyEmpty(length);
00432     for (long i = 0; i < length; i++) {
00433         newString->put(i, ((Character *) at(i))->asLowercase());
00434     }
00435     return newString;
00436 }

Number * String::asNumber void   )  [virtual]
 

Definition at line 438 of file String.cc.

References Core::Number::fromString().

Referenced by demangleMethodName(), and Net::URL::parseHost().

00439 {
00440     return Number::fromString(this);
00441 }

Number * String::asNumberRadix int  radix  )  [virtual]
 

Definition at line 443 of file String.cc.

References Core::Number::fromStringRadix().

00444 {
00445     return Number::fromStringRadix(this, radix);
00446 }

String * String::asString void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 470 of file String.cc.

00471 {
00472     return this;
00473 }

String * String::asUppercase void   )  [virtual]
 

Definition at line 448 of file String.cc.

References at(), copyEmpty(), put(), and size().

Referenced by asUppercaseFirst().

00449 {
00450     long length = size();
00451     String *newString = (String *) copyEmpty(length);
00452     for (long i = 0; i < length; i++) {
00453         newString->put(i, ((Character *) at(i))->asUppercase());
00454     }
00455     return newString;
00456 }

String * String::asUppercaseFirst void   )  [virtual]
 

Definition at line 458 of file String.cc.

References asLowercase(), asUppercase(), at(), copyEmpty(), put(), and size().

00459 {
00460     long length = size();
00461     if (length <= 0) return this;
00462     String *newString = (String *) copyEmpty(length);
00463     newString->put(0, ((Character *) at(0))->asUppercase());
00464     for (long i = 1; i < length; i++) {
00465         newString->put(i, ((Character *) at(i))->asLowercase());
00466     }
00467     return newString;
00468 }

Object * String::at int  index  )  const [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 148 of file String.cc.

References Core::StringImpl::at(), implementor, and size().

Referenced by asArrayOfSubstringsSeparatedBy(), asCString(), asLowercase(), asUppercase(), asUppercaseFirst(), demangleMethodName(), hash(), Core::ByteCharacterEncoder::integerValueFrom(), isDigitString(), isEqual(), matchesPattern(), Core::EncodedStreamFactory::normalizedEncoding(), and String().

00149 {
00150     if (index < 0 || index >= size())
00151         (new SubscriptOutOfBoundsError(__PRETTY_FUNCTION__, index))->raiseFrom(this);
00152     return implementor->at(index);
00153 }

void String::changeSize long  newSize  )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 211 of file String.cc.

References Core::StringImpl::changeSize(), and implementor.

00212 {
00213     if (newSize < 0) {
00214         fprintf(stderr, "Warning: Changing size of String to negative. Making zero instead.\n");
00215         newSize = 0;
00216     }
00217     implementor->changeSize(newSize);
00218 }

void String::changeWideToFit int  width  )  [protected, virtual]
 

Definition at line 631 of file String.cc.

References Core::StringImpl::asByteString(), Core::StringImpl::asCharacterArray(), Core::StringImpl::asTwoByteString(), and implementor.

Referenced by put().

00632 {
00633     switch (width) {
00634     case 1 :
00635         implementor = implementor->asByteString();
00636         break;
00637     case 2 :
00638         implementor = implementor->asTwoByteString();
00639         break;
00640     case 4 :
00641         implementor = implementor->asCharacterArray();
00642         break;
00643     }
00644 }

String * String::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Collection.

Definition at line 97 of file String.cc.

References String().

00098 {
00099     return new String("String");
00100 }

String * String::concatenateWith const char *  string  )  [virtual]
 

Definition at line 501 of file String.cc.

References concatenateWith(), and String().

00502 {
00503     return concatenateWith(new String(string));
00504 }

String * String::concatenateWith String string  )  [virtual]
 

Definition at line 496 of file String.cc.

References Core::SequenceableCollection::copyReplace(), and size().

Referenced by concatenateWith(), and operator+().

00497 {
00498     return (String *) copyReplace(size(), size(), string);
00499 }

virtual Object* Core::String::copy long  from,
long  to
[inline, virtual]
 

Returns a new collection with the same items as the specified portion of this collection.

  • from - the first item of this collection, that will be copied
  • to - the item behind the last item of this collection, that will be copied. If to <= from, no items will be copied and the returned collection will zero length.

Reimplemented from Core::SequenceableCollection.

Definition at line 171 of file String.h.

References Core::SequenceableCollection::copy().

00172       { return SequenceableCollection::copy(from, to); }

Object * String::copy void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 476 of file String.cc.

References String().

Referenced by asArrayOfSubstringsSeparatedBy(), Tools::Filename::constructString(), demangleMethodName(), Tools::Filename::extension(), Net::URL::fromString(), Tools::HierarchicalConfigurationReader::getConfigurationFor(), Tools::HierarchicalConfigurationReader::parseAssignment(), Tools::HierarchicalConfigurationReader::parseLine(), Core::GenericException::printStackOn(), Tools::HierarchicalConfigurationReader::readLine(), Tools::ConfigurationReader::readLine(), Tools::Filename::tail(), and trimBlanks().

00477 {
00478     return new String(*this);
00479 }

Object * String::copyEmpty long  size  )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 481 of file String.cc.

References String().

Referenced by asLowercase(), asUppercase(), and asUppercaseFirst().

00482 {
00483     return new String(size);
00484 }

String * String::demangleMethodName void   )  [virtual]
 

Definition at line 576 of file String.cc.

References asNumber(), at(), Core::Stream::contents(), copy(), Core::Stream::nextPutAll(), size(), String(), and Core::Character::value().

Referenced by Core::GenericException::printStackOn().

00577 {
00578 #if __GNUC_PREREQ(3,0)
00579     Stream *stream = (new String(size()))->writeStream();
00580     long segmentLength = 3, segmentStart = 0;
00581     String *buffer = this;
00582     String *segment;
00583 
00584     /* Skip prefix */
00585     while (!dynamic_cast<Character *>(buffer->at(segmentStart + segmentLength))->isDigit()) {
00586         segmentLength++;
00587     }
00588 
00589     while (dynamic_cast<Character *>(buffer->at(segmentStart + segmentLength))->isDigit()) {
00590         if (buffer != this) stream->nextPutAll("::");
00591         buffer = dynamic_cast<String *>(buffer->copy(segmentLength + segmentStart, buffer->size()));
00592         segmentStart = 0;
00593         segmentLength = buffer->asNumber()->asLong();
00594         while (dynamic_cast<Character *>(buffer->at(segmentStart))->isDigit())
00595             segmentStart++;
00596         segment = dynamic_cast<String *>(buffer->copy(segmentStart, segmentStart + segmentLength));
00597         stream->nextPutAll(segment);
00598         if (buffer->at(segmentStart + segmentLength)->isEqual(Character::value('D'))) {
00599             stream->nextPutAll("::~");
00600             stream->nextPutAll(segment);
00601         }
00602     }
00603     if (buffer == this) {
00604         /* Can't demangle */
00605         return this;
00606     }
00607     stream->nextPutAll("()");
00608 
00609     return dynamic_cast<String *>(stream->contents());
00610 #else
00611     /* Don't know how to demangle */
00612     return this;
00613 #endif
00614 }

bool String::endsWith const char *  str  )  const [virtual]
 

Definition at line 540 of file String.cc.

References endsWith(), and String().

00541 {
00542     return endsWith(new String(str));
00543 }

virtual bool Core::String::endsWith SequenceableCollection coll  )  const [inline, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 202 of file String.h.

References Core::SequenceableCollection::endsWith().

Referenced by endsWith().

00203       { return SequenceableCollection::endsWith(coll); }

String * String::format const char *  format,
  ...
[static]
 

Same as format(const String* format, .

..). Provide for convenience.

See also:
format(const String* format, ...)

Definition at line 353 of file String.cc.

References formatArgumentsIntoString().

00354 {
00355     String *result;
00356     va_list ap;
00357 
00358     va_start(ap, format);
00359     result = formatArgumentsIntoString(format, ap);
00360     va_end(ap);
00361 
00362     return result;
00363 }

String * String::format const String format,
  ...
[static]
 

Creates new String instace from formatted string.

  • format formatting string, use vsnprint syntax.
  • \... arguments to be formatted.
    Returns:
    new String with formatted content.
    See also:
    format(const char* format, ...)

Definition at line 365 of file String.cc.

References asCString(), and formatArgumentsIntoString().

Referenced by Core::Stream::print(), Core::Time::printOn(), Core::Date::printOn(), and Core::Character::printOn().

00366 {
00367     String *result;
00368     va_list ap;
00369 
00370     va_start(ap, format);
00371     result = formatArgumentsIntoString(format->asCString(), ap);
00372     va_end(ap);
00373     return result;
00374 }

String * String::formatArgumentsIntoString const char *  format,
va_list  args
[static, protected]
 

Definition at line 623 of file String.cc.

Referenced by format().

00624 {
00625     char buf[1025];
00626 
00627     vsnprintf(buf, 1024, format, args);
00628     return (new ByteArray(buf, strlen(buf)))->asString();
00629 }

long String::hash void   )  const [virtual]
 

Answer object hash value.

The value should be same for objects found equal with isEqual() method. So if you rewrite this method you should rewrite isEqual() method too.

Reimplemented from Core::Object.

Definition at line 221 of file String.cc.

References at(), and size().

00222 {
00223     long hashConst = 0x12345;
00224     int length = size();
00225 
00226     if (length > 0) {
00227         hashConst ^= ((Character *) at(0))->asInteger();
00228         if (length > 1) {
00229             hashConst ^= ((Character *) at(length-1))->asInteger();
00230             if (length > 3) {
00231                 hashConst ^= ((Character *) at(length/2-1))->asInteger()
00232                              ^ ((Character *) at(length/2+1))->asInteger();
00233             }
00234         }
00235     }
00236     return hashConst;
00237 }

bool String::includes const char  element  )  [virtual]
 

Definition at line 515 of file String.cc.

References includes(), and Core::Character::value().

00516 {
00517     return includes(Character::value(element));
00518 }

virtual bool Core::String::includes Object object  )  [inline, virtual]
 

Reimplemented from Core::Collection.

Definition at line 184 of file String.h.

References Core::Collection::includes().

Referenced by includes(), Tools::Filename::privFilesMatchingAccessList(), and trimBlanks().

00185       { return SequenceableCollection::includes(object); }

virtual bool Core::String::includesSubcollection const char *  coll  )  const [inline, virtual]
 

Definition at line 189 of file String.h.

References Core::SequenceableCollection::includesSubcollection(), and String().

virtual bool Core::String::includesSubcollection SequenceableCollection coll  )  const [inline, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 187 of file String.h.

References Core::SequenceableCollection::includesSubcollection().

Referenced by Net::URL::fromString().

long String::indexOf const char  obj  )  const [virtual]
 

Definition at line 183 of file String.cc.

References Core::SequenceableCollection::indexOf(), and Core::Character::value().

00184 {
00185     return SequenceableCollection::indexOf(Character::value(obj));
00186 }

virtual long Core::String::indexOf Object obj  )  const [inline, virtual]
 

Finds first index of element in a collection.

If none found returns -1.

Reimplemented from Core::SequenceableCollection.

Definition at line 100 of file String.h.

References Core::SequenceableCollection::indexOf().

Referenced by Net::URL::fromString(), Tools::HierarchicalConfigurationReader::getConfigurationFor(), Tools::HierarchicalConfigurationReader::parseLine(), Core::GenericException::printStackOn(), Tools::HierarchicalConfigurationReader::readLine(), and Tools::ConfigurationReader::readLine().

00101       { return SequenceableCollection::indexOf(obj); }

bool String::isByteString void   )  const [virtual]
 

Definition at line 545 of file String.cc.

References implementor, and Core::StringImpl::isByteString().

00546 {
00547     return implementor->isByteString();
00548 }

bool String::isCharacterArray void   )  const [virtual]
 

Definition at line 555 of file String.cc.

References implementor, and Core::StringImpl::isCharacterArray().

00556 {
00557     return implementor->isCharacterArray();
00558 }

bool String::isDigitString void   )  [virtual]
 

Answers if the string contains only decimal digits.

Definition at line 525 of file String.cc.

References at(), and size().

00526 {
00527     long length = size();
00528     for (long i = 0; i < length; i++) {
00529         if (!((Character *) at(i))->isDigit())
00530             return false;
00531     }
00532     return true;
00533 }

bool String::isEqual const char *  string  )  const [virtual]
 

Definition at line 259 of file String.cc.

References at(), isEqual(), and size().

00260 {
00261     long i, length = size();
00262     for (i = 0; i < length && string[i] != 0; i++) {
00263         if (!((Character *) at(i))->isEqual(string[i]))
00264             return false;
00265     }
00266     if (i < length || string[i] != 0) return false;
00267     return true;
00268 }

virtual bool Core::String::isEqual const Object object  )  const [inline, virtual]
 

Compare receiver with given object.

Do not rewrite this method. It just a sugar for Object::isEqual(Object *).

  • object - object to compare receiver with

Reimplemented from Core::Object.

Definition at line 120 of file String.h.

References Core::Object::isEqual().

00121       { return SequenceableCollection::isEqual(object); }

bool String::isEqual const Object object  )  const [virtual]
 

Compare receiver with given object.

This method could compare objects with more sophisticated algorithm (eg. based on instance variables comparing or so).

If you rewrite this method you should rewrite hash() too.

  • object - object to compare receiver with

Reimplemented from Core::Object.

Definition at line 239 of file String.cc.

References implementor, Core::StringImpl::isEqual(), Core::Object::isString(), and size().

Referenced by Core::EncodedStreamFactory::EncodedStreamFactory(), isEqual(), and Core::Object::isInstanceOf().

00240 {
00241 /*    long length = size();
00242     if (object->isString() &&
00243         length == ((String *) object)->size()) {
00244         String *charArray = (String *) object;
00245         for (long i = 0; i < length; i++) {
00246             if (!at(i)->isEqual(charArray->at(i)))
00247                 return false;
00248         }
00249         return true;
00250     }
00251     return false;
00252 */
00253     if (!object->isString()) return false;
00254     String *otherOne = (String *) object;
00255     if (otherOne->size() != this->size()) return false;
00256     return this->implementor->isEqual(otherOne->implementor);
00257 }

bool String::isString void   )  const [virtual]
 

Answer if the receiver is a String.

Reimplemented from Core::Object.

Definition at line 520 of file String.cc.

00521 {
00522     return true;
00523 }

bool String::isTwoByteString void   )  const [virtual]
 

Definition at line 550 of file String.cc.

References implementor, and Core::StringImpl::isTwoByteString().

00551 {
00552     return implementor->isTwoByteString();
00553 }

long String::lastIndexOf const char  obj  )  const [virtual]
 

Definition at line 188 of file String.cc.

References Core::SequenceableCollection::lastIndexOf(), and Core::Character::value().

00189 {
00190     return SequenceableCollection::lastIndexOf(Character::value(obj));
00191 }

virtual long Core::String::lastIndexOf Object obj  )  const [inline, virtual]
 

Finds last index of element in a collection.

If none found returns -1.

Reimplemented from Core::SequenceableCollection.

Definition at line 103 of file String.h.

References Core::SequenceableCollection::lastIndexOf().

Referenced by Tools::Filename::extension(), and Tools::HierarchicalConfigurationReader::parseAssignment().

00104       { return SequenceableCollection::lastIndexOf(obj); }

bool String::match const char *  string,
bool  ignoreCase
[virtual]
 

Definition at line 285 of file String.cc.

References String().

00286 {
00287     return (new String(str))->matchesPattern(this, ignoreCase);
00288 }

bool String::match String string,
bool  ignoreCase
[virtual]
 

Definition at line 280 of file String.cc.

References matchesPattern().

00281 {
00282     return str->matchesPattern(this, ignoreCase);
00283 }

bool String::match const char *  string  )  [virtual]
 

Definition at line 275 of file String.cc.

References match(), and String().

00276 {
00277     return match(new String(string), true);
00278 }

bool String::match String string  )  [virtual]
 

Answer whether a String matches the pattern in the receiver.

Matching ignores upper/lower case differences. Where the receiver contains #, a String may contain any single character. Where the receiver contains *, a String may contain any sequence of characters.

Examples:

  (new String("xyz"))->match(new String("Xyz")) == true
  (new String("x#z"))->match(new String("x@z")) == true 
  (new String("x*z"))->match(new String("x whyNot? z")) == true
  (new String("*x"))->match(new String("xx")) == true
  

Definition at line 270 of file String.cc.

Referenced by match(), and Tools::Filename::privFilesMatchingAccessList().

00271 {
00272     return match(str, true);
00273 }

bool String::matchesPattern String string,
bool  ignoreCase
[virtual]
 

Definition at line 290 of file String.cc.

References Core::Character::asUppercase(), at(), Core::Character::isEqual(), and size().

Referenced by match().

00291 {
00292     long stringSize, stringIndex, stringStartScan;
00293     long patternSize, patternIndex, patternStartScan;
00294 
00295     stringSize = size();
00296     stringIndex = 0;
00297     patternSize = pattern->size();
00298     patternIndex = 0;
00299     stringStartScan = -1;
00300     patternStartScan = 0;
00301 
00302     while (patternIndex < patternSize) {
00303         Character *p = (Character *) pattern->at(patternIndex);
00304         patternIndex++;
00305         if (p->isEqual('*')) {
00306             /* We found a successful match after the last *, if any. */
00307             if (patternIndex >= patternSize)
00308                 return true;
00309             stringStartScan = stringIndex;
00310             patternStartScan = patternIndex;
00311         } else {
00312             if (stringIndex >= stringSize)
00313                 return false;
00314             Character *t = (Character *) at(stringIndex);
00315             stringIndex++;
00316             if (t->isEqual(p) || p->isEqual('#') ||
00317                 (ignoreCase && t->asUppercase()->isEqual(p->asUppercase()))) {
00318                 if (patternIndex >= patternSize && stringIndex < stringSize) {
00319                     if (stringStartScan < 0)
00320                         return false;
00321                     stringIndex = stringIndex + patternStartScan - patternIndex + 1;
00322                     patternIndex = patternStartScan;
00323                 }
00324             } else {
00325                 if (stringStartScan < 0)
00326                     return false;
00327                 stringIndex = stringIndex + patternStartScan - patternIndex + 1;
00328                 patternIndex = patternStartScan;
00329             }
00330         }
00331     }
00332 
00333     if (stringIndex < stringSize)
00334         return false;
00335     return true;
00336 }

long String::nextIndexOf const char  element,
long  startIndex,
long  stopIndex
const [virtual]
 

Definition at line 193 of file String.cc.

References Core::SequenceableCollection::nextIndexOf(), and Core::Character::value().

00194 {
00195     return SequenceableCollection::nextIndexOf(Character::value(element),
00196                                                startIndex, stopIndex);
00197 }

virtual long Core::String::nextIndexOf Object element,
long  startIndex,
long  stopIndex
const [inline, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 106 of file String.h.

References Core::SequenceableCollection::nextIndexOf().

Referenced by Core::GenericException::printStackOn().

00107       { return SequenceableCollection::nextIndexOf(element, startIndex, stopIndex); }

String::operator char * void   )  const [virtual]
 

Definition at line 376 of file String.cc.

References asCString().

00377 {
00378     return asCString();
00379 }

String & String::operator+ const char *  string  )  [virtual]
 

Definition at line 491 of file String.cc.

References concatenateWith().

00492 {
00493     return *concatenateWith(string);
00494 }

SequenceableCollection & String::operator+ SequenceableCollection collection  )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 486 of file String.cc.

References Core::SequenceableCollection::copyReplace(), and size().

00487 {
00488     return *copyReplace(size(), size(), &collection);
00489 }

long String::prevIndexOf const char  element,
long  startIndex,
long  stopIndex
const [virtual]
 

Definition at line 199 of file String.cc.

References Core::SequenceableCollection::prevIndexOf(), and Core::Character::value().

00200 {
00201     return SequenceableCollection::prevIndexOf(Character::value(element),
00202                                                startIndex, stopIndex);
00203 }

virtual long Core::String::prevIndexOf Object element,
long  startIndex,
long  stopIndex
const [inline, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 109 of file String.h.

References Core::SequenceableCollection::prevIndexOf().

00110       { return SequenceableCollection::prevIndexOf(element, startIndex, stopIndex); }

void String::printOn Stream stream  )  const [virtual]
 

Print object identification into the stream.

Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.

  • stream - stream to print to.

Reimplemented from Core::Collection.

Definition at line 507 of file String.cc.

References Core::Stream::nextPut(), and Core::Stream::nextPutAll().

00508 {
00509     stream->nextPut('\"');
00510     stream->nextPutAll(this);
00511     stream->nextPut('\"');
00512 }

void String::put int  index,
char  obj
[virtual]
 

Definition at line 173 of file String.cc.

References put(), and Core::Character::value().

00174 {
00175     put(index, Character::value(obj));
00176 }

void String::put int  index,
Object obj
[virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 155 of file String.cc.

References Core::StringImpl::byteSize(), Core::Character::byteSize(), changeWideToFit(), Core::Object::error(), implementor, Core::Object::isCharacter(), nil, Core::StringImpl::put(), size(), and String().

Referenced by asLowercase(), asUppercase(), asUppercaseFirst(), put(), String(), with(), and withAll().

00156 {
00157     if (obj == nil || !obj->isCharacter()) {
00158         error(new String("String stores only Characters."),
00159               new String(__PRETTY_FUNCTION__), obj);
00160     }
00161     if (index < 0 || index >= size())
00162         (new SubscriptOutOfBoundsError(__PRETTY_FUNCTION__, index))->raiseFrom(this);
00163 
00164     Character *chr = dynamic_cast<Character *>(obj);
00165 
00166     if (chr->byteSize() > implementor->byteSize()) {
00167         changeWideToFit(chr->byteSize());
00168     }
00169 
00170     implementor->put(index, chr);
00171 }

long String::size void   )  const [virtual]
 

Answer how many elements the collection includes.

Reimplemented from Core::SequenceableCollection.

Definition at line 178 of file String.cc.

References implementor, and Core::StringImpl::size().

Referenced by asArrayOfSubstringsSeparatedBy(), asCString(), asLowercase(), asUppercase(), asUppercaseFirst(), at(), concatenateWith(), Tools::Filename::constructString(), demangleMethodName(), Tools::Filename::extension(), Net::URL::fromString(), Core::ByteArray::fromStringEncoding(), Tools::HierarchicalConfigurationReader::getConfigurationFor(), hash(), isDigitString(), isEqual(), matchesPattern(), operator+(), Tools::HierarchicalConfigurationReader::parseAssignment(), Net::URL::parseHost(), Core::GenericException::printStackOn(), put(), Tools::HierarchicalConfigurationReader::readLine(), Tools::ConfigurationReader::readLine(), String(), Tools::Filename::tail(), and trimBlanks().

00179 {
00180     return implementor->size();
00181 }

bool String::startsWith const char *  str  )  const [virtual]
 

Definition at line 535 of file String.cc.

References startsWith(), and String().

00536 {
00537     return startsWith(new String(str));
00538 }

virtual bool Core::String::startsWith SequenceableCollection coll  )  const [inline, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 199 of file String.h.

References Core::SequenceableCollection::startsWith().

Referenced by Core::ByteCharacterEncoder::integerValueFrom(), and startsWith().

00200       { return SequenceableCollection::startsWith(coll); }

String * String::trimBlanks void   )  [virtual]
 

Definition at line 561 of file String.cc.

References copy(), includes(), size(), and String().

Referenced by Tools::HierarchicalConfigurationReader::parseAssignment(), Tools::HierarchicalConfigurationReader::parseLine(), and Tools::ConfigurationReader::readLine().

00562 {
00563     String *separators = new String(" \t\n\r");
00564     long index = 0, length = size();
00565 
00566     if (length == 0) return this;
00567     while (index < length && separators->includes(this->at(index)))
00568         index++;
00569     while (index < length && separators->includes(this->at(length-1)))
00570         length--;
00571     if (index == length) return new String;
00572     if (index == 0 && length == size()) return this;
00573     return dynamic_cast<String *>(copy(index, length));
00574 }

void String::visitBy Visitor visitor  )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 617 of file String.cc.

00618 {
00619     visitor->visitString(this);
00620 }

String * String::with Character obj1,
Character obj2,
Character obj3,
Character obj4
[static]
 

Definition at line 127 of file String.cc.

References put(), and String().

00128 {
00129     String *newString = new String(4);
00130     newString->put(0, obj1);
00131     newString->put(1, obj2);
00132     newString->put(2, obj3);
00133     newString->put(3, obj4);
00134     return newString;
00135 }

String * String::with Character obj1,
Character obj2,
Character obj3
[static]
 

Definition at line 118 of file String.cc.

References put(), and String().

00119 {
00120     String *newString = new String(3);
00121     newString->put(0, obj1);
00122     newString->put(1, obj2);
00123     newString->put(2, obj3);
00124     return newString;
00125 }

String * String::with Character obj1,
Character obj2
[static]
 

Definition at line 110 of file String.cc.

References put(), and String().

00111 {
00112     String *newString = new String(2);
00113     newString->put(0, obj1);
00114     newString->put(1, obj2);
00115     return newString;
00116 }

String * String::with Character object  )  [static]
 

Definition at line 103 of file String.cc.

References put(), and String().

00104 {
00105     String *newString = new String(1);
00106     newString->put(0, object);
00107     return newString;
00108 }

String * String::withAll Collection coll  )  [static]
 

Definition at line 137 of file String.cc.

References put(), and String().

00138 {
00139     String *newString = new String(coll->size());
00140     int index = 0;
00141     for (Iterator *i = coll->iterator(); !i->finished(); i->next()) {
00142         newString->put(index++, i->value());
00143     }
00144     return newString;
00145 }


Member Data Documentation

StringImpl* Core::String::implementor [protected]
 

Definition at line 50 of file String.h.

Referenced by at(), changeSize(), changeWideToFit(), isByteString(), isCharacterArray(), isEqual(), isTwoByteString(), put(), size(), String(), and ~String().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:52:01 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2