Debian Codegraph @

Source/tstring.cpp

raw
1 // tstring.cpp
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 #ifdef _UNICODE
16
17 #include "tstring.h"
18 #include "util.h"
19 #include <vector>
20 #include <stdio.h>
21
22 void CtoTString::Init(const char* str, UINT cp)
23 {
24 #if defined(_UNICODE) && !defined(_WIN32)
25 if (CP_ACP == cp)
26 {
27 assert(NSISRT_free_is_STDC_free());
28 m_wStr = NSISRT_mbtowc(str); // Should be faster than iconv
29 return ;
30 }
31 #endif
32 int len = MultiByteToWideChar(cp, 0, str, -1, NULL, 0);
33 m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t));
34 if (m_wStr) MultiByteToWideChar(cp, 0, str, -1, m_wStr, len);
35 }
36
37 void CtoTString::Init(const char* str)
38 {
39 Init(str, CP_ACP);
40 }
41
42 CtoTString::~CtoTString() { free(m_wStr); m_wStr = 0; }
43
44
45
46 void TtoCString::Init(const wchar_t* str)
47 {
48 #if defined(_UNICODE) && !defined(_WIN32)
49 assert(NSISRT_free_is_STDC_free());
50 m_cStr = NSISRT_wctomb(str); // Should be faster than iconv
51 return ;
52 #endif
53 int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, 0, 0);
54 m_cStr = (char*) malloc(len);
55 if (m_cStr) WideCharToMultiByte(CP_ACP, 0, str, -1, m_cStr, len, 0, 0);
56 }
57
58 TtoCString::~TtoCString() { free(m_cStr); m_cStr = 0; }
59
60
61 #endif