Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICU4CをWindows10同梱のものに差し替える検討 #1783

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sakura/sakura.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<ItemDefinitionGroup Label="sakura.common">
<ClCompile>
<AdditionalIncludeDirectories>..\sakura_core;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32_WINNT=_WIN32_WINNT_WIN7;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand Down
50 changes: 12 additions & 38 deletions sakura_core/extmodule/CIcu4cI18n.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! @file */
/*
Copyright (C) 2018-2021, Sakura Editor Organization
Copyright (C) 2018-2022, Sakura Editor Organization
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand All @@ -25,40 +25,14 @@
#include "StdAfx.h"
#include "CIcu4cI18n.h"

CIcu4cI18n::CIcu4cI18n() noexcept
: _ucsdet_open(nullptr)
, _ucsdet_setText(nullptr)
, _ucsdet_detect(nullptr)
, _ucsdet_close(nullptr)
{
}

/*!
* @brief DLLの名前を返す
*/
LPCWSTR CIcu4cI18n::GetDllNameImp( [[maybe_unused]] int index )
{
return L"icuin66.dll"; //バージョンは固定
}

/*!
DLLの初期化
関数のアドレスを取得してメンバに保管する.
@retval true 成功
@retval false アドレス取得に失敗
*/
bool CIcu4cI18n::InitDllImp()
{
//DLL内関数名リスト
const ImportTable table[] = {
{ &_ucsdet_open, "ucsdet_open_66" }, //バージョンは固定
{ &_ucsdet_setText, "ucsdet_setText_66" }, //バージョンは固定
{ &_ucsdet_detect, "ucsdet_detect_66" }, //バージョンは固定
{ &_ucsdet_getName, "ucsdet_getName_66" }, //バージョンは固定
{ &_ucsdet_close, "ucsdet_close_66" }, //バージョンは固定
{ NULL, 0 }
};
return RegisterEntries(table);
}
#include <ntddndis.h>

// リンクするライブラリはSDKにより変える
#if defined(NDIS_SUPPORT_NDIS683)
// Windows 10 SDK 10.0.18362以降を利用している場合
# pragma comment(lib, "icu.lib")
#else
// Windows 10 SDK 10.0.18362を利用できない場合(vs2017でビルドする場合)
# pragma comment(lib, "icuin.lib")
# pragma comment(lib, "icuuc.lib")
#endif
53 changes: 15 additions & 38 deletions sakura_core/extmodule/CIcu4cI18n.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! @file */
/*
Copyright (C) 2018-2021, Sakura Editor Organization
Copyright (C) 2018-2022, Sakura Editor Organization
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand All @@ -26,58 +26,35 @@
#define SAKURA_CICU4CI18N_16EE9B14_2791_4C5D_AE1E_E78FBF5CB083_H_
#pragma once

#include "CDllHandler.h"

//ICU4Cの型定義
class UCharsetDetector;
class UCharsetMatch;

typedef enum UErrorCode {
U_ZERO_ERROR = 0, /**< No error, no warning. */
} UErrorCode;
#include <icu.h>

/*!
* ICU4C の i18n ライブラリ(icuin.dll) をラップするクラス
* ICU4C のライブラリ(icu.dll) をラップするクラス
*
* Windows 10 1703でICU4CがWindowsに統合された。
* この実装では最新1903以降で導入されたicu.dllを使うようにしている。
* 1703~1809だと実装DLLが2つに分かれていてicu.dllが存在しない。
*/
class CIcu4cI18n final : public CDllImp
class CIcu4cI18n
{
// DLL関数型定義
typedef UCharsetDetector* (__cdecl *ucsdet_open_t)(UErrorCode *status);
typedef void (__cdecl *ucsdet_setText_t)(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status);
typedef const UCharsetMatch * (__cdecl *ucsdet_detect_t)(UCharsetDetector *ucsd, UErrorCode *status);
typedef const char* (__cdecl *ucsdet_getName_t)(const UCharsetMatch *ucsm, UErrorCode *status);
typedef void (__cdecl *ucsdet_close_t)(UCharsetDetector *ucsd);

// メンバ定義
ucsdet_open_t _ucsdet_open;
ucsdet_setText_t _ucsdet_setText;
ucsdet_detect_t _ucsdet_detect;
ucsdet_getName_t _ucsdet_getName;
ucsdet_close_t _ucsdet_close;

public:
CIcu4cI18n() noexcept;

protected:
// CDllImpインタフェース
LPCWSTR GetDllNameImp(int nIndex) override;
bool InitDllImp() override;
[[nodiscard]] bool IsAvailable() const { return true; }
bool InitDll() const { return true; }

public:
inline UCharsetDetector* ucsdet_open(UErrorCode *status) const {
return _ucsdet_open(status);
return ::ucsdet_open(status);
}
inline void ucsdet_setText(UCharsetDetector *ucsd, const char *textIn, int32_t len, UErrorCode *status) const {
return _ucsdet_setText(ucsd, textIn, len, status);
return ::ucsdet_setText(ucsd, textIn, len, status);
}
inline const UCharsetMatch* ucsdet_detect(UCharsetDetector *ucsd, UErrorCode *status) const {
return _ucsdet_detect(ucsd, status);
return ::ucsdet_detect(ucsd, status);
}
inline const char* ucsdet_getName(const UCharsetMatch *ucsm, UErrorCode *status) const {
return _ucsdet_getName(ucsm, status);
return ::ucsdet_getName(ucsm, status);
}
inline void ucsdet_close(UCharsetDetector *ucsd) const {
return _ucsdet_close(ucsd);
return ::ucsdet_close(ucsd);
}
};
#endif /* SAKURA_CICU4CI18N_16EE9B14_2791_4C5D_AE1E_E78FBF5CB083_H_ */
2 changes: 1 addition & 1 deletion tests/googletest
Submodule googletest updated 335 files