linux_enchant.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* enchant
  2. * Copyright (C) 2003 Dom Lachowicz
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. * In addition, as a special exception, Dom Lachowicz
  20. * gives permission to link the code of this program with
  21. * non-LGPL Spelling Provider libraries (eg: a MSFT Office
  22. * spell checker backend) and distribute linked combinations including
  23. * the two. You must obey the GNU Lesser General Public License in all
  24. * respects for all of the code used other than said providers. If you modify
  25. * this file, you may extend this exception to your version of the
  26. * file, but you are not obligated to do so. If you do not wish to
  27. * do so, delete this exception statement from your version.
  28. *
  29. * Nicholas Guriev (email: guriev-ns@ya.ru) split the full <enchant++.h> header
  30. * into two files, linux_enchant.h and linux_enchant.cpp, to use within Desktop
  31. * App Toolkit. He also implemented explicit linking with dlopen/dlsym to avoid
  32. * rigid dependency on the Enchant library at runtime.
  33. */
  34. #pragma once
  35. #include <string>
  36. #include <vector>
  37. #include <exception>
  38. #ifndef ENCHANT_H
  39. typedef struct str_enchant_broker EnchantBroker;
  40. typedef struct str_enchant_dict EnchantDict;
  41. /**
  42. * EnchantBrokerDescribeFn
  43. * @provider_name: The provider's identifier, such as "ispell" or "aspell" in UTF8 encoding
  44. * @provider_desc: A description of the provider, such as "Aspell 0.53" in UTF8 encoding
  45. * @provider_dll_file: The provider's DLL filename in Glib file encoding (UTF8 on Windows)
  46. * @user_data: Supplied user data, or %null if you don't care
  47. *
  48. * Callback used to enumerate and describe Enchant's various providers
  49. */
  50. typedef void (*EnchantBrokerDescribeFn) (const char * const provider_name,
  51. const char * const provider_desc,
  52. const char * const provider_dll_file,
  53. void * user_data);
  54. /**
  55. * EnchantDictDescribeFn
  56. * @lang_tag: The dictionary's language tag (eg: en_US, de_AT, ...)
  57. * @provider_name: The provider's name (eg: Aspell) in UTF8 encoding
  58. * @provider_desc: The provider's description (eg: Aspell 0.50.3) in UTF8 encoding
  59. * @provider_file: The DLL/SO where this dict's provider was loaded from in Glib file encoding (UTF8 on Windows)
  60. * @user_data: Supplied user data, or %null if you don't care
  61. *
  62. * Callback used to describe an individual dictionary
  63. */
  64. typedef void (*EnchantDictDescribeFn) (const char * const lang_tag,
  65. const char * const provider_name,
  66. const char * const provider_desc,
  67. const char * const provider_file,
  68. void * user_data);
  69. #endif // !ENCHANT_H
  70. namespace enchant
  71. {
  72. class Broker;
  73. class Exception : public std::exception
  74. {
  75. public:
  76. explicit Exception (const char * ex);
  77. virtual ~Exception () noexcept;
  78. virtual const char * what () const noexcept;
  79. private:
  80. std::string m_ex;
  81. }; // class enchant::Exception
  82. class Dict
  83. {
  84. friend class enchant::Broker;
  85. public:
  86. ~Dict ();
  87. bool check (const std::string & utf8word);
  88. void suggest (const std::string & utf8word,
  89. std::vector<std::string> & out_suggestions);
  90. std::vector<std::string> suggest (const std::string & utf8word) {
  91. std::vector<std::string> result;
  92. suggest (utf8word, result);
  93. return result;
  94. }
  95. void add (const std::string & utf8word);
  96. void add_to_session (const std::string & utf8word);
  97. bool is_added (const std::string & utf8word);
  98. void remove (const std::string & utf8word);
  99. void remove_from_session (const std::string & utf8word);
  100. bool is_removed (const std::string & utf8word);
  101. void store_replacement (const std::string & utf8bad,
  102. const std::string & utf8good);
  103. const std::string & get_lang () const {
  104. return m_lang;
  105. }
  106. const std::string & get_provider_name () const {
  107. return m_provider_name;
  108. }
  109. const std::string & get_provider_desc () const {
  110. return m_provider_desc;
  111. }
  112. const std::string & get_provider_file () const {
  113. return m_provider_file;
  114. }
  115. private:
  116. // space reserved for API/ABI expansion
  117. void * _private[5];
  118. static void s_describe_fn (const char * const lang,
  119. const char * const provider_name,
  120. const char * const provider_desc,
  121. const char * const provider_file,
  122. void * user_data) {
  123. enchant::Dict * dict = static_cast<enchant::Dict *> (user_data);
  124. dict->m_lang = lang;
  125. dict->m_provider_name = provider_name;
  126. dict->m_provider_desc = provider_desc;
  127. dict->m_provider_file = provider_file;
  128. }
  129. Dict (EnchantDict * dict, EnchantBroker * broker);
  130. // private, unimplemented
  131. Dict () = delete;
  132. Dict (const Dict & rhs) = delete;
  133. Dict& operator=(const Dict & rhs) = delete;
  134. EnchantDict * m_dict;
  135. EnchantBroker * m_broker;
  136. std::string m_lang;
  137. std::string m_provider_name;
  138. std::string m_provider_desc;
  139. std::string m_provider_file;
  140. }; // class enchant::Dict
  141. class Broker
  142. {
  143. public:
  144. Broker ();
  145. ~Broker ();
  146. Dict * request_dict (const std::string & lang);
  147. Dict * request_pwl_dict (const std::string & pwl);
  148. bool dict_exists (const std::string & lang);
  149. void set_ordering (const std::string & tag, const std::string & ordering);
  150. void describe (EnchantBrokerDescribeFn fn, void * user_data = nullptr);
  151. void list_dicts (EnchantDictDescribeFn fn, void * user_data = nullptr);
  152. private:
  153. // space reserved for API/ABI expansion
  154. void * _private[5];
  155. // not implemented
  156. Broker (const Broker & rhs) = delete;
  157. Broker& operator=(const Broker & rhs) = delete;
  158. EnchantBroker * m_broker;
  159. }; // class enchant::Broker
  160. namespace loader {
  161. bool do_explicit_linking ();
  162. } // loader subnamespace
  163. } // enchant namespace
  164. // vi: ts=8 sw=8