Replaced UCS-2 by UTF-16, removed unused UniConversion.*

pull/9707/head
Udo Hoffmann 2021-03-26 21:04:42 +01:00 committed by Don HO
parent 38bf76e843
commit 6834d796ab
13 changed files with 42 additions and 213 deletions

View File

@ -283,14 +283,14 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="45003" name="Macintosh (CR)"/>
<Item id="45004" name="ANSI"/>
<Item id="45005" name="UTF-8-BOM"/>
<Item id="45006" name="UCS-2 BE BOM"/>
<Item id="45007" name="UCS-2 LE BOM"/>
<Item id="45006" name="UTF-16 BE BOM"/>
<Item id="45007" name="UTF-16 LE BOM"/>
<Item id="45008" name="UTF-8"/>
<Item id="45009" name="Convert to ANSI"/>
<Item id="45010" name="Convert to UTF-8"/>
<Item id="45011" name="Convert to UTF-8-BOM"/>
<Item id="45012" name="Convert to UCS-2 BE BOM"/>
<Item id="45013" name="Convert to UCS-2 LE BOM"/>
<Item id="45012" name="Convert to UTF-16 BE BOM"/>
<Item id="45013" name="Convert to UTF-16 LE BOM"/>
<Item id="45060" name="Big5 (Traditional)"/>
<Item id="45061" name="GB2312 (Simplified)"/>
<Item id="45054" name="OEM 861: Icelandic"/>
@ -864,8 +864,8 @@ You can define several column markers by using white space to separate the diffe
<Item id="6406" name="ANSI"/>
<Item id="6407" name="UTF-8"/>
<Item id="6408" name="UTF-8 with BOM"/>
<Item id="6409" name="UCS-2 Big Endian with BOM"/>
<Item id="6410" name="UCS-2 Little Endian with BOM"/>
<Item id="6409" name="UTF-16 Big Endian with BOM"/>
<Item id="6410" name="UTF-16 Little Endian with BOM"/>
<Item id="6411" name="Default language :"/>
<Item id="6419" name="New Document"/>
<Item id="6420" name="Apply to opened ANSI files"/>

View File

@ -2580,13 +2580,13 @@ void Notepad_plus::setUniModeText()
case uniUTF8:
uniModeTextString = TEXT("UTF-8-BOM"); break;
case uni16BE:
uniModeTextString = TEXT("UCS-2 BE BOM"); break;
uniModeTextString = TEXT("UTF-16 BE BOM"); break;
case uni16LE:
uniModeTextString = TEXT("UCS-2 LE BOM"); break;
uniModeTextString = TEXT("UTF-16 LE BOM"); break;
case uni16BE_NoBOM:
uniModeTextString = TEXT("UCS-2 Big Endian"); break;
uniModeTextString = TEXT("UTF-16 Big Endian"); break;
case uni16LE_NoBOM:
uniModeTextString = TEXT("UCS-2 Little Endian"); break;
uniModeTextString = TEXT("UTF-16 Little Endian"); break;
case uniCookie:
uniModeTextString = TEXT("UTF-8"); break;
default :
@ -4463,8 +4463,8 @@ void Notepad_plus::checkUnicodeMenuItems() const
switch (um)
{
case uniUTF8 : id = IDM_FORMAT_UTF_8; break;
case uni16BE : id = IDM_FORMAT_UCS_2BE; break;
case uni16LE : id = IDM_FORMAT_UCS_2LE; break;
case uni16BE : id = IDM_FORMAT_UTF_16BE; break;
case uni16LE : id = IDM_FORMAT_UTF_16LE; break;
case uniCookie : id = IDM_FORMAT_AS_UTF_8; break;
case uni8Bit : id = IDM_FORMAT_ANSI; break;
}

View File

