Back to index

lightning-sunbird  0.9+nobinonly
nsString.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et cindent: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla.
00017  *
00018  * The Initial Developer of the Original Code is IBM Corporation.
00019  * Portions created by IBM Corporation are Copyright (C) 2003
00020  * IBM Corporation. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Darin Fisher <darin@meer.net>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsString_h___
00040 #define nsString_h___
00041 
00042 
00043 #ifndef nsSubstring_h___
00044 #include "nsSubstring.h"
00045 #endif
00046 
00047 #ifndef nsDependentSubstring_h___
00048 #include "nsDependentSubstring.h"
00049 #endif
00050 
00051 #ifndef nsReadableUtils_h___
00052 #include "nsReadableUtils.h"
00053 #endif
00054 
00055 #include NEW_H
00056 
00057   // enable support for the obsolete string API if not explicitly disabled
00058 #ifndef MOZ_STRING_WITH_OBSOLETE_API
00059 #define MOZ_STRING_WITH_OBSOLETE_API 1
00060 #endif
00061 
00062 #if MOZ_STRING_WITH_OBSOLETE_API
00063   // radix values for ToInteger/AppendInt
00064 #define kRadix10        (10)
00065 #define kRadix16        (16)
00066 #define kAutoDetect     (100)
00067 #define kRadixUnknown   (kAutoDetect+1)
00068 #define IGNORE_CASE     (PR_TRUE)
00069 #endif
00070 
00071 
00072   // declare nsString, et. al.
00073 #include "string-template-def-unichar.h"
00074 #include "nsTString.h"
00075 #include "string-template-undef.h"
00076 
00077   // declare nsCString, et. al.
00078 #include "string-template-def-char.h"
00079 #include "nsTString.h"
00080 #include "string-template-undef.h"
00081 
00082 
00086 class NS_LossyConvertUTF16toASCII : public nsCAutoString
00087   {
00088     public:
00089       explicit
00090       NS_LossyConvertUTF16toASCII( const PRUnichar* aString )
00091         {
00092           LossyAppendUTF16toASCII(aString, *this);
00093         }
00094 
00095       NS_LossyConvertUTF16toASCII( const PRUnichar* aString, PRUint32 aLength )
00096         {
00097           LossyAppendUTF16toASCII(Substring(aString, aString + aLength), *this);
00098         }
00099 
00100       explicit
00101       NS_LossyConvertUTF16toASCII( const nsAString& aString )
00102         {
00103           LossyAppendUTF16toASCII(aString, *this);
00104         }
00105 
00106     private:
00107         // NOT TO BE IMPLEMENTED
00108       NS_LossyConvertUTF16toASCII( char );
00109   };
00110 
00111 
00112 class NS_ConvertASCIItoUTF16 : public nsAutoString
00113   {
00114     public:
00115       explicit
00116       NS_ConvertASCIItoUTF16( const char* aCString )
00117         {
00118           AppendASCIItoUTF16(aCString, *this);
00119         }
00120 
00121       NS_ConvertASCIItoUTF16( const char* aCString, PRUint32 aLength )
00122         {
00123           AppendASCIItoUTF16(Substring(aCString, aCString + aLength), *this);
00124         }
00125 
00126       explicit
00127       NS_ConvertASCIItoUTF16( const nsACString& aCString )
00128         {
00129           AppendASCIItoUTF16(aCString, *this);
00130         }
00131 
00132     private:
00133         // NOT TO BE IMPLEMENTED
00134       NS_ConvertASCIItoUTF16( PRUnichar );
00135   };
00136 
00137 
00141 class NS_ConvertUTF16toUTF8 : public nsCAutoString
00142   {
00143     public:
00144       explicit
00145       NS_ConvertUTF16toUTF8( const PRUnichar* aString )
00146         {
00147           AppendUTF16toUTF8(aString, *this);
00148         }
00149 
00150       NS_ConvertUTF16toUTF8( const PRUnichar* aString, PRUint32 aLength )
00151         {
00152           AppendUTF16toUTF8(Substring(aString, aString + aLength), *this);
00153         }
00154 
00155       explicit
00156       NS_ConvertUTF16toUTF8( const nsAString& aString )
00157         {
00158           AppendUTF16toUTF8(aString, *this);
00159         }
00160 
00161     private:
00162         // NOT TO BE IMPLEMENTED
00163       NS_ConvertUTF16toUTF8( char );
00164   };
00165 
00166 
00167 class NS_ConvertUTF8toUTF16 : public nsAutoString
00168   {
00169     public:
00170       explicit
00171       NS_ConvertUTF8toUTF16( const char* aCString )
00172         {
00173           AppendUTF8toUTF16(aCString, *this);
00174         }
00175 
00176       NS_ConvertUTF8toUTF16( const char* aCString, PRUint32 aLength )
00177         {
00178           AppendUTF8toUTF16(Substring(aCString, aCString + aLength), *this);
00179         }
00180 
00181       explicit
00182       NS_ConvertUTF8toUTF16( const nsACString& aCString )
00183         {
00184           AppendUTF8toUTF16(aCString, *this);
00185         }
00186 
00187     private:
00188         // NOT TO BE IMPLEMENTED
00189       NS_ConvertUTF8toUTF16( PRUnichar );
00190   };
00191 
00192 
00193 // the following are included/declared for backwards compatibility
00194 
00195 typedef NS_ConvertUTF16toUTF8 NS_ConvertUCS2toUTF8;
00196 typedef NS_LossyConvertUTF16toASCII NS_LossyConvertUCS2toASCII;
00197 typedef NS_ConvertASCIItoUTF16 NS_ConvertASCIItoUCS2;
00198 typedef NS_ConvertUTF8toUTF16 NS_ConvertUTF8toUCS2;
00199 typedef nsAutoString nsVoidableString;
00200 
00201 #ifndef nsDependentString_h___
00202 #include "nsDependentString.h"
00203 #endif
00204 
00205 #ifndef nsLiteralString_h___
00206 #include "nsLiteralString.h"
00207 #endif
00208 
00209 #ifndef nsPromiseFlatString_h___
00210 #include "nsPromiseFlatString.h"
00211 #endif
00212 
00213 // need to include these for backwards compatibility
00214 #include "nsMemory.h"
00215 #include <string.h>
00216 #include <stdio.h>
00217 #include "plhash.h"
00218 
00219 inline PRInt32 MinInt(PRInt32 x, PRInt32 y)
00220   {
00221     return NS_MIN(x, y);
00222   }
00223 
00224 inline PRInt32 MaxInt(PRInt32 x, PRInt32 y)
00225   {
00226     return NS_MAX(x, y);
00227   }
00228 
00234 inline void Recycle( char* aBuffer) { nsMemory::Free(aBuffer); }
00235 inline void Recycle( PRUnichar* aBuffer) { nsMemory::Free(aBuffer); }
00236 
00237 #endif // !defined(nsString_h___)