Back to index

lightning-sunbird  0.9+nobinonly
nsLiteralString.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Scott Collins <scc@mozilla.org> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or 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 nsLiteralString_h___
00040 #define nsLiteralString_h___
00041 
00042 #ifndef nscore_h___
00043 #include "nscore.h"
00044 #endif
00045 
00046 #ifndef nsDependentString_h___
00047 #include "nsDependentString.h"
00048 #endif
00049 
00050 
00051 #if 0
00052 inline
00053 const nsDependentString
00054 literal_string( const nsAString::char_type* aPtr )
00055   {
00056     return nsDependentString(aPtr);
00057   }
00058 
00059 inline
00060 const nsDependentString
00061 literal_string( const nsAString::char_type* aPtr, PRUint32 aLength )
00062   {
00063     return nsDependentString(aPtr, aLength);
00064   }
00065 
00066 inline
00067 const nsDependentCString
00068 literal_string( const nsACString::char_type* aPtr )
00069   {
00070     return nsDependentCString(aPtr);
00071   }
00072 
00073 inline
00074 const nsDependentCString
00075 literal_string( const nsACString::char_type* aPtr, PRUint32 aLength )
00076   {
00077     return nsDependentCString(aPtr, aLength);
00078   }
00079 #endif
00080 
00081 #ifdef HAVE_CPP_2BYTE_WCHAR_T
00082   #define NS_LL(s)                                L##s
00083   #define NS_MULTILINE_LITERAL_STRING(s)          nsDependentString(NS_REINTERPRET_CAST(const nsAString::char_type*, s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
00084   #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(NS_REINTERPRET_CAST(const nsAString::char_type*, s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
00085   #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(NS_REINTERPRET_CAST(const nsAString::char_type*, s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
00086   typedef nsDependentString nsLiteralString;
00087 #else
00088   #define NS_LL(s)                                s
00089   #define NS_MULTILINE_LITERAL_STRING(s)          NS_ConvertASCIItoUTF16(s, PRUint32(sizeof(s)-1))
00090   #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(s, PRUint32(sizeof(s)-1))
00091   #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const NS_ConvertASCIItoUTF16 n(s, PRUint32(sizeof(s)-1))
00092   typedef NS_ConvertASCIItoUTF16 nsLiteralString;
00093 #endif
00094 
00095 /*
00096  * Macro arguments used in concatenation or stringification won't be expanded.
00097  * Therefore, in order for |NS_L(FOO)| to work as expected (which is to expand
00098  * |FOO| before doing whatever |NS_L| needs to do to it) a helper macro needs
00099  * to be inserted in between to allow the macro argument to expand.
00100  * See "3.10.6 Separate Expansion of Macro Arguments" of the CPP manual for a
00101  * more accurate and precise explanation.
00102  */
00103 
00104 #define NS_L(s)                                   NS_LL(s)
00105 
00106 #define NS_LITERAL_STRING(s)                      NS_STATIC_CAST(const nsAFlatString&, NS_MULTILINE_LITERAL_STRING(NS_LL(s)))
00107 #define NS_LITERAL_STRING_INIT(n,s)               NS_MULTILINE_LITERAL_STRING_INIT(n, NS_LL(s))
00108 #define NS_NAMED_LITERAL_STRING(n,s)              NS_NAMED_MULTILINE_LITERAL_STRING(n, NS_LL(s))
00109 
00110 #define NS_LITERAL_CSTRING(s)                     NS_STATIC_CAST(const nsDependentCString&, nsDependentCString(s, PRUint32(sizeof(s)-1)))
00111 #define NS_LITERAL_CSTRING_INIT(n,s)              n(s, PRUint32(sizeof(s)-1))
00112 #define NS_NAMED_LITERAL_CSTRING(n,s)             const nsDependentCString n(s, PRUint32(sizeof(s)-1))
00113 
00114 typedef nsDependentCString nsLiteralCString;
00115 
00116 #endif /* !defined(nsLiteralString_h___) */