3ds Max C++ API Reference
Char Class Reference

Represents a single Unicode character. More...

#include <maxchar.h>

+ Inheritance diagram for Char:

Public Member Functions

 Char ()
 
 Char (char)
 Create a character with a single-byte Active Code Page character. More...
 
 Char (wchar_t)
 Create a character with a single-WCHAR UTF16 character. More...
 
 Char (const MaxString &)
 
 Char (const wchar_t *)
 
 Char (const char *)
 
 Char (unsigned int code_page, const char *)
 
 Char (unsigned int ch)
 Create a character using a UCS4 character. More...
 
MaxString ToMaxString () const
 Convert this character to a MaxString. More...
 
size_t ToUTF16 (wchar_t *string, size_t length) const
 Convert this character to UTF16. More...
 
size_t ToACP (char *string, size_t length) const
 Convert this character to the active code page. More...
 
size_t ToCP (unsigned int cp, char *string, size_t length) const
 Convert this character to the specified code page. More...
 
size_t ToMCHAR (MCHAR *s, size_t length) const
 Convert this character to an MCHAR (Active Code Page or UTF16). More...
 
bool operator== (char) const
 Compare this character to an active code page character. More...
 
bool operator== (wchar_t) const
 Compare this character to a UTF16 character. More...
 
bool operator== (const Char &) const
 Compare this character to a UTF16 character. More...
 
bool operator!= (char c) const
 Not equal operator for an active code page character. More...
 
bool operator!= (wchar_t c) const
 Not equal operator for a UTF16 character. More...
 
bool operator!= (const Char &c) const
 Not equal operator for a UTF16 character. More...
 
Charoperator= (wchar_t)
 Assignment operator for a UTF16 character. More...
 
Charoperator= (char)
 Assignment operator for an active code page character. More...
 
Charoperator= (const MaxString &)
 Assignment operator for a MaxString. More...
 
Charoperator= (const wchar_t *)
 Assignment operator for a constant UTF16 character. More...
 
Charoperator= (const char *)
 Assignment operator for a constant active code page character. More...
 
CharSet (unsigned int cp, const char *string)
 Change this character to represents the first character of the string specified, based on the code page specified. More...
 
bool IsNull () const
 Returns true if this character represents a NULL character. More...
 
bool IsValid () const
 Returns true if this character represents a non-NULL character. More...
 
unsigned int CharCode () const
 Returns the character as UTF32. More...
 
bool IsSpace () const
 
bool IsDigit () const
 
bool IsAlpha () const
 
bool IsAlphaNumeric () const
 
bool IsPunctuation () const
 
bool IsUnicode () const
 
Char ToUpper () const
 
Char ToLower () const
 
MCHARIsInCharacterSet (const MCHAR *) const
 Determine if this character is found inside a particular character set. More...
 

Static Public Member Functions

static bool IsValidUTF8 (const void *data, size_t len, bool *pFoundExtendedChar=0, size_t *pPartialCharAtEnd=0)
 Determine if the UTF-8 string is valid. More...
 
static unsigned int UTF8CharLength (unsigned char character)
 Determine the length of an UTF-8 character. More...
 
static bool IsUTF16LeadChar (wchar_t character)
 Determine if the UTF-16 char is a lead character. More...
 
- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Protected Attributes

unsigned int _ch
 

Detailed Description

Represents a single Unicode character.

The main advantage of this class is the ability of representing them without allocating external memory.

This class was designed to be able to cast "unsigned int*" array to a "Char*" array. This class doesn't have any destructor or virtual functions.

Constructor & Destructor Documentation

◆ Char() [1/8]

Char ( )

◆ Char() [2/8]

Char ( char  )

Create a character with a single-byte Active Code Page character.

This constructor is best used with a compile-time constant because if you specify a only the first half of a DBCS character this function will throw an exception.

◆ Char() [3/8]

Char ( wchar_t  )

Create a character with a single-WCHAR UTF16 character.

This constructor is best used with a compile-time constant because if you specify a only the first half of a UTF16 character this function will throw an exception.

◆ Char() [4/8]

Char ( const MaxString )

◆ Char() [5/8]

Char ( const wchar_t *  )

◆ Char() [6/8]

Char ( const char *  )

◆ Char() [7/8]

Char ( unsigned int  code_page,
const char *   
)

◆ Char() [8/8]

Char ( unsigned int  ch)
explicit

Create a character using a UCS4 character.

We specified "explicit" because "unsigned int" are so generic that we didn't want to construct a "Char" implicitly by mistake.

Member Function Documentation

◆ ToMaxString()

MaxString ToMaxString ( ) const

Convert this character to a MaxString.

◆ ToUTF16()

size_t ToUTF16 ( wchar_t *  string,
size_t  length 
) const

Convert this character to UTF16.

Parameters
stringstring buffer to put the converted characters
lengththe buffer size of param string in number characters
Returns
number of characters converted.

◆ ToACP()

