diff options
-rw-r--r-- | system/keyboardlayouts/korean.xml | 54 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogKeyboardGeneric.cpp | 8 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogKeyboardGeneric.h | 2 | ||||
-rw-r--r-- | xbmc/input/InputCodingTable.h | 18 | ||||
-rw-r--r-- | xbmc/input/InputCodingTableBaiduPY.cpp | 168 | ||||
-rw-r--r-- | xbmc/input/InputCodingTableBaiduPY.h | 4 | ||||
-rw-r--r-- | xbmc/input/InputCodingTableBasePY.cpp | 12 | ||||
-rw-r--r-- | xbmc/input/InputCodingTableBasePY.h | 2 | ||||
-rw-r--r-- | xbmc/input/InputCodingTableKorean.cpp | 606 | ||||
-rw-r--r-- | xbmc/input/InputCodingTableKorean.h | 2 |
10 files changed, 462 insertions, 414 deletions
diff --git a/system/keyboardlayouts/korean.xml b/system/keyboardlayouts/korean.xml index 5c91788ab1..31109e5440 100644 --- a/system/keyboardlayouts/korean.xml +++ b/system/keyboardlayouts/korean.xml @@ -1,27 +1,27 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
-Please use English language names instead.
-Default font lacks support for all characters
--->
-<keyboardlayouts>
- <layout language="Korean" layout="ㄱㄴㄷ" codingtable="Korean">
- <keyboard>
- <row>0123456789</row>
- <row>ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋ</row>
- <row>ㅌㅍㅎㄲㄸㅃㅆㅉㅏㅑㅓ</row>
- <row>ㅕㅗㅛㅜㅠㅡㅣㅐㅔㅒㅖ</row>
- </keyboard>
- <keyboard modifiers="shift">
- <row>0123456789</row>
- <row>ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋ</row>
- <row>ㅌㅍㅎㄲㄸㅃㅆㅉㅏㅑㅓ</row>
- <row>ㅕㅗㅛㅜㅠㅡㅣㅐㅔㅒㅖ</row>
- </keyboard>
- <keyboard modifiers="symbol,shift+symbol">
- <row>)!@#$%^&*(</row>
- <row>[]{}-_=+;:</row>
- <row>'",.<>/?\|</row>
- <row>`~</row>
- </keyboard>
- </layout>
-</keyboardlayouts>
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- +Please use English language names instead. +Default font lacks support for all characters +--> +<keyboardlayouts> + <layout language="Korean" layout="ㄱㄴㄷ" codingtable="Korean"> + <keyboard> + <row>0123456789</row> + <row>ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋ</row> + <row>ㅌㅍㅎㄲㄸㅃㅆㅉㅏㅑㅓ</row> + <row>ㅕㅗㅛㅜㅠㅡㅣㅐㅔㅒㅖ</row> + </keyboard> + <keyboard modifiers="shift"> + <row>0123456789</row> + <row>ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋ</row> + <row>ㅌㅍㅎㄲㄸㅃㅆㅉㅏㅑㅓ</row> + <row>ㅕㅗㅛㅜㅠㅡㅣㅐㅔㅒㅖ</row> + </keyboard> + <keyboard modifiers="symbol,shift+symbol"> + <row>)!@#$%^&*(</row> + <row>[]{}-_=+;:</row> + <row>'",.<>/?\|</row> + <row>`~</row> + </keyboard> + </layout> +</keyboardlayouts> diff --git a/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp b/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp index 6dc062d533..e49c83946a 100644 --- a/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp +++ b/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp @@ -438,6 +438,8 @@ void CGUIDialogKeyboardGeneric::UpdateButtons() m_currentLayout = 0; CKeyboardLayout layout = m_layouts.empty() ? CKeyboardLayout() : m_layouts[m_currentLayout]; m_codingtable = layout.GetCodingTable(); + if (m_codingtable && !m_codingtable->IsInitialized()) + m_codingtable->Initialize(); bool bShowWordList = false; if (m_codingtable) @@ -494,6 +496,12 @@ void CGUIDialogKeyboardGeneric::UpdateButtons() void CGUIDialogKeyboardGeneric::OnDeinitWindow(int nextWindowID) { + for (auto& layout : m_layouts) + { + auto codingTable = layout.GetCodingTable(); + if (codingTable && codingTable->IsInitialized()) + codingTable->Deinitialize(); + } // call base class CGUIDialog::OnDeinitWindow(nextWindowID); // reset the heading (we don't always have this) diff --git a/xbmc/dialogs/GUIDialogKeyboardGeneric.h b/xbmc/dialogs/GUIDialogKeyboardGeneric.h index 30d97e0505..356abeb186 100644 --- a/xbmc/dialogs/GUIDialogKeyboardGeneric.h +++ b/xbmc/dialogs/GUIDialogKeyboardGeneric.h @@ -62,11 +62,9 @@ class CGUIDialogKeyboardGeneric : public CGUIDialog, public CGUIKeyboard private: void OnClickButton(int iButtonControl); void UpdateButtons(); - char GetCharacter(int iButton); void Character(const std::string &ch); void Backspace(); void SetEditText(const std::string& text); - void SendSearchMessage(); float GetStringWidth(const std::wstring& utf16); void ChangeWordList(int direct); // direct: 0 - first page, 1 - next page, -1 - prev page void ShowWordList(int which); // which: 0 - current page, 1 - next page, -1 -prev page diff --git a/xbmc/input/InputCodingTable.h b/xbmc/input/InputCodingTable.h index b870a415c2..0bdd96a8df 100644 --- a/xbmc/input/InputCodingTable.h +++ b/xbmc/input/InputCodingTable.h @@ -30,6 +30,24 @@ public: virtual int GetType() { return TYPE_WORD_LIST; } virtual ~IInputCodingTable() {} + /*! \brief Called for the active keyboard layout when it's loaded, stick any initialization here + + This won't be needed for most implementations so we don't set it =0 but provide a default + implementation. + */ + virtual void Initialize() {} + + /*! \brief Called for the active keyboard layout when it's unloaded, stick any cleanup here + + This won't be needed for most implementations so we don't set it =0 but provide a default + implementation. + */ + virtual void Deinitialize() {} + + /*! \brief Can be overridden if initialization is expensive to avoid calling initialize more than needed + \return true if initialization has beeen done and was successful, false otherwise. + */ + virtual bool IsInitialized() const { return true; } virtual bool GetWordListPage(const std::string& strCode, bool isFirstPage) = 0; virtual std::vector<std::wstring> GetResponse(int response) = 0; const std::string& GetCodeChars() const { return m_codechars; } diff --git a/xbmc/input/InputCodingTableBaiduPY.cpp b/xbmc/input/InputCodingTableBaiduPY.cpp index e8baa3a6df..c79ebe23d6 100644 --- a/xbmc/input/InputCodingTableBaiduPY.cpp +++ b/xbmc/input/InputCodingTableBaiduPY.cpp @@ -26,80 +26,81 @@ #include "filesystem/CurlFile.h" #include "utils/StringUtils.h" #include "utils/RegExp.h" -#include "guilib/GUIMessage.h"
-#include "guilib/GUIWindowManager.h"
-
+#include "guilib/GUIMessage.h" +#include "guilib/GUIWindowManager.h" + CInputCodingTableBaiduPY::CInputCodingTableBaiduPY(const std::string& strUrl) : - CThread("BaiduPYApi"),
- m_messageCounter{ 0 },
- m_api_begin{ 0 },
- m_api_end{ 20 },
- m_api_nomore{ false }
+ CThread("BaiduPYApi"), + m_messageCounter{ 0 }, + m_api_begin{ 0 }, + m_api_end{ 20 }, + m_api_nomore{ false }, + m_initialized{ false } { m_url = strUrl; m_codechars = "abcdefghijklmnopqrstuvwxyz"; m_code = ""; - Create(); } -void CInputCodingTableBaiduPY::Process()
-{
- while (!m_bStop) //Make sure we don't exit the thread
- {
- AbortableWait(m_Event, -1); //Wait for work to appear
- while (!m_bStop) //Process all queued work before going back to wait on the event
- {
- CSingleLock lock(m_CS);
- if (m_work.empty())
- break;
-
- auto work = m_work.front();
- m_work.pop_front();
- lock.Leave();
-
- std::string data;
- XFILE::CCurlFile http;
- std::string strUrl;
- strUrl = StringUtils::Format(m_url.c_str(), work.c_str(), m_api_begin, m_api_end);
-
- if (http.Get(strUrl, data))
- HandleResponse(work, data);
- }
- }
-}
- -void CInputCodingTableBaiduPY::HandleResponse(const std::string& strCode, const std::string& response)
-{
- if (strCode != m_code) // don't handle obsolete response
- return;
-
- std::vector<std::wstring> words;
- CRegExp reg;
- reg.RegComp("\\[\"(.+?)\",[^\\]]+\\]");
- int pos = 0;
- int num = 0;
- while ((pos = reg.RegFind(response.c_str(), pos)) >= 0)
- {
- num++;
- std::string full = reg.GetMatch(0);
- std::string word = reg.GetMatch(1);
- pos += full.length();
- words.push_back(UnicodeToWString(word));
- }
- if (words.size() < 20)
- m_api_nomore = true;
- else
- {
+void CInputCodingTableBaiduPY::Process() +{ + m_initialized = true; + while (!m_bStop) //Make sure we don't exit the thread + { + AbortableWait(m_Event, -1); //Wait for work to appear + while (!m_bStop) //Process all queued work before going back to wait on the event + { + CSingleLock lock(m_CS); + if (m_work.empty()) + break; + + auto work = m_work.front(); + m_work.pop_front(); + lock.Leave(); + + std::string data; + XFILE::CCurlFile http; + std::string strUrl; + strUrl = StringUtils::Format(m_url.c_str(), work.c_str(), m_api_begin, m_api_end); + + if (http.Get(strUrl, data)) + HandleResponse(work, data); + } + } +} + +void CInputCodingTableBaiduPY::HandleResponse(const std::string& strCode, const std::string& response) +{ + if (strCode != m_code) // don't handle obsolete response + return; + + std::vector<std::wstring> words; + CRegExp reg; + reg.RegComp("\\[\"(.+?)\",[^\\]]+\\]"); + int pos = 0; + int num = 0; + while ((pos = reg.RegFind(response.c_str(), pos)) >= 0) + { + num++; + std::string full = reg.GetMatch(0); + std::string word = reg.GetMatch(1); + pos += full.length(); + words.push_back(UnicodeToWString(word)); + } + if (words.size() < 20) + m_api_nomore = true; + else + { m_api_begin += 20; m_api_end += 20; } - CSingleLock lock(m_CS);
- m_responses.insert(std::make_pair(++m_messageCounter, words));
- CGUIMessage msg(GUI_MSG_CODINGTABLE_LOOKUP_COMPLETED, 0, 0, m_messageCounter);
- msg.SetStringParam(strCode);
- lock.Leave();
- g_windowManager.SendThreadMessage(msg, g_windowManager.GetActiveWindowID());
-}
+ CSingleLock lock(m_CS); + m_responses.insert(std::make_pair(++m_messageCounter, words)); + CGUIMessage msg(GUI_MSG_CODINGTABLE_LOOKUP_COMPLETED, 0, 0, m_messageCounter); + msg.SetStringParam(strCode); + lock.Leave(); + g_windowManager.SendThreadMessage(msg, g_windowManager.GetActiveWindowID()); +} std::wstring CInputCodingTableBaiduPY::UnicodeToWString(const std::string& unicode) { @@ -113,13 +114,32 @@ std::wstring CInputCodingTableBaiduPY::UnicodeToWString(const std::string& unico return result; } -std::vector<std::wstring> CInputCodingTableBaiduPY::GetResponse(int response)
-{
- CSingleLock lock(m_CS);
- auto words = m_responses.at(response);
- m_responses.erase(response);
- return words;
-}
+std::vector<std::wstring> CInputCodingTableBaiduPY::GetResponse(int response) +{ + CSingleLock lock(m_CS); + auto words = m_responses.at(response); + m_responses.erase(response); + return words; +} + +void CInputCodingTableBaiduPY::Initialize() +{ + CSingleLock lock(m_CS); + if (!IsRunning()) + Create(); +} + +void CInputCodingTableBaiduPY::Deinitialize() +{ + m_Event.Set(); + StopThread(true); + m_initialized = false; +} + +bool CInputCodingTableBaiduPY::IsInitialized() const +{ + return m_initialized; +} bool CInputCodingTableBaiduPY::GetWordListPage(const std::string& strCode, bool isFirstPage) { @@ -138,8 +158,8 @@ bool CInputCodingTableBaiduPY::GetWordListPage(const std::string& strCode, bool return false; } - CSingleLock lock(m_CS);
- m_work.push_back(strCode);
- m_Event.Set();
+ CSingleLock lock(m_CS); + m_work.push_back(strCode); + m_Event.Set(); return true; } diff --git a/xbmc/input/InputCodingTableBaiduPY.h b/xbmc/input/InputCodingTableBaiduPY.h index 992ee03da0..d00135bfd8 100644 --- a/xbmc/input/InputCodingTableBaiduPY.h +++ b/xbmc/input/InputCodingTableBaiduPY.h @@ -31,6 +31,9 @@ public: CInputCodingTableBaiduPY(const std::string& strUrl); virtual ~CInputCodingTableBaiduPY() {} + virtual void Initialize() override; + virtual void Deinitialize() override; + virtual bool IsInitialized() const override; virtual bool GetWordListPage(const std::string& strCode, bool isFirstPage); virtual void Process(); @@ -45,6 +48,7 @@ private: int m_api_begin; // baidu api begin num int m_api_end; // baidu api end num bool m_api_nomore; + bool m_initialized; std::deque<std::string> m_work; std::map<int, std::vector<std::wstring>> m_responses; diff --git a/xbmc/input/InputCodingTableBasePY.cpp b/xbmc/input/InputCodingTableBasePY.cpp index d040fa4041..7b26a597f6 100644 --- a/xbmc/input/InputCodingTableBasePY.cpp +++ b/xbmc/input/InputCodingTableBasePY.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2005-2013 Team Kodi * http://kodi.tv * @@ -21,7 +21,7 @@ #include <stdlib.h> #include "InputCodingTableBasePY.h" #include "utils/CharsetConverter.h" -#include "guilib/GUIMessage.h"
+#include "guilib/GUIMessage.h" #include "guilib/GUIWindowManager.h" static std::map<std::string, std::wstring> codemap = @@ -443,7 +443,7 @@ CInputCodingTableBasePY::CInputCodingTableBasePY() std::vector<std::wstring> CInputCodingTableBasePY::GetResponse(int) { - return m_words;
+ return m_words; } bool CInputCodingTableBasePY::GetWordListPage(const std::string& strCode, bool isFirstPage) @@ -460,8 +460,8 @@ bool CInputCodingTableBasePY::GetWordListPage(const std::string& strCode, bool i m_words.push_back(finder->second.substr(i, 1)); } } - CGUIMessage msg(GUI_MSG_CODINGTABLE_LOOKUP_COMPLETED, 0, 0, 0);
- msg.SetStringParam(strCode);
- g_windowManager.SendThreadMessage(msg, g_windowManager.GetActiveWindowID());
+ CGUIMessage msg(GUI_MSG_CODINGTABLE_LOOKUP_COMPLETED, 0, 0, 0); + msg.SetStringParam(strCode); + g_windowManager.SendThreadMessage(msg, g_windowManager.GetActiveWindowID()); return true; } diff --git a/xbmc/input/InputCodingTableBasePY.h b/xbmc/input/InputCodingTableBasePY.h index dbb984299a..7d9f6dabf7 100644 --- a/xbmc/input/InputCodingTableBasePY.h +++ b/xbmc/input/InputCodingTableBasePY.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once /* * Copyright (C) 2005-2013 Team Kodi diff --git a/xbmc/input/InputCodingTableKorean.cpp b/xbmc/input/InputCodingTableKorean.cpp index e4522093d0..ee747121ea 100644 --- a/xbmc/input/InputCodingTableKorean.cpp +++ b/xbmc/input/InputCodingTableKorean.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2005-2015 Team Kodi * http://kodi.tv * @@ -28,7 +28,7 @@ CInputCodingTableKorean::CInputCodingTableKorean() std::vector<std::wstring> CInputCodingTableKorean::GetResponse(int) { - return m_words;
+ return m_words; } bool CInputCodingTableKorean::GetWordListPage(const std::string& strCode, bool isFirstPage) @@ -50,314 +50,314 @@ int CInputCodingTableKorean::MergeCode(int choseong, int jungseong, int jongseon // https://en.wikipedia.org/wiki/Hangul // http://www.theyt.net/wiki/%ED%95%9C%EC%98%81%ED%83%80%EB%B3%80%ED%99%98%EA%B8%B0 -std::wstring CInputCodingTableKorean::InputToKorean(const std::wstring& input)
-{
- std::wstring dicEnglish = L"rRseEfaqQtTdwWczxvgkoiOjpuPhynbml";
- std::wstring dicKorean = L"ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎㅏㅐㅑㅒㅓㅔㅕㅖㅗㅛㅜㅠㅡㅣ";
- std::wstring dicChoseong = L"ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ";
- std::wstring dicJungseong = L"ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ";
- std::wstring dicJongseong = L"ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ";
-
- std::wstring korean;
-
- if (input.empty())
- return korean;
-
- int choseong = -1, jungseong = -1, jongseong = -1;
-
- for (unsigned int i = 0; i < input.size(); i++)
- {
- wchar_t ch = input.at(i);
- int key = dicKorean.find(ch);
-
+std::wstring CInputCodingTableKorean::InputToKorean(const std::wstring& input) +{ + std::wstring dicEnglish = L"rRseEfaqQtTdwWczxvgkoiOjpuPhynbml"; + std::wstring dicKorean = L"ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎㅏㅐㅑㅒㅓㅔㅕㅖㅗㅛㅜㅠㅡㅣ"; + std::wstring dicChoseong = L"ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ"; + std::wstring dicJungseong = L"ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ"; + std::wstring dicJongseong = L"ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ"; + + std::wstring korean; + + if (input.empty()) + return korean; + + int choseong = -1, jungseong = -1, jongseong = -1; + + for (unsigned int i = 0; i < input.size(); i++) + { + wchar_t ch = input.at(i); + int key = dicKorean.find(ch); + // H/W Keyboard input with English will be changed to Korean - // because H/W input in Korean is not supported.
- if (key == -1)
- key = dicEnglish.find(ch);
-
- if (key == -1) // If not Korean and English
- {
- // If there is remained Korean, merge code into character
- if (choseong != -1) // There is choseong
- {
- if (jungseong != -1) // choseong+jungseong+(jongseong)
- korean += MergeCode(choseong, jungseong, jongseong);
- else // Only choseong
- korean += dicChoseong.at(choseong);
- }
- else
- {
- if (jungseong != -1) // Jungseong
- korean += dicJungseong.at(jungseong);
-
- if (jongseong != -1) // Jongseong
- korean += dicJongseong.at(jongseong);
- }
- choseong = -1;
- jungseong = -1;
- jongseong = -1;
- korean += ch;
- }
- else if (key < 19) // If key is consonant, key could be choseong or jungseong
- {
- if (jungseong != -1)
- {
+ // because H/W input in Korean is not supported. + if (key == -1) + key = dicEnglish.find(ch); + + if (key == -1) // If not Korean and English + { + // If there is remained Korean, merge code into character + if (choseong != -1) // There is choseong + { + if (jungseong != -1) // choseong+jungseong+(jongseong) + korean += MergeCode(choseong, jungseong, jongseong); + else // Only choseong + korean += dicChoseong.at(choseong); + } + else + { + if (jungseong != -1) // Jungseong + korean += dicJungseong.at(jungseong); + + if (jongseong != -1) // Jongseong + korean += dicJongseong.at(jongseong); + } + choseong = -1; + jungseong = -1; + jongseong = -1; + korean += ch; + } + else if (key < 19) // If key is consonant, key could be choseong or jungseong + { + if (jungseong != -1) + { if (choseong == -1) // Jungseong without choseong cannot have jongseong. - // So inputted key is jungseong character, new character is begun.
- {
- korean += dicJungseong.at(jungseong);
- jungseong = -1;
- choseong = key;
- }
- else // Jungseong with choseong can have jongseong.
- {
- if (jongseong == -1) // Chongseong can have two consonant. So this is first consonant of chongseong.
- {
- jongseong = dicJongseong.find(dicKorean.at(key));
+ // So inputted key is jungseong character, new character is begun. + { + korean += dicJungseong.at(jungseong); + jungseong = -1; + choseong = key; + } + else // Jungseong with choseong can have jongseong. + { + if (jongseong == -1) // Chongseong can have two consonant. So this is first consonant of chongseong. + { + jongseong = dicJongseong.find(dicKorean.at(key)); if (jongseong == -1) // This consonant cannot be jongseong. ex) ㄸ, ㅃ, ㅉ - {
- korean += MergeCode(choseong, jungseong, jongseong);
- choseong = dicChoseong.find(dicKorean.at(key));
- jungseong = -1;
- }
- }
- else if (jongseong == 0 && key == 9) // ㄳ
- jongseong = 2;
- else if (jongseong == 3 && key == 12) // ㄵ
- jongseong = 4;
- else if (jongseong == 3 && key == 18) // ㄶ
- jongseong = 5;
- else if (jongseong == 7 && key == 0) // ㄺ
- jongseong = 8;
- else if (jongseong == 7 && key == 6) // ㄻ
- jongseong = 9;
- else if (jongseong == 7 && key == 7) // ㄼ
- jongseong = 10;
- else if (jongseong == 7 && key == 9) // ㄽ
- jongseong = 11;
- else if (jongseong == 7 && key == 16) // ㄾ
- jongseong = 12;
- else if (jongseong == 7 && key == 17) // ㄿ
- jongseong = 13;
- else if (jongseong == 7 && key == 18) // ㅀ
- jongseong = 14;
- else if (jongseong == 16 && key == 9) // ㅄ
- jongseong = 17;
- else // Jongseong is completed. So new consonant is choseong.
- {
- korean += MergeCode(choseong, jungseong, jongseong);
- choseong = dicChoseong.find(dicKorean.at(key));
- jungseong = -1;
- jongseong = -1;
- }
- }
- }
- else // If there is no jungseong, new consonant can be choseong or second part of double consonant.
- {
- if (choseong == -1) // New consonant is choseong. Also it could be first part of double consonant.
- {
+ { + korean += MergeCode(choseong, jungseong, jongseong); + choseong = dicChoseong.find(dicKorean.at(key)); + jungseong = -1; + } + } + else if (jongseong == 0 && key == 9) // ㄳ + jongseong = 2; + else if (jongseong == 3 && key == 12) // ㄵ + jongseong = 4; + else if (jongseong == 3 && key == 18) // ㄶ + jongseong = 5; + else if (jongseong == 7 && key == 0) // ㄺ + jongseong = 8; + else if (jongseong == 7 && key == 6) // ㄻ + jongseong = 9; + else if (jongseong == 7 && key == 7) // ㄼ + jongseong = 10; + else if (jongseong == 7 && key == 9) // ㄽ + jongseong = 11; + else if (jongseong == 7 && key == 16) // ㄾ + jongseong = 12; + else if (jongseong == 7 && key == 17) // ㄿ + jongseong = 13; + else if (jongseong == 7 && key == 18) // ㅀ + jongseong = 14; + else if (jongseong == 16 && key == 9) // ㅄ + jongseong = 17; + else // Jongseong is completed. So new consonant is choseong. + { + korean += MergeCode(choseong, jungseong, jongseong); + choseong = dicChoseong.find(dicKorean.at(key)); + jungseong = -1; + jongseong = -1; + } + } + } + else // If there is no jungseong, new consonant can be choseong or second part of double consonant. + { + if (choseong == -1) // New consonant is choseong. Also it could be first part of double consonant. + { if (jongseong != -1) // If choseong is already completed, new consonant is another choseong. - // So previous character has only jongseong.
- {
- korean += dicJongseong.at(jongseong);
- jongseong = -1;
- }
- choseong = dicChoseong.find(dicKorean.at(key));
- }
- // Find double consonant of chongseong
- else if (choseong == 0 && key == 9) // ㄳ
- {
- choseong = -1;
- jongseong = 2;
- }
- else if (choseong == 2 && key == 12) // ㄵ
- {
- choseong = -1;
- jongseong = 4;
- }
- else if (choseong == 2 && key == 18) // ㄶ
- {
- choseong = -1;
- jongseong = 5;
- }
- else if (choseong == 5 && key == 0) // ㄺ
- {
- choseong = -1;
- jongseong = 8;
- }
- else if (choseong == 5 && key == 6) // ㄻ
- {
- choseong = -1;
- jongseong = 9;
- }
- else if (choseong == 5 && key == 7) // ㄼ
- {
- choseong = -1;
- jongseong = 10;
- }
- else if (choseong == 5 && key == 9) // ㄽ
- {
- choseong = -1;
- jongseong = 11;
- }
- else if (choseong == 5 && key == 16) // ㄾ
- {
- choseong = -1;
- jongseong = 12;
- }
- else if (choseong == 5 && key == 17) // ㄿ
- {
- choseong = -1;
- jongseong = 13;
- }
- else if (choseong == 5 && key == 18) // ㅀ
- {
- choseong = -1;
- jongseong = 14;
- }
- else if (choseong == 7 && key == 9) // ㅄ
- {
- choseong = -1;
- jongseong = 17;
- }
- else // In this case, previous character has only choseong. And new consonant is choseong.
- {
- korean += dicChoseong.at(choseong);
- choseong = dicChoseong.find(dicKorean.at(key));
- }
- }
- }
- else // If key is vowel, key is jungseong.
- {
+ // So previous character has only jongseong. + { + korean += dicJongseong.at(jongseong); + jongseong = -1; + } + choseong = dicChoseong.find(dicKorean.at(key)); + } + // Find double consonant of chongseong + else if (choseong == 0 && key == 9) // ㄳ + { + choseong = -1; + jongseong = 2; + } + else if (choseong == 2 && key == 12) // ㄵ + { + choseong = -1; + jongseong = 4; + } + else if (choseong == 2 && key == 18) // ㄶ + { + choseong = -1; + jongseong = 5; + } + else if (choseong == 5 && key == 0) // ㄺ + { + choseong = -1; + jongseong = 8; + } + else if (choseong == 5 && key == 6) // ㄻ + { + choseong = -1; + jongseong = 9; + } + else if (choseong == 5 && key == 7) // ㄼ + { + choseong = -1; + jongseong = 10; + } + else if (choseong == 5 && key == 9) // ㄽ + { + choseong = -1; + jongseong = 11; + } + else if (choseong == 5 && key == 16) // ㄾ + { + choseong = -1; + jongseong = 12; + } + else if (choseong == 5 && key == 17) // ㄿ + { + choseong = -1; + jongseong = 13; + } + else if (choseong == 5 && key == 18) // ㅀ + { + choseong = -1; + jongseong = 14; + } + else if (choseong == 7 && key == 9) // ㅄ + { + choseong = -1; + jongseong = 17; + } + else // In this case, previous character has only choseong. And new consonant is choseong. + { + korean += dicChoseong.at(choseong); + choseong = dicChoseong.find(dicKorean.at(key)); + } + } + } + else // If key is vowel, key is jungseong. + { if (jongseong != -1) // If previous character has jongseong and this key is jungseong, - // actually latest vowel is not jongseong. It's choseong of new character.
- {
- // If jongseong of previous character is double consonant, we will seperate it to two vowel again.
- // First part of double consonant is jongseong of previous character.
- // Second part of double consonant is choseong of current character.
- int newCho;
- if (jongseong == 2) // ㄱ, ㅅ
- {
- jongseong = 0;
- newCho = 9;
- }
- else if (jongseong == 4) // ㄴ, ㅈ
- {
- jongseong = 3;
- newCho = 12;
- }
- else if (jongseong == 5) // ㄴ, ㅎ
- {
- jongseong = 3;
- newCho = 18;
- }
- else if (jongseong == 8) // ㄹ, ㄱ
- {
- jongseong = 7;
- newCho = 0;
- }
- else if (jongseong == 9) // ㄹ, ㅁ
- {
- jongseong = 7;
- newCho = 6;
- }
- else if (jongseong == 10) // ㄹ, ㅂ
- {
- jongseong = 7;
- newCho = 7;
- }
- else if (jongseong == 11) // ㄹ, ㅅ
- {
- jongseong = 7;
- newCho = 9;
- }
- else if (jongseong == 12) // ㄹ, ㅌ
- {
- jongseong = 7;
- newCho = 16;
- }
- else if (jongseong == 13) // ㄹ, ㅍ
- {
- jongseong = 7;
- newCho = 17;
- }
- else if (jongseong == 14) // ㄹ, ㅎ
- {
- jongseong = 7;
- newCho = 18;
- }
- else if (jongseong == 17) // ㅂ, ㅅ
- {
- jongseong = 16;
- newCho = 9;
- }
+ // actually latest vowel is not jongseong. It's choseong of new character. + { + // If jongseong of previous character is double consonant, we will seperate it to two vowel again. + // First part of double consonant is jongseong of previous character. + // Second part of double consonant is choseong of current character. + int newCho; + if (jongseong == 2) // ㄱ, ㅅ + { + jongseong = 0; + newCho = 9; + } + else if (jongseong == 4) // ㄴ, ㅈ + { + jongseong = 3; + newCho = 12; + } + else if (jongseong == 5) // ㄴ, ㅎ + { + jongseong = 3; + newCho = 18; + } + else if (jongseong == 8) // ㄹ, ㄱ + { + jongseong = 7; + newCho = 0; + } + else if (jongseong == 9) // ㄹ, ㅁ + { + jongseong = 7; + newCho = 6; + } + else if (jongseong == 10) // ㄹ, ㅂ + { + jongseong = 7; + newCho = 7; + } + else if (jongseong == 11) // ㄹ, ㅅ + { + jongseong = 7; + newCho = 9; + } + else if (jongseong == 12) // ㄹ, ㅌ + { + jongseong = 7; + newCho = 16; + } + else if (jongseong == 13) // ㄹ, ㅍ + { + jongseong = 7; + newCho = 17; + } + else if (jongseong == 14) // ㄹ, ㅎ + { + jongseong = 7; + newCho = 18; + } + else if (jongseong == 17) // ㅂ, ㅅ + { + jongseong = 16; + newCho = 9; + } else // If jongseong is single consonant, previous character has no chongseong. - // It's choseong of current character.
- {
- newCho = dicChoseong.find(dicJongseong.at(jongseong));
- jongseong = -1;
- }
- if (choseong != -1) // If previous character has choseong and jungseong.
- korean += MergeCode(choseong, jungseong, jongseong);
- else // If previous character has Jongseong only.
- korean += dicJongseong.at(jongseong);
-
- choseong = newCho;
- jungseong = -1;
- jongseong = -1;
- }
- if (jungseong == -1) // If this key is first vowel, it's first part of jungseong.
- {
- jungseong = dicJungseong.find(dicKorean.at(key));
- }
- // If there is jungseong already, jungseong is double vowel.
- else if (jungseong == 8 && key == 19) // ㅘ
- jungseong = 9;
- else if (jungseong == 8 && key == 20) // ㅙ
- jungseong = 10;
- else if (jungseong == 8 && key == 32) // ㅚ
- jungseong = 11;
- else if (jungseong == 13 && key == 23) // ㅝ
- jungseong = 14;
- else if (jungseong == 13 && key == 24) // ㅞ
- jungseong = 15;
- else if (jungseong == 13 && key == 32) // ㅟ
- jungseong = 16;
- else if (jungseong == 18 && key == 32) // ㅢ
- jungseong = 19;
- else // If two vowel cannot be double vowel.
- {
+ // It's choseong of current character. + { + newCho = dicChoseong.find(dicJongseong.at(jongseong)); + jongseong = -1; + } + if (choseong != -1) // If previous character has choseong and jungseong. + korean += MergeCode(choseong, jungseong, jongseong); + else // If previous character has Jongseong only. + korean += dicJongseong.at(jongseong); + + choseong = newCho; + jungseong = -1; + jongseong = -1; + } + if (jungseong == -1) // If this key is first vowel, it's first part of jungseong. + { + jungseong = dicJungseong.find(dicKorean.at(key)); + } + // If there is jungseong already, jungseong is double vowel. + else if (jungseong == 8 && key == 19) // ㅘ + jungseong = 9; + else if (jungseong == 8 && key == 20) // ㅙ + jungseong = 10; + else if (jungseong == 8 && key == 32) // ㅚ + jungseong = 11; + else if (jungseong == 13 && key == 23) // ㅝ + jungseong = 14; + else if (jungseong == 13 && key == 24) // ㅞ + jungseong = 15; + else if (jungseong == 13 && key == 32) // ㅟ + jungseong = 16; + else if (jungseong == 18 && key == 32) // ㅢ + jungseong = 19; + else // If two vowel cannot be double vowel. + { if (choseong != -1) // Previous character is completed. - // Current character is begin with jungseong.
- {
- korean += MergeCode(choseong, jungseong, jongseong);
- choseong = -1;
- }
- else // Previous character has jungseon only.
- korean += dicJungseong.at(jungseong);
- jungseong = -1;
- korean += dicKorean.at(key);
- }
- }
- }
-
- // Process last character
- if (choseong != -1)
- {
- if (jungseong != -1) // Current character has choseong and jungseong.
- korean += MergeCode(choseong, jungseong, jongseong);
- else // Current character has choseong only.
- korean += dicChoseong.at(choseong);
- }
- else
- {
- if (jungseong != -1) // Current character has jungseong only
- korean += dicJungseong.at(jungseong);
- else if (jongseong != -1) // Current character has jongseong only
- korean += dicJongseong.at(jongseong);
- }
-
- return korean;
+ // Current character is begin with jungseong. + { + korean += MergeCode(choseong, jungseong, jongseong); + choseong = -1; + } + else // Previous character has jungseon only. + korean += dicJungseong.at(jungseong); + jungseong = -1; + korean += dicKorean.at(key); + } + } + } + + // Process last character + if (choseong != -1) + { + if (jungseong != -1) // Current character has choseong and jungseong. + korean += MergeCode(choseong, jungseong, jongseong); + else // Current character has choseong only. + korean += dicChoseong.at(choseong); + } + else + { + if (jungseong != -1) // Current character has jungseong only + korean += dicJungseong.at(jungseong); + else if (jongseong != -1) // Current character has jongseong only + korean += dicJongseong.at(jongseong); + } + + return korean; } std::string CInputCodingTableKorean::ConvertString(const std::string& strCode) diff --git a/xbmc/input/InputCodingTableKorean.h b/xbmc/input/InputCodingTableKorean.h index 15582a4c83..d2d3d9b4f9 100644 --- a/xbmc/input/InputCodingTableKorean.h +++ b/xbmc/input/InputCodingTableKorean.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once /* * Copyright (C) 2005-2015 Team Kodi |