xpcom/string/public/nsString.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/string/public/nsString.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,215 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsString_h___
    1.11 +#define nsString_h___
    1.12 +
    1.13 +#include "mozilla/Attributes.h"
    1.14 +
    1.15 +#include "nsSubstring.h"
    1.16 +#include "nsDependentSubstring.h"
    1.17 +#include "nsReadableUtils.h"
    1.18 +
    1.19 +#include <new>
    1.20 +
    1.21 +  // enable support for the obsolete string API if not explicitly disabled
    1.22 +#ifndef MOZ_STRING_WITH_OBSOLETE_API
    1.23 +#define MOZ_STRING_WITH_OBSOLETE_API 1
    1.24 +#endif
    1.25 +
    1.26 +#if MOZ_STRING_WITH_OBSOLETE_API
    1.27 +  // radix values for ToInteger/AppendInt
    1.28 +#define kRadix10        (10)
    1.29 +#define kRadix16        (16)
    1.30 +#define kAutoDetect     (100)
    1.31 +#define kRadixUnknown   (kAutoDetect+1)
    1.32 +#define IGNORE_CASE     (true)
    1.33 +#endif
    1.34 +
    1.35 +
    1.36 +  // declare nsString, et. al.
    1.37 +#include "string-template-def-unichar.h"
    1.38 +#include "nsTString.h"
    1.39 +#include "string-template-undef.h"
    1.40 +
    1.41 +  // declare nsCString, et. al.
    1.42 +#include "string-template-def-char.h"
    1.43 +#include "nsTString.h"
    1.44 +#include "string-template-undef.h"
    1.45 +
    1.46 +static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
    1.47 +static_assert(sizeof(nsString::char_type) == 2,
    1.48 +              "size of nsString::char_type must be 2");
    1.49 +static_assert(nsString::char_type(-1) > nsString::char_type(0),
    1.50 +              "nsString::char_type must be unsigned");
    1.51 +static_assert(sizeof(nsCString::char_type) == 1,
    1.52 +              "size of nsCString::char_type must be 1");
    1.53 +
    1.54 +
    1.55 +  /**
    1.56 +   * A helper class that converts a UTF-16 string to ASCII in a lossy manner
    1.57 +   */
    1.58 +class NS_LossyConvertUTF16toASCII : public nsAutoCString
    1.59 +  {
    1.60 +    public:
    1.61 +      explicit
    1.62 +      NS_LossyConvertUTF16toASCII( const char16_t* aString )
    1.63 +        {
    1.64 +          LossyAppendUTF16toASCII(aString, *this);
    1.65 +        }
    1.66 +
    1.67 +      NS_LossyConvertUTF16toASCII( const char16_t* aString, uint32_t aLength )
    1.68 +        {
    1.69 +          LossyAppendUTF16toASCII(Substring(aString, aLength), *this);
    1.70 +        }
    1.71 +
    1.72 +#ifdef MOZ_USE_CHAR16_WRAPPER
    1.73 +      explicit
    1.74 +      NS_LossyConvertUTF16toASCII( char16ptr_t aString )
    1.75 +        : NS_LossyConvertUTF16toASCII(static_cast<const char16_t*>(aString)) {}
    1.76 +
    1.77 +      NS_LossyConvertUTF16toASCII( char16ptr_t aString, uint32_t aLength )
    1.78 +        : NS_LossyConvertUTF16toASCII(static_cast<const char16_t*>(aString), aLength) {}
    1.79 +#endif
    1.80 +
    1.81 +      explicit
    1.82 +      NS_LossyConvertUTF16toASCII( const nsAString& aString )
    1.83 +        {
    1.84 +          LossyAppendUTF16toASCII(aString, *this);
    1.85 +        }
    1.86 +
    1.87 +    private:
    1.88 +        // NOT TO BE IMPLEMENTED
    1.89 +      NS_LossyConvertUTF16toASCII( char );
    1.90 +  };
    1.91 +
    1.92 +
    1.93 +class NS_ConvertASCIItoUTF16 : public nsAutoString
    1.94 +  {
    1.95 +    public:
    1.96 +      explicit
    1.97 +      NS_ConvertASCIItoUTF16( const char* aCString )
    1.98 +        {
    1.99 +          AppendASCIItoUTF16(aCString, *this);
   1.100 +        }
   1.101 +
   1.102 +      NS_ConvertASCIItoUTF16( const char* aCString, uint32_t aLength )
   1.103 +        {
   1.104 +          AppendASCIItoUTF16(Substring(aCString, aLength), *this);
   1.105 +        }
   1.106 +
   1.107 +      explicit
   1.108 +      NS_ConvertASCIItoUTF16( const nsACString& aCString )
   1.109 +        {
   1.110 +          AppendASCIItoUTF16(aCString, *this);
   1.111 +        }
   1.112 +
   1.113 +    private:
   1.114 +        // NOT TO BE IMPLEMENTED
   1.115 +      NS_ConvertASCIItoUTF16( char16_t );
   1.116 +  };
   1.117 +
   1.118 +
   1.119 +  /**
   1.120 +   * A helper class that converts a UTF-16 string to UTF-8
   1.121 +   */
   1.122 +class NS_ConvertUTF16toUTF8 : public nsAutoCString
   1.123 +  {
   1.124 +    public:
   1.125 +      explicit
   1.126 +      NS_ConvertUTF16toUTF8( const char16_t* aString )
   1.127 +        {
   1.128 +          AppendUTF16toUTF8(aString, *this);
   1.129 +        }
   1.130 +
   1.131 +      NS_ConvertUTF16toUTF8( const char16_t* aString, uint32_t aLength )
   1.132 +        {
   1.133 +          AppendUTF16toUTF8(Substring(aString, aLength), *this);
   1.134 +        }
   1.135 +
   1.136 +#ifdef MOZ_USE_CHAR16_WRAPPER
   1.137 +      NS_ConvertUTF16toUTF8( char16ptr_t aString ) : NS_ConvertUTF16toUTF8(static_cast<const char16_t*>(aString)) {}
   1.138 +
   1.139 +      NS_ConvertUTF16toUTF8( char16ptr_t aString, uint32_t aLength )
   1.140 +        : NS_ConvertUTF16toUTF8(static_cast<const char16_t*>(aString), aLength) {}
   1.141 +#endif
   1.142 +
   1.143 +      explicit
   1.144 +      NS_ConvertUTF16toUTF8( const nsAString& aString )
   1.145 +        {
   1.146 +          AppendUTF16toUTF8(aString, *this);
   1.147 +        }
   1.148 +
   1.149 +    private:
   1.150 +        // NOT TO BE IMPLEMENTED
   1.151 +      NS_ConvertUTF16toUTF8( char );
   1.152 +  };
   1.153 +
   1.154 +
   1.155 +class NS_ConvertUTF8toUTF16 : public nsAutoString
   1.156 +  {
   1.157 +    public:
   1.158 +      explicit
   1.159 +      NS_ConvertUTF8toUTF16( const char* aCString )
   1.160 +        {
   1.161 +          AppendUTF8toUTF16(aCString, *this);
   1.162 +        }
   1.163 +
   1.164 +      NS_ConvertUTF8toUTF16( const char* aCString, uint32_t aLength )
   1.165 +        {
   1.166 +          AppendUTF8toUTF16(Substring(aCString, aLength), *this);
   1.167 +        }
   1.168 +
   1.169 +      explicit
   1.170 +      NS_ConvertUTF8toUTF16( const nsACString& aCString )
   1.171 +        {
   1.172 +          AppendUTF8toUTF16(aCString, *this);
   1.173 +        }
   1.174 +
   1.175 +    private:
   1.176 +        // NOT TO BE IMPLEMENTED
   1.177 +      NS_ConvertUTF8toUTF16( char16_t );
   1.178 +  };
   1.179 +
   1.180 +
   1.181 +#ifdef MOZ_USE_CHAR16_WRAPPER
   1.182 +
   1.183 +inline char16_t*
   1.184 +wwc(wchar_t *str)
   1.185 +{
   1.186 +    return reinterpret_cast<char16_t*>(str);
   1.187 +}
   1.188 +
   1.189 +inline wchar_t*
   1.190 +wwc(char16_t *str)
   1.191 +{
   1.192 +    return reinterpret_cast<wchar_t*>(str);
   1.193 +}
   1.194 +
   1.195 +#else
   1.196 +
   1.197 +inline char16_t*
   1.198 +wwc(char16_t *str)
   1.199 +{
   1.200 +    return str;
   1.201 +}
   1.202 +
   1.203 +#endif
   1.204 +
   1.205 +// the following are included/declared for backwards compatibility
   1.206 +typedef nsAutoString nsVoidableString;
   1.207 +
   1.208 +#include "nsDependentString.h"
   1.209 +#include "nsLiteralString.h"
   1.210 +#include "nsPromiseFlatString.h"
   1.211 +
   1.212 +// need to include these for backwards compatibility
   1.213 +#include "nsMemory.h"
   1.214 +#include <string.h>
   1.215 +#include <stdio.h>
   1.216 +#include "plhash.h"
   1.217 +
   1.218 +#endif // !defined(nsString_h___)

mercurial