t-suw****@users*****
t-suw****@users*****
2007年 10月 14日 (日) 14:52:05 JST
Index: AquaSKK/src/backend/SKKBackEnd.cpp diff -u /dev/null AquaSKK/src/backend/SKKBackEnd.cpp:1.1.2.1 --- /dev/null Sun Oct 14 14:52:05 2007 +++ AquaSKK/src/backend/SKKBackEnd.cpp Sun Oct 14 14:52:05 2007 @@ -0,0 +1,58 @@ +/* -*- C++ -*- + MacOS X implementation of the SKK input method. + + Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "SKKBackEnd.h" +#include "SKKBackEndImpl.h" + +// è£å® +bool SKKBackEnd::Complete(const std::string& entry, std::vector<std::string>& result) { + return SKKBackEndImpl::Complete(entry, result); +} + +// æ¤ç´¢ +bool SKKBackEnd::FindOkuriAri(const std::string& entry, const std::string& okuri, SKK::CandidateContainer& result) { + return SKKBackEndImpl::FindOkuriAri(entry, okuri, result); +} + +bool SKKBackEnd::FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result) { + return SKKBackEndImpl::FindOkuriNasi(entry, result); +} + +// ç»é² +bool SKKBackEnd::RegisterOkuriAri(const std::string& entry, const std::string& okuri, const SKK::Candidate& candidate) { + return SKKBackEndImpl::RegisterOkuriAri(entry, okuri, candidate); +} + +bool SKKBackEnd::RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) { + return SKKBackEndImpl::RegisterOkuriNasi(entry, candidate); +} + +bool SKKBackEnd::RegisterToggleEntry(const std::string& entry) { + return SKKBackEndImpl::RegisterToggleEntry(entry); +} + +// åé¤ +bool SKKBackEnd::RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate) { + return SKKBackEndImpl::RemoveOkuriAri(entry, candidate); +} + +bool SKKBackEnd::RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) { + return SKKBackEndImpl::RemoveOkuriNasi(entry, candidate); +} Index: AquaSKK/src/backend/SKKBackEnd.h diff -u /dev/null AquaSKK/src/backend/SKKBackEnd.h:1.1.2.1 --- /dev/null Sun Oct 14 14:52:05 2007 +++ AquaSKK/src/backend/SKKBackEnd.h Sun Oct 14 14:52:05 2007 @@ -0,0 +1,46 @@ +/* -*- C++ -*- + MacOS X implementation of the SKK input method. + + Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef INC__SKKBackEnd__ +#define INC__SKKBackEnd__ + +#include "SKK.h" + +// è¾æ¸é¢é£ã®æä½ +class SKKBackEnd { +public: + // è£å® + static bool Complete(const std::string& entry, std::vector<std::string>& result); + + // æ¤ç´¢ + static bool FindOkuriAri(const std::string& entry, const std::string& okuri, SKK::CandidateContainer& result); + static bool FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result); + + // ç»é² + static bool RegisterOkuriAri(const std::string& entry, const std::string& okuri, const SKK::Candidate& candidate); + static bool RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate); + static bool RegisterToggleEntry(const std::string& entry); + + // åé¤ + static bool RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate); + static bool RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate); +}; + +#endif Index: AquaSKK/src/backend/SKKBackEndImpl.h diff -u /dev/null AquaSKK/src/backend/SKKBackEndImpl.h:1.1.2.1 --- /dev/null Sun Oct 14 14:52:05 2007 +++ AquaSKK/src/backend/SKKBackEndImpl.h Sun Oct 14 14:52:05 2007 @@ -0,0 +1,50 @@ +/* -*- C++ -*- + MacOS X implementation of the SKK input method. + + Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef INC__SKKBackEndImpl__ +#define INC__SKKBackEndImpl__ + +#include "SKK.h" + +// å®è£ +class SKKBackEndImpl { +public: + // è£å® + static bool Complete(const std::string& entry, std::vector<std::string>& result); + + // æ¤ç´¢ + static bool FindOkuriAri(const std::string& entry, const std::string& kana, SKK::CandidateContainer& result); + static bool FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result); + + // ç»é² + static bool RegisterOkuriAri(const std::string& entry, const std::string& okuri, const SKK::Candidate& candidate); + static bool RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate); + static bool RegisterToggleEntry(const std::string& entry); + + // åé¤ + static bool RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate); + static bool RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate); +}; + +#ifdef __APPLE__ +#include "SKKCarbonBackEnd.cpp" +#endif + +#endif Index: AquaSKK/src/backend/SKKCarbonBackEnd.cpp diff -u /dev/null AquaSKK/src/backend/SKKCarbonBackEnd.cpp:1.1.2.1 --- /dev/null Sun Oct 14 14:52:05 2007 +++ AquaSKK/src/backend/SKKCarbonBackEnd.cpp Sun Oct 14 14:52:05 2007 @@ -0,0 +1,222 @@ +/* -*- C++ -*- + $Id: SKKCarbonBackEnd.cpp,v 1.1.2.1 2007/10/14 05:52:05 t-suwa Exp $ + + MacOS X implementation of the SKK input method. + + Copyright (C) 2007 Tomotaka SUWA <t.suw****@mac*****> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <set> +#include <sstream> +#include <algorithm> + +#include "CppCFString.h" +#include "CppCFData.h" +#include "ServerConnection.h" +#include "ServerConnectionFactory.h" +#include "BIMClientServer.h" +#include "ClientConfiguration.h" +#include "NumericConverter.h" + +// ====================================================================== +// ã¦ã¼ãã£ãªã㣠+// ====================================================================== + +static CppCFString CppCFStringFromUTF8(const std::string& utf8) { + return CppCFString(utf8.c_str(), kCFStringEncodingUTF8); +} + +// å¤æãµã¼ãã¼ãå¼ã³åºã +static CppCFString ServerCall(int cmd, const CppCFString& query) { + CppCFData data(query.toCFData()); + ServerConnection connection = ServerConnectionFactory::theInstance().newConnection(); + + CppCFString result(connection.send(cmd, data, kAquaSKKServerRunLoopMode).getData()); + + return result; +} + +// æ¤ç´¢çµæ â SKK::CandidateContainer å¤æ +static void ExpandCandidate(const CppCFString& str, SKK::CandidateContainer& result, NumericConverter* conv = 0) { + std::vector<CppCFString> tmp = str.split(SKK_MSG_DELIMITER); + SKK::Candidate candidate; + + result.clear(); + + for(unsigned i = 0; i < tmp.size(); ++ i) { + tmp[i].decode(); + + // æ°å¤å¤æãæå¹ãï¼ + if(conv) { + // ãªãªã¸ãã«ã®å¤æåè£ã¨ã表示ç¨ã®å¤æåè£ãç¨æãã¦ãã(OAOO ã®åå) + candidate.SetBody(tmp[i].toStdString(kCFStringEncodingUTF8)); + candidate.SetFace(conv->Apply(candidate.Body())); + + result.push_back(candidate); + } else { + result.push_back(tmp[i].toStdString(kCFStringEncodingUTF8)); + } + } +} + +// ãã¼ã¸ +static void MergeCandidate(const std::string& entry, SKK::CandidateContainer& ret1, SKK::CandidateContainer& ret2) { + SKK::CandidateContainer result; + + typedef std::set<std::string> Check; + Check check; + + struct local { + static void unique(SKK::CandidateContainer& src, SKK::CandidateContainer& result, Check& check) { + for(SKK::CandidateIterator iter = src.begin(); iter != src.end(); ++ iter) { + if(check.find(iter->Face()) != check.end()) continue; + + check.insert(check.lower_bound(iter->Face()), iter->Face()); + result.push_back(iter->Face()); + } + } + }; + + check.insert(entry); + + local::unique(ret1, result, check); + local::unique(ret2, result, check); + + result.swap(ret1); +} + +// ====================================================================== +// SKKBackEndImpl ã¤ã³ã¿ãã§ã¼ã¹ +// ====================================================================== + +// è£å® +bool SKKBackEndImpl::Complete(const std::string& entry, std::vector<std::string>& result) { + CppCFString str(entry.c_str(), kCFStringEncodingUTF8); + str = ServerCall(kSKKFetchCompletions, str); + + std::string tmp = str.toStdString(kCFStringEncodingUTF8); + std::replace(tmp.begin(), tmp.end(), (char)SKK_MSG_DELIMITER, ' '); + std::istringstream buf(tmp); + + result.clear(); + while(buf >> tmp) { + result.push_back(tmp); + } + + return !result.empty(); +} + +// æ¤ç´¢ +bool SKKBackEndImpl::FindOkuriAri(const std::string& entry, const std::string& okuri, SKK::CandidateContainer& result) { + CppCFString query('+'); + + query.append(CppCFStringFromUTF8(entry)); + query.append(SKK_MSG_DELIMITER); + query.append(CppCFStringFromUTF8(okuri)); + + ExpandCandidate(ServerCall(kSKKMessageSearch, query), result); + + return !result.empty(); +} + +bool SKKBackEndImpl::FindOkuriNasi(const std::string& entry, SKK::CandidateContainer& result) { + CppCFString query('-'); + + query.append(CppCFStringFromUTF8(entry)); + + ExpandCandidate(ServerCall(kSKKMessageSearch, query), result); + + // æ°å¤å¤æãæå¹ï¼ + if(ClientConfiguration::theInstance().useNumericConversion()) { + NumericConverter conv; + + // æ£è¦åã§ããªããã°çµäº + if(!conv.Setup(entry)) { + return !result.empty(); + } + + // æ£è¦åããæååã§åæ¤ç´¢ãã + query.clear(); + query.append('-'); + query.append(CppCFStringFromUTF8(conv.NormalizedKey())); + + SKK::CandidateContainer tmp; + ExpandCandidate(ServerCall(kSKKMessageSearch, query), tmp, &conv); + MergeCandidate(entry, result, tmp); + } + + return !result.empty(); +} + +// ç»é² +bool SKKBackEndImpl::RegisterOkuriAri(const std::string& entry, const std::string& okuri, + const SKK::Candidate& candidate) { + CppCFString query('+'); + + query.append(CppCFStringFromUTF8(entry)); + query.append(SKK_MSG_DELIMITER); + query.append(CppCFStringFromUTF8(okuri)); + query.append(SKK_MSG_DELIMITER); + query.append(CppCFStringFromUTF8(candidate.Body())); + + ServerCall(kSKKRegisterThisToUserDic, query); + + return true; +} + +bool SKKBackEndImpl::RegisterOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) { + CppCFString query('-'); + + query.append(CppCFStringFromUTF8(entry)); + query.append(SKK_MSG_DELIMITER); + query.append(CppCFStringFromUTF8(candidate.Body())); + + ServerCall(kSKKRegisterThisToUserDic, query); + + return true; +} + +bool SKKBackEndImpl::RegisterToggleEntry(const std::string& entry) { + ServerCall(kSKKRegisterToggleEntry, CppCFStringFromUTF8(entry)); + + return true; +} + +// åé¤ +bool SKKBackEndImpl::RemoveOkuriAri(const std::string& entry, const SKK::Candidate& candidate) { + CppCFString query('+'); + + query.append(CppCFStringFromUTF8(entry)); + query.append(SKK_MSG_DELIMITER); + query.append(CppCFStringFromUTF8(candidate.Body())); + + ServerCall(kSKKRemoveThisFromUserDic, query); + + return true; +} + +bool SKKBackEndImpl::RemoveOkuriNasi(const std::string& entry, const SKK::Candidate& candidate) { + CppCFString query('-'); + + query.append(CppCFStringFromUTF8(entry)); + query.append(SKK_MSG_DELIMITER); + query.append(CppCFStringFromUTF8(candidate.Body())); + + ServerCall(kSKKRemoveThisFromUserDic, query); + + return true; +}