summaryrefslogtreecommitdiff
path: root/Source/tstring.cpp
blob: 0be0545971f235c3f6e7ce7d10cc0174afe30714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// tstring.cpp
//
// This file is a part of Unicode NSIS.
//
// Copyright (C) 2007-2017 Jim Park
//
// Licensed under the zlib/libpng license (the "License");
// you may not use this file except in compliance with the License.
//
// This software is provided 'as-is', without any expressed or implied
// warranty.
//
// Provides TSTRING support.

#ifdef _UNICODE

#include "tstring.h"
#include "util.h"
#include <vector>
#include <stdio.h>

void CtoTString::Init(const char* str, UINT cp)
{
#if defined(_UNICODE) && !defined(_WIN32)
  if (CP_ACP == cp)
  {
    m_wStr = NSISRT_mbtowc(str); // Should be faster than iconv
    return ;
  }
#endif
  int len = MultiByteToWideChar(cp, 0, str, -1, NULL, 0);
  m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t));
  if (m_wStr) MultiByteToWideChar(cp, 0, str, -1, m_wStr, len);
}

void CtoTString::Init(const char* str)
{
  Init(str, CP_ACP);
}

CtoTString::~CtoTString() { free(m_wStr); m_wStr = 0; }



void TtoCString::Init(const wchar_t* str)
{
#if defined(_UNICODE) && !defined(_WIN32)
  m_cStr = NSISRT_wctomb(str); // Should be faster than iconv
  return ;
#endif
  int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, 0, 0);
  m_cStr = (char*) malloc(len);
  if (m_cStr) WideCharToMultiByte(CP_ACP, 0, str, -1, m_cStr, len, 0, 0);
}

TtoCString::~TtoCString() { free(m_cStr); m_cStr = 0; }


#endif