Polygon Crucher SDK - Documentation
Documentation
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
xstringoperation.h
Go to the documentation of this file.
1//! @file xstringoperation.h
2//! @brief strings low level functions and conversion. Some are declared in macos_stringoperation, win_stringoperation...
3//!
4//! Created by Mootools on 20/05/2016.
5//! Copyright © 2016 Mootools. All rights reserved.
6//////////////////////////////////////////////////////////////////////////////////
7
8#ifndef xstring_operation_h
9#define xstring_operation_h
10
11BEGIN_MOOTOOLS_NAMESPACE
12
13// On Windows xStringEncoding can be one of these value or a code page
14typedef enum XEnumType( unsigned int)
15{
16 xStringDefaultEncoding = (unsigned int)-1, // Use for converting to default OS encoding (for converting from CXStringA <-> CXStringW)
17 xStringAnsi = 1, // char encoding
18 xStringUtf8, // char encoding (Mac OS default)
19 xStringUtf16, // wchar_t encoding (Windows default)
20 xStringUtf32, // wchar_t encoding (not supported)
21} xStringEncoding;
22
23#define IsStringEncodingUnicode(encodingValue) ((bool)((encodingValue == xStringUtf16) || (encodingValue == xStringUtf32)))
24
25DLL_TOOLSFUNCTION CXString xLoadString(unsigned int resourceID); // Must be exported as accessed through a CXString template
26DLL_TOOLSFUNCTION SIZET xUTF8ToUTF16(const unsigned char *utf8, unsigned short *utf16);
27DLL_TOOLSFUNCTION SIZET xUTF16ToUTF32(const unsigned short *utf16, SIZET charcount, unsigned int *utf32);
28
29// String conversions
30
31// Forward declarations of our classes. They are defined later.
32class XCA2A;
33class XCA2W;
34class XCW2A;
35class XCW2W;
36
37// typedefs for the well known text conversions
38typedef XCA2W XA2W;
39typedef XCW2A XW2A;
40typedef XCW2W XW2W;
41typedef XCA2A XA2A;
42
43#ifdef _UNICODE
44 typedef XCA2W XA2T;
45 typedef XCW2A XT2A;
46 typedef XCW2W XT2W;
47 typedef XCW2W XW2T;
48#else
49 typedef XCA2A XA2T;
50 typedef XCA2A XT2A;
51 typedef XCA2W XT2W;
52 typedef XCW2A XW2T;
53#endif
54
55typedef XT2A XCT2A;
56typedef XT2W XCT2W;
57typedef XA2T XCA2T;
58typedef XW2T XCW2T;
59
60bool XFASTCA2W(CXCharArrayW& buffer, LPCSTR pStr, xStringEncoding srcAnsiEncoding = xStringDefaultEncoding);
61
62//! @class XCA2W
63//! @brief Conversion from ansi / utf8 (char) to unicode (wchar_t)
64//! @details Allows to get a CXStringW from a CXStringA for example.
65class DLL_TOOLSFUNCTION XCA2W
66{
67public:
68#ifdef __WINDOWS__
69 // Windows : ansi source might be ansi, code page, or utf8
70 // unicode destination is always windows default unicode (utf16)
71 XCA2W(LPCSTR pStr, xStringEncoding srcAnsiEncoding = xStringDefaultEncoding);
72#else
73 // Macos & Linux: ansi source is always UTF8.
74 // Unicode conversion might be done from 16 or 32 bits (Macos only) unicode string
75 XCA2W(LPCSTR pStr, xStringEncoding srcAnsiEncoding = xStringDefaultEncoding);
76#endif
77
78 ~XCA2W() {}
79 operator LPCWSTR() { return isValid ? buffer.data() : NULL; }
80
81private:
82 CXCharArrayW buffer;
83 bool isValid;
84};
85
86bool XFASTCW2A(CXCharArrayA& buffer, LPCWSTR pWstr, xStringEncoding dstAnsiEncoding = xStringDefaultEncoding);
87
88//! @class XCW2A
89//! @brief Conversion from unicode (wchar_t) to ansi / utf8 (char)
90//! @details Allows to get a CXStringA from a CXStringW for example.
91class DLL_TOOLSFUNCTION XCW2A
92{
93public:
94#ifdef __WINDOWS__
95 // Windows : ansi destination might be ansi, code page, or utf8
96 // unicode source is always windows default unicode (utf16)
97 XCW2A(LPCWSTR pWStr, xStringEncoding dstAnsiEncoding = xStringDefaultEncoding);
98#else
99 // Macos & Linux: ansi destination is always UTF8.
100 // Unicode conversion might be done from 16 or 32 bits (Macos only) unicode string
101 XCW2A(LPCWSTR pWStr, xStringEncoding dstAnsiEncoding = xStringDefaultEncoding);
102#endif
103
104 ~XCW2A() {}
105 operator LPCSTR() { return isValid ? buffer.data() : NULL; }
106
107private:
108 CXCharArrayA buffer;
109 bool isValid;
110};
111
112// Does not perform ANSI conversion yet, return the string itself
113class DLL_TOOLSFUNCTION XCW2W
114{
115public:
116 XCW2W(LPCWSTR pWStr, xStringEncoding encoding = xStringDefaultEncoding);
117 operator LPCWSTR() { return (LPWSTR)m_pWStr; }
118
119private:
120 LPCWSTR m_pWStr;
121};
122
123// Does not perform ANSI conversion yet, return the string itself
124class DLL_TOOLSFUNCTION XCA2A
125{
126public:
127 XCA2A(LPCSTR pStr, xStringEncoding encoding = xStringDefaultEncoding);
128 operator LPCSTR() { return (LPSTR)m_pStr; }
129
130private:
131 LPCSTR m_pStr;
132};
133
134END_MOOTOOLS_NAMESPACE
135
136#endif /* xstring_operation_h */
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Conversion from ansi / utf8 (char) to unicode (wchar_t)
Definition xstringoperation.h:66
Conversion from unicode (wchar_t) to ansi / utf8 (char)
Definition xstringoperation.h:92