@ -581,8 +581,8 @@ BEGIN
MENUITEM "ANSI", IDM_FORMAT_ANSI
MENUITEM "UTF-8", IDM_FORMAT_AS_UTF_8
MENUITEM "UTF-8-BOM", IDM_FORMAT_UTF_8
MENUITEM "UCS-2 BE BOM", IDM_FORMAT_UCS_2BE
MENUITEM "UCS-2 LE BOM", IDM_FORMAT_UCS_2LE
MENUITEM "UTF-16 BE BOM", IDM_FORMAT_UTF_16BE
MENUITEM "UTF-16 LE BOM", IDM_FORMAT_UTF_16LE
POPUP "Character sets"
BEGIN
POPUP "Arabic"
@ -698,8 +698,8 @@ BEGIN
MENUITEM "Convert to ANSI", IDM_FORMAT_CONV2_ANSI
MENUITEM "Convert to UTF-8", IDM_FORMAT_CONV2_AS_UTF_8
MENUITEM "Convert to UTF-8-BOM", IDM_FORMAT_CONV2_UTF_8
MENUITEM "Convert to UCS-2 BE BOM", IDM_FORMAT_CONV2_UCS_2BE
MENUITEM "Convert to UCS-2 LE BOM", IDM_FORMAT_CONV2_UCS_2LE
MENUITEM "Convert to UTF-16 BE BOM", IDM_FORMAT_CONV2_UTF_16BE
MENUITEM "Convert to UTF-16 LE BOM", IDM_FORMAT_CONV2_UTF_16LE
END
POPUP "&Language"

View File

