/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Implements a UTF-16 character type. */
#ifndef mozilla_Char16_h #define mozilla_Char16_h
#ifdef __cplusplus
/* * C++11 introduces a char16_t type and support for UTF-16 string and character * literals. C++11's char16_t is a distinct builtin type. Technically, char16_t * is a 16-bit code unit of a Unicode code point, not a "character".
*/
# ifdef WIN32 # define MOZ_USE_CHAR16_WRAPPER # include <cstdint> # include "mozilla/Attributes.h" /** * Win32 API extensively uses wchar_t, which is represented by a separated * builtin type than char16_t per spec. It's not the case for MSVC prior to * MSVC 2015, but other compilers follow the spec. We want to mix wchar_t and * char16_t on Windows builds. This class is supposed to make it easier. It * stores char16_t const pointer, but provides implicit casts for wchar_t as * well. On other platforms, we simply use * |typedef const char16_t* char16ptr_t|. Here, we want to make the class as * similar to this typedef, including providing some casts that are allowed * by the typedef.
*/ class char16ptr_t { private: const char16_t* mPtr;
static_assert(sizeof(char16_t) == sizeof(wchar_t), "char16_t and wchar_t sizes differ");
/** * Some Windows API calls accept BYTE* but require that data actually be * WCHAR*. Supporting this requires explicit operators to support the * requisite explicit casts.
*/ explicitoperatorconstchar*() const { returnreinterpret_cast<constchar*>(mPtr);
} explicitoperatorconstunsignedchar*() const { returnreinterpret_cast<constunsignedchar*>(mPtr);
} explicitoperatorunsignedchar*() const { returnconst_cast<unsignedchar*>( reinterpret_cast<constunsignedchar*>(mPtr));
} explicitoperatorvoid*() const { returnconst_cast<char16_t*>(mPtr); }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.