unichar.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: unichar.h
  3. // Purpose: interface of wxUniChar
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxUniChar
  9. This class represents a single Unicode character. It can be converted to
  10. and from @c char or @c wchar_t and implements commonly used character operations.
  11. @library{wxbase}
  12. @category{data}
  13. */
  14. class wxUniChar
  15. {
  16. public:
  17. /**
  18. A type capable of holding any Unicode code point.
  19. We do not use wchar_t as it cannot do the job on Win32,
  20. where wchar_t is a 16-bit type (wchar_t* is encoded using UTF-16 on Win32).
  21. */
  22. typedef wxUint32 value_type;
  23. /**
  24. Default ctor.
  25. */
  26. wxUniChar();
  27. //@{
  28. /**
  29. Create a character from the 8-bit character value @a c using the
  30. current locale encoding.
  31. */
  32. wxUniChar(char c);
  33. wxUniChar(unsigned char c);
  34. //@}
  35. wxUniChar(int c);
  36. wxUniChar(unsigned int c);
  37. wxUniChar(long int c);
  38. wxUniChar(unsigned long int c);
  39. wxUniChar(short int c);
  40. wxUniChar(unsigned short int c);
  41. wxUniChar(wxLongLong_t c);
  42. wxUniChar(wxULongLong_t c);
  43. wxUniChar(const wxUniCharRef& c);
  44. /**
  45. Returns Unicode code point value of the character.
  46. */
  47. value_type GetValue() const;
  48. /**
  49. Returns true if the character is an ASCII character (i.e.\ if its value is less than 128).
  50. */
  51. bool IsAscii() const;
  52. /**
  53. Returns true if the character is representable as a single byte in the
  54. current locale encoding.
  55. This function only returns true if the character can be converted in
  56. exactly one byte, e.g. it only returns true for 7 bit ASCII characters
  57. when the encoding used is UTF-8.
  58. It is mostly useful to test if the character can be passed to functions
  59. taking a char and is used by wxWidgets itself for this purpose.
  60. @param c
  61. An output pointer to the value of this Unicode character as a @c
  62. char. Must be non-@NULL.
  63. @return
  64. @true if the object is an 8 bit char and @a c was filled with its
  65. value as char or @false otherwise (@a c won't be modified then).
  66. @see IsAscii()
  67. @since 2.9.1
  68. */
  69. bool GetAsChar(char *c) const;
  70. //@{
  71. /**
  72. Conversions to char and wchar_t types: all of those are needed to be
  73. able to pass wxUniChars to various standard narrow and wide character
  74. functions.
  75. */
  76. operator char() const;
  77. operator unsigned char() const;
  78. operator wchar_t() const;
  79. operator int() const;
  80. operator unsigned int() const;
  81. operator long int() const;
  82. operator unsigned long int() const;
  83. operator short int() const;
  84. operator unsigned short int() const;
  85. operator wxLongLong_t() const;
  86. operator wxULongLong_t() const;
  87. //@}
  88. //@{
  89. /**
  90. Assignment operators
  91. */
  92. wxUniChar& operator=(const wxUniChar& c);
  93. wxUniChar& operator=(const wxUniCharRef& c);
  94. wxUniChar& operator=(char c);
  95. wxUniChar& operator=(unsigned char c);
  96. wxUniChar& operator=(wchar_t c);
  97. wxUniChar& operator=(int c);
  98. wxUniChar& operator=(unsigned int c);
  99. wxUniChar& operator=(long int c);
  100. wxUniChar& operator=(unsigned long int c);
  101. wxUniChar& operator=(short int c);
  102. wxUniChar& operator=(unsigned short int c);
  103. wxUniChar& operator=(wxLongLong_t c);
  104. wxUniChar& operator=(wxULongLong_t c);
  105. //@}
  106. };
  107. /**
  108. @class wxUniCharRef
  109. Writeable reference to a character in wxString.
  110. This class can be used in the same way wxChar is used, except that changing
  111. its value updates the underlying string object.
  112. @library{wxbase}
  113. @category{data}
  114. */
  115. class wxUniCharRef
  116. {
  117. public:
  118. };