Debian Codegraph @

Source/tstring.h

raw
1 // tstring.h
2 //
3 // This file is a part of Unicode NSIS.
4 //
5 // Copyright (C) 2007-2026 Jim Park
6 //
7 // Licensed under the zlib/libpng license (the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // This software is provided 'as-is', without any expressed or implied
11 // warranty.
12 //
13 // Provides TSTRING support.
14
15 /*
16 Unicode support by Jim Park -- 07/23/2007
17 */
18
19 #ifndef NSIS_TSTRING___H__
20 #define NSIS_TSTRING___H__
21
22 #include "Platform.h"
23 #include "tchar.h"
24 #include <string>
25
26 /* Abstract string type as well. */
27 #ifdef _UNICODE
28 typedef std::wstring tstring;
29 typedef std::wofstream tofstream;
30 typedef std::wifstream tifstream;
31 #else
32 typedef std::string tstring;
33 typedef std::ofstream tofstream;
34 typedef std::ifstream tifstream;
35 #endif
36
37 #ifndef _UNICODE
38 #define CtoTString(str) (str)
39 #define CtoTString2(str,cp) (str)
40 #define TtoCString(str) (str)
41 #define CtoTStrParam CtoTString
42 #else
43 #define CtoTString2(str,cp) CtoTString((str),(cp))
44 #define CtoTStrParam(str) ( (const TCHAR*) CtoTString((str)) ) // Use this when passing as a vararg parameter
45
46
47 // This is a helpful little function for converting exceptions or
48 // other system type things that come back ANSI and must be
49 // utilized as either ANSI or wchar_t depending on _UNICODE.
50 class CtoTString
51 {
52 void Init(const char* str, UINT cp);
53 void Init(const char* str);
54 public:
55 CtoTString(const char* str) { Init(str); }
56 CtoTString(const char* str, UINT cp) { Init(str, cp); }
57 CtoTString(const std::string& str) { Init(str.c_str()); }
58
59 ~CtoTString();
60
61 operator const wchar_t*() const { return m_wStr; }
62 inline const wchar_t*GetTStr() const { return m_wStr; }
63
64 private:
65 wchar_t* m_wStr;
66 };
67
68 // There may be system things that require C strings but we
69 // may actually have Unicode strings.
70 class TtoCString
71 {
72 void Init(const wchar_t* str);
73 public:
74 TtoCString(const wchar_t* wStr) { Init(wStr); }
75 TtoCString(const tstring& wStr) { Init(wStr.c_str()); }
76
77 ~TtoCString();
78
79 operator const char*() const { return m_cStr; };
80
81 private:
82 char* m_cStr;
83 };
84 #endif // _UNICODE
85
86 #define PosixBug_CtoTString CtoTString
87 #define PosixBug_TtoCString TtoCString
88
89 #endif // NSIS_TSTRING___H__