size_t ToACP ( char *  string,
size_t  length 
) const

Convert this character to the active code page.

Parameters
string- string buffer to put the converted characters
length- the buffer size of param string in number characters
Returns
- number of characters converted.

◆ ToCP()

size_t ToCP ( unsigned int  cp,
char *  string,
size_t  length 
) const

Convert this character to the specified code page.

Parameters
cpThe specified code page
stringstring buffer to put the converted characters
lengththe buffer size of param string in number characters
Returns
number of characters converted.

◆ ToMCHAR()

size_t ToMCHAR ( MCHAR s,
size_t  length 
) const
inline

Convert this character to an MCHAR (Active Code Page or UTF16).

Parameters
sstring buffer to put the converted characters
lengththe buffer size of param s in number characters
Returns
number of characters converted.
121 { return ToUTF16(s, length); };
size_t ToUTF16(wchar_t *string, size_t length) const
Convert this character to UTF16.

◆ operator==() [1/3]

bool operator== ( char  ) const

Compare this character to an active code page character.

◆ operator==() [2/3]

bool operator== ( wchar_t  ) const

Compare this character to a UTF16 character.

◆ operator==() [3/3]

bool operator== ( const Char ) const

Compare this character to a UTF16 character.

◆ operator!=() [1/3]

bool operator!= ( char  c) const
inline

Not equal operator for an active code page character.

143 { return !(*this == c); }

◆ operator!=() [2/3]

bool operator!= ( wchar_t  c) const
inline

Not equal operator for a UTF16 character.

145 { return !(*this == c); }

◆ operator!=() [3/3]

bool operator!= ( const Char c) const
inline

Not equal operator for a UTF16 character.

147 { return !(*this == c); }

◆ operator=() [1/5]

Char& operator= ( wchar_t  )

Assignment operator for a UTF16 character.

◆ operator=() [2/5]

Char& operator= ( char  )

Assignment operator for an active code page character.

◆ operator=() [3/5]

Char& operator= ( const MaxString )

Assignment operator for a MaxString.

◆ operator=() [4/5]

Char& operator= ( const wchar_t *  )

Assignment operator for a constant UTF16 character.

◆ operator=() [5/5]

Char& operator= ( const char *  )

Assignment operator for a constant active code page character.

◆ Set()

Char& Set ( unsigned int  cp,
const char *  string 
)

Change this character to represents the first character of the string specified, based on the code page specified.

Parameters
cp- The specified code page
string- The string to use as a copy source

◆ IsNull()

bool IsNull ( ) const
inline

Returns true if this character represents a NULL character.

173 { return _ch == 0; }
unsigned int _ch
Definition: maxchar.h:39

◆ IsValid()

bool IsValid ( ) const
inline

Returns true if this character represents a non-NULL character.

176 { return _ch != 0; }

◆ CharCode()

unsigned int CharCode ( ) const
inline

Returns the character as UTF32.

179 { return _ch; }

◆ IsSpace()

bool IsSpace ( ) const

◆ IsDigit()

bool IsDigit ( ) const

◆ IsAlpha()

bool IsAlpha ( ) const

◆ IsAlphaNumeric()

bool IsAlphaNumeric ( ) const

◆ IsPunctuation()

bool IsPunctuation ( ) const

◆ IsUnicode()

bool IsUnicode ( ) const
inline
201 { return _ch > 0x7e; }

◆ ToUpper()

Char ToUpper ( ) const

◆ ToLower()

Char ToLower ( ) const

◆ IsValidUTF8()

static bool IsValidUTF8 ( const void data,
size_t  len,
bool *  pFoundExtendedChar = 0,
size_t pPartialCharAtEnd = 0 
)
static

Determine if the UTF-8 string is valid.

Parameters
dataBuffer pointer to validate encoding of
lenSize of the buffer to validate
pFoundExtendedCharIf not null, returns if the presence of multi-bytes character was found.
pPartialCharAtEndIf not null, returns if the number of bytes missing for the last character. The beginning was correct, but it missed the ending.
Returns
True if the string is a valid UTF8, False otherwise

◆ UTF8CharLength()

static unsigned int UTF8CharLength ( unsigned char  character)
static

Determine the length of an UTF-8 character.

Parameters
characterUTF-8 character to get the length of
Returns
length of the character in bytes.

◆ IsUTF16LeadChar()

static bool IsUTF16LeadChar ( wchar_t  character)
static

Determine if the UTF-16 char is a lead character.

In some situation, UTF-16 can be stored on four bytes instead of two.

Parameters
characterCharacter to test
Returns
True if the character is a lead character, False otherwise

◆ IsInCharacterSet()

MCHAR* IsInCharacterSet ( const MCHAR ) const

Determine if this character is found inside a particular character set.

This function slightly differs from strrchr or wcsrchr, because it can search DBCS or UTF16 character accurately inside a string without partially matching it.

Member Data Documentation

◆ _ch

unsigned int _ch
protected