Skip to content

Commit

Permalink
kisaragi : yomi katakana conversion
Browse files Browse the repository at this point in the history
unicode-multibite conversion error handling
  • Loading branch information
ponapalt committed Apr 3, 2020
1 parent 0cccfe0 commit e506ec1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 26 deletions.
34 changes: 19 additions & 15 deletions csaori_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,31 @@ namespace SAORI_FUNC{

std::string UnicodeToMultiByte(const wchar_t *Source, unsigned int CodePage, DWORD Flags)
{
if (int Len = ::WideCharToMultiByte(CodePage, Flags, Source, (int)wcslen(Source), NULL, 0, NULL, NULL)) {
std::vector<char> Dest(Len);
if (Len = ::WideCharToMultiByte(CodePage, Flags, Source, (int)wcslen(Source), &Dest[0], static_cast<int>(Dest.size()), NULL, NULL)) {
return std::string(Dest.begin(), Dest.begin() + Len);
if ( Source && *Source ) {
if (int Len = ::WideCharToMultiByte(CodePage, Flags, Source, (int)wcslen(Source), NULL, 0, NULL, NULL)) {
std::vector<char> Dest(Len);
if (Len = ::WideCharToMultiByte(CodePage, Flags, Source, (int)wcslen(Source), &Dest[0], static_cast<int>(Dest.size()), NULL, NULL)) {
return std::string(Dest.begin(), Dest.begin() + Len);
}
}
}
}
return "";
return "";
}


std::wstring MultiByteToUnicode(const char* Source, unsigned int CodePage, DWORD Flags)
{
if (int Len = ::MultiByteToWideChar(CodePage, Flags, Source, (int)strlen(Source), NULL, 0)) {
std::vector<wchar_t> Dest(Len);
if (Len = ::MultiByteToWideChar(CodePage, 0, Source, (int)strlen(Source), &Dest[0], static_cast<int>(Dest.size()))) {
return std::wstring(Dest.begin(), Dest.begin() + Len);
if ( Source && *Source ) {
if (int Len = ::MultiByteToWideChar(CodePage, Flags, Source, (int)strlen(Source), NULL, 0)) {
std::vector<wchar_t> Dest(Len);
if (Len = ::MultiByteToWideChar(CodePage, 0, Source, (int)strlen(Source), &Dest[0], static_cast<int>(Dest.size()))) {
return std::wstring(Dest.begin(), Dest.begin() + Len);
}
}
}
}
return L"";
return L"";
}

std::wstring CodePagetoString(unsigned int cset){
switch(cset){
case CP_SJIS:
Expand Down
37 changes: 30 additions & 7 deletions impl_saori/kisaragi/kisaragi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,38 @@ void CSAORIKisaragi::exec_type(const CSAORIInput& in,CSAORIOutput& out,string_t

string_t result = SAORI_FUNC::MultiByteToUnicode(pLattice->toString(),CP_UTF8);
string_t sl;
string_t::size_type pos = 0;

do {
pos = SAORI_FUNC::getLine(sl, result, pos);
out.values.push_back(sl);
} while ( pos != string_t::npos );

out.result = SAORI_FUNC::intToString(out.values.size());
if ( m_outFormat.compare(L"yomi") == 0 ) {
string_t::iterator ypos = result.begin();
char_t c;

while ( ypos != result.end() ) {
c = *ypos;

//ひらがな->カタカナ
if ( (c >= L'\x3041' && c <= L'\x3094') || (c == L'\x309D') || (c == L'\x309E') ) {
c += (char_t)0x60U;
*ypos = c;
}

ypos += 1;
}
}

if ( result.size() > 0 ) {
string_t::size_type pos = 0;
do {
pos = SAORI_FUNC::getLine(sl, result, pos);
out.values.push_back(sl);
} while ( pos != string_t::npos );

out.result = SAORI_FUNC::intToString(out.values.size());
}
else {
out.result = L"-1";
}
out.result_code = SAORIRESULT_OK;

return;
}

Expand Down
8 changes: 8 additions & 0 deletions impl_saori/kisaragi/kisaragi.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions impl_saori/kisaragi/kisaragi.rc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,1,0
FILEVERSION 1,1,2,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
Expand All @@ -73,7 +73,7 @@ BEGIN
VALUE "Comments", " \0"
VALUE "CompanyName", " \0"
VALUE "FileDescription", "kisaragi SAORI Extension\0"
VALUE "FileVersion", "1, 1, 1, 0\0"
VALUE "FileVersion", "1, 1, 2, 0\0"
VALUE "InternalName", "kisaragi\0"
VALUE "LegalCopyright", " \0"
VALUE "LegalTrademarks", " \0"
Expand Down
8 changes: 6 additions & 2 deletions impl_saori/kisaragi/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ dic
�t�H�[�}�b�g�̈Ⴂ�ɂ‚��ẮA�Ⴆ�Ή��L���Q�l�ɂȂ�܂��B
http://d.hatena.ne.jp/Kshi_Kshi/20110102/1293920002


��wakati

����
Argument0: parse
Argument0: wakati
Argument1: ��͂��镶����

�߂�l(Result)
Expand Down Expand Up @@ -112,6 +111,8 @@ dic

�@�\
�J�^�J�i�œǂ݉�����U��܂��B
�����ɂȂ��ǂ݉��������m�̌��t�̏ꍇ�́A�Ђ炪�Ȃ̏ꍇ�̓J�^�J�i�ϊ��A����ȊO�͂��̂܂܏o�͂���܂��B
�䂦�ɁA�o�͂ɃJ�^�J�i�ȊO�̕�����������ꍇ������̂�z�肵�Ă��������B

��
Argument0: yomi
Expand Down Expand Up @@ -152,3 +153,6 @@ license.txt
�E2017/9/10 v1.1.1
�@dicrc�܂ł̃p�X��2�o�C�g�������܂܂��Ƃ��܂��ǂݍ��܂Ȃ������C��

�E2020/4/3 v1.1.2
�@yomi�Ŗ��m��ɏo������ꍇ�A���‚��ꂪ�Ђ炪�Ȃ������ꍇ�ɁA�J�^�J�i�ɕϊ����鏈����lj�

0 comments on commit e506ec1

Please # to comment.