@ -2366,8 +2366,8 @@ void Notepad_plus::command(int id)
case IDM_FORMAT_ANSI :
case IDM_FORMAT_UTF_8 :
case IDM_FORMAT_UCS_2BE :
case IDM_FORMAT_UCS_2LE :
case IDM_FORMAT_UTF_16BE :
case IDM_FORMAT_UTF_16LE :
case IDM_FORMAT_AS_UTF_8 :
{
Buffer * buf = _pEditView->getCurrentBuffer();
@ -2385,11 +2385,11 @@ void Notepad_plus::command(int id)
um = uniUTF8;
break;
case IDM_FORMAT_UCS_2BE:
case IDM_FORMAT_UTF_16BE:
um = uni16BE;
break;
case IDM_FORMAT_UCS_2LE:
case IDM_FORMAT_UTF_16LE:
um = uni16LE;
break;
@ -2555,8 +2555,8 @@ void Notepad_plus::command(int id)
case IDM_FORMAT_CONV2_ANSI:
case IDM_FORMAT_CONV2_AS_UTF_8:
case IDM_FORMAT_CONV2_UTF_8:
case IDM_FORMAT_CONV2_UCS_2BE:
case IDM_FORMAT_CONV2_UCS_2LE:
case IDM_FORMAT_CONV2_UTF_16BE:
case IDM_FORMAT_CONV2_UTF_16LE:
{
int idEncoding = -1;
Buffer *buf = _pEditView->getCurrentBuffer();
@ -2628,7 +2628,7 @@ void Notepad_plus::command(int id)
break;
}
case IDM_FORMAT_CONV2_UCS_2BE:
case IDM_FORMAT_CONV2_UTF_16BE:
{
if (encoding != -1)
{
@ -2638,7 +2638,7 @@ void Notepad_plus::command(int id)
return;
}
idEncoding = IDM_FORMAT_UCS_2BE;
idEncoding = IDM_FORMAT_UTF_16BE;
if (um == uni16BE)
return;
@ -2651,7 +2651,7 @@ void Notepad_plus::command(int id)
break;
}
case IDM_FORMAT_CONV2_UCS_2LE:
case IDM_FORMAT_CONV2_UTF_16LE:
{
if (encoding != -1)
{
@ -2661,7 +2661,7 @@ void Notepad_plus::command(int id)
return;
}
idEncoding = IDM_FORMAT_UCS_2LE;
idEncoding = IDM_FORMAT_UTF_16LE;
if (um == uni16LE)
return;
if (um != uni8Bit)

View File

@ -313,8 +313,8 @@ static const WinMenuKeyDefinition winKeyDefs[] =
{ VK_NULL, IDM_FORMAT_ANSI, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_AS_UTF_8, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_UTF_8, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_UCS_2BE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_UCS_2LE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_UTF_16BE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_UTF_16LE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_ISO_8859_6, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_WIN_1256, false, false, false, nullptr },
@ -367,8 +367,8 @@ static const WinMenuKeyDefinition winKeyDefs[] =
{ VK_NULL, IDM_FORMAT_CONV2_ANSI, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_CONV2_AS_UTF_8, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_CONV2_UTF_8, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_CONV2_UCS_2BE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_CONV2_UCS_2LE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_CONV2_UTF_16BE, false, false, false, nullptr },
{ VK_NULL, IDM_FORMAT_CONV2_UTF_16LE, false, false, false, nullptr },
{ VK_NULL, IDM_LANG_USER_DLG, false, false, false, nullptr },
{ VK_NULL, IDM_LANG_USER, false, false, false, nullptr },

View File

@ -19,7 +19,6 @@
#include "FindReplaceDlg.h"
#include "ScintillaEditView.h"
#include "Notepad_plus_msgs.h"
#include "UniConversion.h"
#include "localization.h"
#include "Utf8.h"

View File

@ -1,152 +0,0 @@
// Scintilla source code edit control
/** @file UniConversion.cxx
** Functions to handle UFT-8 and UCS-2 strings.
**/
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <windows.h>
#include "UniConversion.h"
unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen)
{
unsigned int len = 0;
for (unsigned int i = 0; i < tlen && uptr[i]; ++i)
{
unsigned int uch = uptr[i];
if (uch < 0x80)
++len;
else if (uch < 0x800)
len += 2;
else
len +=3;
}
return len;
}
void UTF8FromUCS2(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len)
{
int k = 0;
for (unsigned int i = 0; i < tlen && uptr[i]; ++i)
{
unsigned int uch = uptr[i];
if (uch < 0x80)
{
putf[k++] = static_cast<char>(uch);
}
else if (uch < 0x800)
{
putf[k++] = static_cast<char>(0xC0 | (uch >> 6));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
else
{
putf[k++] = static_cast<char>(0xE0 | (uch >> 12));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
}
putf[len] = '\0';
}
unsigned int UCS2Length(const char *s, unsigned int len)
{
unsigned int ulen = 0;
for (unsigned int i=0; i<len; ++i)
{
UCHAR ch = static_cast<UCHAR>(s[i]);
if ((ch < 0x80) || (ch > (0x80 + 0x40)))
++ulen;
}
return ulen;
}
unsigned int UCS2FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen)
{
unsigned int ui=0;
const UCHAR *us = reinterpret_cast<const UCHAR *>(s);
unsigned int i=0;
while ((i<len) && (ui<tlen))
{
UCHAR ch = us[i++];
if (ch < 0x80)
{
tbuf[ui] = ch;
}
else if (ch < 0x80 + 0x40 + 0x20)
{
tbuf[ui] = static_cast<wchar_t>((ch & 0x1F) << 6);
ch = us[i++];
tbuf[ui] = static_cast<wchar_t>(tbuf[ui] + (ch & 0x7F));
}
else
{
tbuf[ui] = static_cast<wchar_t>((ch & 0xF) << 12);
ch = us[i++];
tbuf[ui] = static_cast<wchar_t>(tbuf[ui] + ((ch & 0x7F) << 6));
ch = us[i++];
tbuf[ui] = static_cast<wchar_t>(tbuf[ui] + (ch & 0x7F));
}
ui++;
}
return ui;
}
unsigned int ascii_to_utf8(const char * pszASCII, unsigned int lenASCII, char * pszUTF8)
{
// length of pszUTF8 must be enough;
// its maximum is (lenASCII*3 + 1)
if (!lenASCII || !pszASCII)
{
pszUTF8[0] = 0;
return 0;
}
unsigned int lenUCS2;
unsigned int lenUTF8;
wchar_t *pszUCS2 = new wchar_t[lenASCII * 3 + 1];
if (!pszUCS2)
{
pszUTF8[0] = 0;
return 0;
}
lenUCS2 = ::MultiByteToWideChar(CP_ACP, 0, pszASCII, lenASCII, pszUCS2, lenASCII + 1);
lenUTF8 = UTF8Length(pszUCS2, lenUCS2);
// length of pszUTF8 must be >= (lenUTF8 + 1)
UTF8FromUCS2(pszUCS2, lenUCS2, pszUTF8, lenUTF8);
delete [] pszUCS2;
return lenUTF8;
}
int utf8_to_ascii(const char * pszUTF8, unsigned int lenUTF8, char * pszASCII)
{
// length of pszASCII must be enough;
// its maximum is (lenUTF8 + 1)
if (!lenUTF8 || !pszUTF8)
{
pszASCII[0] = 0;
return 0;
}
unsigned int lenUCS2;
wchar_t* pszUCS2;
pszUCS2 = new wchar_t[lenUTF8 + 1];
if (!pszUCS2)
{
pszASCII[0] = 0;
return 0;
}
lenUCS2 = UCS2FromUTF8(pszUTF8, lenUTF8, pszUCS2, lenUTF8);
pszUCS2[lenUCS2] = 0;
// length of pszASCII must be >= (lenUCS2 + 1)
int nbByte = ::WideCharToMultiByte(CP_ACP, 0, pszUCS2, lenUCS2, pszASCII, lenUCS2 + 1, NULL, NULL);
delete [] pszUCS2;
return nbByte;
}

View File

@ -1,16 +0,0 @@
// Scintilla source code edit control
/** @file UniConversion.h
** Functions to handle UFT-8 and UCS-2 strings.
**/
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#pragma once
unsigned int UTF8Length(const wchar_t * uptr, unsigned int tlen);
void UTF8FromUCS2(const wchar_t * uptr, unsigned int tlen, char * putf, unsigned int len);
unsigned int UCS2Length(const char * s, unsigned int len);
unsigned int UCS2FromUTF8(const char * s, unsigned int len, wchar_t * tbuf, unsigned int tlen);
unsigned int ascii_to_utf8(const char * pszASCII, unsigned int lenASCII, char * pszUTF8);
int utf8_to_ascii(const char * pszUTF8, unsigned int lenUTF8, char * pszASCII);

View File

@ -131,8 +131,8 @@ BEGIN
CONTROL "UTF-8",IDC_RADIO_UTF8SANSBOM,"Button",BS_AUTORADIOBUTTON,242,53,128,10
CONTROL "Apply to opened ANSI files",IDC_CHECK_OPENANSIASUTF8, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,252,65,144,10
CONTROL "UTF-8 with BOM",IDC_RADIO_UTF8,"Button",BS_AUTORADIOBUTTON,242,79,62,10
CONTROL "UCS-2 Big Endian with BOM",IDC_RADIO_UCS2BIG,"Button",BS_AUTORADIOBUTTON,242,95,110,10
CONTROL "UCS-2 Little Endian with BOM",IDC_RADIO_UCS2SMALL,"Button",BS_AUTORADIOBUTTON,242,111,110,10
CONTROL "UTF-16 Big Endian with BOM",IDC_RADIO_UTF16BIG,"Button",BS_AUTORADIOBUTTON,242,95,110,10
CONTROL "UTF-16 Little Endian with BOM",IDC_RADIO_UTF16SMALL,"Button",BS_AUTORADIOBUTTON,242,111,110,10
CONTROL "",IDC_RADIO_OTHERCP,"Button",BS_AUTORADIOBUTTON,242,126,10,10
COMBOBOX IDC_COMBO_OTHERCP,257,125,100,140,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
RTEXT "Default language :",IDC_DEFAULTLANG_STATIC,16,130,77,8

View File

@ -1207,10 +1207,10 @@ INT_PTR CALLBACK NewDocumentSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPA
switch (ndds._unicodeMode)
{
case uni16BE :
ID2Check = IDC_RADIO_UCS2BIG;
ID2Check = IDC_RADIO_UTF16BIG;
break;
case uni16LE :
ID2Check = IDC_RADIO_UCS2SMALL;
ID2Check = IDC_RADIO_UTF16SMALL;
break;
case uniUTF8 :
ID2Check = IDC_RADIO_UTF8;
@ -1287,14 +1287,14 @@ INT_PTR CALLBACK NewDocumentSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPA
case WM_COMMAND:
switch (wParam)
{
case IDC_RADIO_UCS2BIG:
case IDC_RADIO_UTF16BIG:
ndds._unicodeMode = uni16BE;
ndds._openAnsiAsUtf8 = false;
makeOpenAnsiAsUtf8(false);
ndds._codepage = -1;
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_OTHERCP), false);
return TRUE;
case IDC_RADIO_UCS2SMALL:
case IDC_RADIO_UTF16SMALL:
ndds._unicodeMode = uni16LE;
ndds._openAnsiAsUtf8 = false;
makeOpenAnsiAsUtf8(false);

View File

@ -217,8 +217,8 @@
#define IDC_RADIO_ANSI (IDD_PREFERENCE_SUB_NEWDOCUMENT + 6)
#define IDC_RADIO_UTF8SANSBOM (IDD_PREFERENCE_SUB_NEWDOCUMENT + 7)
#define IDC_RADIO_UTF8 (IDD_PREFERENCE_SUB_NEWDOCUMENT + 8)
#define IDC_RADIO_UCS2BIG (IDD_PREFERENCE_SUB_NEWDOCUMENT + 9)
#define IDC_RADIO_UCS2SMALL (IDD_PREFERENCE_SUB_NEWDOCUMENT + 10)
#define IDC_RADIO_UTF16BIG (IDD_PREFERENCE_SUB_NEWDOCUMENT + 9)
#define IDC_RADIO_UTF16SMALL (IDD_PREFERENCE_SUB_NEWDOCUMENT + 10)
#define IDC_DEFAULTLANG_STATIC (IDD_PREFERENCE_SUB_NEWDOCUMENT + 11)
#define IDC_COMBO_DEFAULTLANG (IDD_PREFERENCE_SUB_NEWDOCUMENT + 12)
#define IDC_OPENSAVEDIR_GR_STATIC (IDD_PREFERENCE_SUB_NEWDOCUMENT + 13)

View File

@ -362,14 +362,14 @@
#define IDM_FORMAT_TOMAC (IDM_FORMAT + 3)
#define IDM_FORMAT_ANSI (IDM_FORMAT + 4)
#define IDM_FORMAT_UTF_8 (IDM_FORMAT + 5)
#define IDM_FORMAT_UCS_2BE (IDM_FORMAT + 6)
#define IDM_FORMAT_UCS_2LE (IDM_FORMAT + 7)
#define IDM_FORMAT_UTF_16BE (IDM_FORMAT + 6)
#define IDM_FORMAT_UTF_16LE (IDM_FORMAT + 7)
#define IDM_FORMAT_AS_UTF_8 (IDM_FORMAT + 8)
#define IDM_FORMAT_CONV2_ANSI (IDM_FORMAT + 9)
#define IDM_FORMAT_CONV2_AS_UTF_8 (IDM_FORMAT + 10)
#define IDM_FORMAT_CONV2_UTF_8 (IDM_FORMAT + 11)
#define IDM_FORMAT_CONV2_UCS_2BE (IDM_FORMAT + 12)
#define IDM_FORMAT_CONV2_UCS_2LE (IDM_FORMAT + 13)
#define IDM_FORMAT_CONV2_UTF_16BE (IDM_FORMAT + 12)
#define IDM_FORMAT_CONV2_UTF_16LE (IDM_FORMAT + 13)
#define IDM_FORMAT_ENCODE (IDM_FORMAT + 20)
#define IDM_FORMAT_WIN_1250 (IDM_FORMAT_ENCODE + 0)

View File

@ -380,7 +380,6 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml
<ClCompile Include="..\src\WinControls\ToolTip\ToolTip.cpp" />
<ClCompile Include="..\src\WinControls\TrayIcon\trayIconControler.cpp" />
<ClCompile Include="..\src\uchardet\uchardet.cpp" />
<ClCompile Include="..\src\UniConversion.cpp" />
<ClCompile Include="..\src\WinControls\AboutDlg\URLCtrl.cpp" />
<ClCompile Include="..\src\ScintillaComponent\UserDefineDialog.cpp" />
<ClCompile Include="..\src\Utf8_16.cpp" />
@ -671,7 +670,6 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml
<ClInclude Include="..\src\WinControls\ToolTip\ToolTip.h" />
<ClInclude Include="..\src\WinControls\TrayIcon\trayIconControler.h" />
<ClInclude Include="..\src\uchardet\uchardet.h" />
<ClInclude Include="..\src\UniConversion.h" />
<ClInclude Include="..\src\WinControls\AboutDlg\URLCtrl.h" />
<ClInclude Include="..\src\ScintillaComponent\UserDefineDialog.h" />
<ClInclude Include="..\src\ScintillaComponent\UserDefineLangReference.h" />