epoc32/include/STRNG.INL
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Header STRNG.INL
    15 // 
    16 //
    17 
    18 inline String::String()
    19  :	iLength(0), iText(NULL)
    20 	{
    21 	}
    22 
    23 inline String::String(const char* aText)
    24  :	iLength(0), iText(NULL)
    25 	{
    26 	if (aText && CreateText(strlen(aText)))
    27 		{
    28 		CopyText(iText, aText, iLength);
    29 		iText[iLength] = '\0';
    30 		}
    31 	}
    32 
    33 inline String::String(int aLength,char* aText)
    34  :	iLength(0), iText(NULL)
    35 	{
    36 	if (aText && CreateText(aLength))
    37 		{
    38 		CopyText(iText, aText, aLength);
    39 		iText[iLength] = '\0';
    40 		}
    41 	}
    42 
    43 inline String::String(const String& aString)
    44  :	iLength(0), iText(NULL)
    45 	{
    46 	if (CreateText(aString.iLength))
    47 		{
    48 		CopyText(iText, aString.iText, iLength);
    49 		iText[iLength] = '\0';
    50 		}
    51 	}
    52 
    53 inline String& String::operator = (const char* aText)
    54 	{
    55 	char* text = iText;
    56 	if (CreateText(strlen(aText)))
    57 		{
    58 		CopyText(iText, aText, iLength);
    59 		iText[iLength] = '\0';
    60 		DeleteText(text);
    61 		}
    62 	return *this;
    63 	}
    64 
    65 inline String& String::operator = (const String& aString)
    66 	{
    67 	String string(aString);
    68 	char* text = iText;
    69 	if (CreateText(string.iLength))
    70 		{
    71 		CopyText(iText, string.iText, iLength);
    72 		iText[iLength] = '\0';
    73 		DeleteText(text);
    74 		}
    75 	return *this;
    76 	}
    77 
    78 inline String& String::operator += (const char aChar)
    79 	{
    80 	char* text = iText;
    81 	if (CreateText(iLength + 1))
    82 		{
    83 		CopyText(iText, text, iLength - 1);
    84 		iText[iLength - 1] = aChar;
    85 		iText[iLength] = '\0';
    86 		DeleteText(text);
    87 		}
    88 	return *this;
    89 	}
    90 
    91 inline String& String::operator += (const String& aString)
    92 	{
    93 	char* text = iText;
    94 	int length = iLength;
    95 	if (CreateText(length + aString.iLength))
    96 		{
    97 		CopyText(iText, text, length);
    98 		CopyText(iText + length, aString.iText, aString.iLength);
    99 		iText[iLength] = '\0';
   100 		DeleteText(text);
   101 		}
   102 	return *this;
   103 	}
   104 
   105 inline int String::operator == (const String& aString) const
   106 	{
   107 	boolean same = etrue;
   108 	if (iLength != aString.iLength)
   109 		same = efalse;
   110 	else
   111 		{
   112 		for (int i = 0; i < iLength; i++)
   113 			same = same && ((*this)[i] == aString[i]);
   114 		}
   115 	return same;
   116 	}
   117 
   118 inline char& String::operator [] (const int aNum) const
   119 	{
   120 	return iText[aNum];
   121 	}
   122 
   123 inline int String::Length() const
   124 	{
   125 	return iLength;
   126 	}
   127 
   128 inline const char* String::Text()
   129 	{
   130 	return iText;
   131 	}
   132 
   133 inline void String::CopyText(char* aDest, const char* aSource, int aLength) const
   134 	{
   135 	for (int i = 0; i < aLength; i++)
   136 		aDest[i] = aSource[i];
   137 	}