osncore/osncore/src/ustring.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  utf8 encoded byte container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <osn/ustring.h>
       
    20 #include <osn/osnnew.h> 
       
    21 #include "ustringimpl.h"
       
    22 
       
    23 
       
    24 namespace osncore
       
    25 {
       
    26 static const char* const KInvalidUtf8 = "InvalidUtf8";
       
    27 // -------------------------------------------------------------------------
       
    28 // -------------------------------------------------------------------------
       
    29 //
       
    30 OSN_EXPORT const char* UString::InvalidUtf8::what()const throw()
       
    31     {
       
    32     return KInvalidUtf8;
       
    33     }
       
    34     
       
    35 // -------------------------------------------------------------------------
       
    36 // -------------------------------------------------------------------------
       
    37 //
       
    38 OSN_EXPORT UString::UString():mImpl(new(EMM)UStringImpl())
       
    39     {
       
    40 
       
    41     }
       
    42 	
       
    43 // -------------------------------------------------------------------------
       
    44 // -------------------------------------------------------------------------
       
    45 //
       
    46 OSN_EXPORT UString::UString(const Utf8* aStr)
       
    47     :mImpl(new(EMM)UStringImpl(aStr))
       
    48     {
       
    49 	
       
    50     }
       
    51 
       
    52 // -------------------------------------------------------------------------
       
    53 // -------------------------------------------------------------------------
       
    54 //
       
    55 OSN_EXPORT UString::UString(const Utf8* aStr, int aLen)
       
    56     :mImpl(new(EMM)UStringImpl(aStr, aLen))
       
    57     {
       
    58         
       
    59     }
       
    60 
       
    61 // -------------------------------------------------------------------------
       
    62 // -------------------------------------------------------------------------
       
    63 //
       
    64 OSN_EXPORT UString::UString(const UString& aUString)
       
    65     :mImpl(new(EMM)UStringImpl(*aUString.mImpl.get()))
       
    66     {
       
    67         
       
    68     }
       
    69     
       
    70 // -------------------------------------------------------------------------
       
    71 // -------------------------------------------------------------------------
       
    72 //
       
    73 OSN_EXPORT UString::UString(Unicode aCodePoint)
       
    74     :mImpl(new(EMM)UStringImpl(aCodePoint))
       
    75     {
       
    76         
       
    77     }
       
    78     
       
    79 // -------------------------------------------------------------------------
       
    80 // -------------------------------------------------------------------------
       
    81 //
       
    82 OSN_EXPORT UString& UString::operator=(const UString& aRhs)
       
    83     {
       
    84     if (this != &aRhs)
       
    85         {
       
    86         UStringImpl* tmp = new (EMM)UStringImpl(*aRhs.mImpl.get());
       
    87         mImpl.reset(tmp);
       
    88         }
       
    89         
       
    90     return *this;        
       
    91     }
       
    92 	
       
    93 // -------------------------------------------------------------------------
       
    94 // -------------------------------------------------------------------------
       
    95 //
       
    96 OSN_EXPORT UString& UString::operator=(const Utf8* aRhs)
       
    97     {
       
    98     if (aRhs)
       
    99         {
       
   100         UStringImpl* tmp = new (EMM)UStringImpl(aRhs);
       
   101         mImpl.reset(tmp);
       
   102         }
       
   103         
       
   104     return *this;       
       
   105     }
       
   106 	
       
   107 // -------------------------------------------------------------------------
       
   108 // -------------------------------------------------------------------------
       
   109 //
       
   110 OSN_EXPORT UString::~UString()
       
   111     {
       
   112 
       
   113     }	
       
   114 	
       
   115 // -------------------------------------------------------------------------
       
   116 // -------------------------------------------------------------------------
       
   117 //
       
   118 OSN_EXPORT bool UString::isEmpty()const
       
   119     {
       
   120     return mImpl->empty();
       
   121     }
       
   122 
       
   123 // -------------------------------------------------------------------------
       
   124 // -------------------------------------------------------------------------
       
   125 //
       
   126 OSN_EXPORT long UString::getCharLength()const
       
   127     {
       
   128     return mImpl->length();
       
   129     }
       
   130 
       
   131 // -------------------------------------------------------------------------
       
   132 // -------------------------------------------------------------------------
       
   133 //
       
   134 OSN_EXPORT long UString::getByteLength()const
       
   135     {
       
   136     return mImpl->bytes();
       
   137     }
       
   138 
       
   139 // -------------------------------------------------------------------------
       
   140 // -------------------------------------------------------------------------
       
   141 //
       
   142 OSN_EXPORT const Utf8* UString::getUtf8()const
       
   143     {
       
   144    	return mImpl->utf8();
       
   145     }
       
   146     
       
   147 // -------------------------------------------------------------------------
       
   148 // -------------------------------------------------------------------------
       
   149 //
       
   150 OSN_EXPORT int UString::compareC(const UString& aUString)const
       
   151     {
       
   152     return mImpl->compareC(*aUString.mImpl.get());
       
   153     }
       
   154     	
       
   155 // -------------------------------------------------------------------------
       
   156 // -------------------------------------------------------------------------
       
   157 //
       
   158 OSN_EXPORT int UString::compareC(const Utf8* aStr)const
       
   159     {
       
   160     return mImpl->compareC(aStr);
       
   161     }
       
   162     
       
   163 // -------------------------------------------------------------------------
       
   164 // -------------------------------------------------------------------------
       
   165 //
       
   166 OSN_EXPORT int UString::compare(const UString& aUString)const
       
   167     {
       
   168     return mImpl->compare(*aUString.mImpl.get());
       
   169     }
       
   170     	
       
   171 // -------------------------------------------------------------------------
       
   172 // -------------------------------------------------------------------------
       
   173 //
       
   174 OSN_EXPORT int UString::compare(const Utf8* aStr)const
       
   175     {
       
   176     return mImpl->compare(aStr);
       
   177     }    
       
   178 
       
   179 // -------------------------------------------------------------------------    	  
       
   180 // -------------------------------------------------------------------------
       
   181 //
       
   182 OSN_EXPORT bool UString::operator==(const UString& aRhs)const
       
   183     {
       
   184     return !mImpl->compare(*aRhs.mImpl.get());    
       
   185     }
       
   186     
       
   187 // -------------------------------------------------------------------------
       
   188 // -------------------------------------------------------------------------
       
   189 //
       
   190 OSN_EXPORT bool UString::operator==(const Utf8* aRhs)const
       
   191     {
       
   192     return !mImpl->compare(aRhs);    
       
   193     }
       
   194     
       
   195 // -------------------------------------------------------------------------
       
   196 // -------------------------------------------------------------------------
       
   197 //
       
   198 OSN_EXPORT void UString::append(const UString& aUString)
       
   199     {
       
   200     mImpl->append(*aUString.mImpl.get());
       
   201     }
       
   202 
       
   203 // -------------------------------------------------------------------------
       
   204 // -------------------------------------------------------------------------
       
   205 //
       
   206 OSN_EXPORT void UString::append(const Utf8* aStr)
       
   207     {
       
   208     mImpl->append(aStr);
       
   209     }   
       
   210 
       
   211 // -------------------------------------------------------------------------
       
   212 // -------------------------------------------------------------------------
       
   213 //
       
   214 OSN_EXPORT void UString::insert(
       
   215     long aPos, 
       
   216     const Utf8* aStr)
       
   217     {
       
   218     mImpl->insert(aPos, aStr);
       
   219     }
       
   220           
       
   221 // -------------------------------------------------------------------------
       
   222 // -------------------------------------------------------------------------
       
   223 //
       
   224 OSN_EXPORT void UString::insert(
       
   225     long aPos, 
       
   226     const Utf8* aStr,
       
   227     long aLength)
       
   228     {
       
   229     mImpl->insert(aPos, aStr,aLength);
       
   230     }  
       
   231      
       
   232 // -------------------------------------------------------------------------
       
   233 // -------------------------------------------------------------------------
       
   234 //
       
   235 OSN_EXPORT void UString::replace(
       
   236     long aPos, 
       
   237     const Utf8* aStr)
       
   238     {
       
   239     mImpl->replace(aPos, aStr);
       
   240     }   
       
   241 
       
   242 // -------------------------------------------------------------------------
       
   243 // -------------------------------------------------------------------------
       
   244 //
       
   245 OSN_EXPORT void UString::replace(
       
   246     long aPos, 
       
   247     const Utf8* aStr,
       
   248     long aLength)
       
   249     {
       
   250     mImpl->replace(aPos, aStr, aLength);
       
   251     }         
       
   252 
       
   253 // -------------------------------------------------------------------------
       
   254 // -------------------------------------------------------------------------
       
   255 //
       
   256 OSN_EXPORT void UString::erase(
       
   257     long aPos, 
       
   258     long aLength)
       
   259     {
       
   260     mImpl->erase(aPos, aLength);
       
   261     }         
       
   262 
       
   263 // -------------------------------------------------------------------------
       
   264 // -------------------------------------------------------------------------
       
   265 //
       
   266 OSN_EXPORT Unicode UString::operator[](long aIndex)
       
   267     {
       
   268     return mImpl->operator[](aIndex);
       
   269     }         
       
   270 
       
   271 // -------------------------------------------------------------------------
       
   272 // -------------------------------------------------------------------------
       
   273 //
       
   274 OSN_EXPORT bool UString::isNull()const
       
   275     {
       
   276     return mImpl->null();
       
   277     }
       
   278 }