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

StringImpl.cc

Go to the documentation of this file.
00001 /*
00002  * StringImpl.cc
00003  *
00004  * Smalltalk like class library for C++
00005  * Abstract string implementor.
00006  *
00007  * Copyright (c) 2004-6 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #include <stlib/StringImpl.h>
00025 #include <stlib/ByteArray.h>
00026 #include <stlib/ByteString.h>
00027 #include <stlib/Character.h>
00028 #include <stlib/CharacterArray.h>
00029 #include <stlib/EncodedStream.h>
00030 #include <stlib/InternalEncodedStreamFactory.h>
00031 #include <stlib/String.h>
00032 #include <stlib/TwoByteString.h>
00033 #include <stlib/Error.h>
00034 
00035 #include <string.h>
00036 
00037 using namespace Core;
00038 
00039 /* Accessing protocol */
00040 long StringImpl::size(void) const
00041 {
00042     return tally;
00043 }
00044 
00045 /* Converting protocol */
00046 ByteString *StringImpl::asByteString(void)
00047 {
00048     Character *ch;
00049     ByteString *newString = new ByteString(size());
00050     for (int i = 0; i < size(); i++) {
00051         ch = at(i);
00052         if (ch->byteSize() > 1) {
00053             error(new String("Can't convert String to ByteString. Characters out of range."),
00054                   new String(__PRETTY_FUNCTION__));
00055         }
00056         newString->put(i, at(i));
00057     }
00058     return newString;
00059 }
00060 
00061 TwoByteString *StringImpl::asTwoByteString(void)
00062 {
00063     Character *ch;
00064     TwoByteString *newString = new TwoByteString(size());
00065     for (int i = 0; i < size(); i++) {
00066         ch = at(i);
00067         if (ch->byteSize() > 1) {
00068             /* Can't convert to ByteString, keep this implementor */
00069             error(new String("Can't convert String to TwoByteString. Characters out of range."),
00070                   new String(__PRETTY_FUNCTION__));
00071         }
00072         newString->put(i, at(i));
00073     }
00074     return newString;
00075 }
00076 
00077 CharacterArray *StringImpl::asCharacterArray(void)
00078 {
00079     CharacterArray *newString = new CharacterArray(size());
00080     for (int i = 0; i < size(); i++) {
00081         newString->put(i, at(i));
00082     }
00083     return newString;
00084 }
00085 
00086 /* Testing protocol */
00087 bool StringImpl::isByteString(void) const
00088 {
00089     return false;
00090 }
00091 
00092 bool StringImpl::isTwoByteString(void) const
00093 {
00094     return false;
00095 }
00096 
00097 bool StringImpl::isCharacterArray(void) const
00098 {
00099     return false;
00100 }

Generated on Mon Nov 27 09:47:55 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2