2006-12-24 22:52:54 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
2006-01-16 22:02:54 +01:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file spellchecker_hunspell.cpp
|
|
|
|
/// @brief Hunspell-based spell checker implementation
|
|
|
|
/// @ingroup spelling
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-16 19:29:29 +01:00
|
|
|
|
2007-12-31 07:46:22 +01:00
|
|
|
#ifdef WITH_HUNSPELL
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2007-01-01 05:15:54 +01:00
|
|
|
#include <wx/dir.h>
|
2007-01-01 06:15:05 +01:00
|
|
|
#include <wx/filename.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
#include <wx/log.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/txtstrm.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-01 10:21:30 +02:00
|
|
|
#include <libaegisub/log.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <hunspell/hunspell.hxx>
|
|
|
|
|
|
|
|
#include "charset_conv.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
|
|
|
#include "main.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "spellchecker_hunspell.h"
|
|
|
|
#include "standard_paths.h"
|
2010-06-03 22:32:25 +02:00
|
|
|
#include "text_file_reader.h"
|
|
|
|
#include "text_file_writer.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2007-04-22 04:03:40 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Constructor
|
2006-12-24 22:52:54 +01:00
|
|
|
HunspellSpellChecker::HunspellSpellChecker() {
|
2007-01-01 05:15:54 +01:00
|
|
|
hunspell = NULL;
|
2006-12-26 01:12:18 +01:00
|
|
|
conv = NULL;
|
2010-06-03 22:32:25 +02:00
|
|
|
rconv = NULL;
|
2010-05-21 03:13:36 +02:00
|
|
|
SetLanguage(lagi_wxString(OPT_GET("Tool/Spell Checker/Language")->GetString()));
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Destructor
|
2006-12-24 22:52:54 +01:00
|
|
|
HunspellSpellChecker::~HunspellSpellChecker() {
|
2007-01-02 01:47:47 +01:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Reset spelling library
|
2007-01-02 01:47:47 +01:00
|
|
|
void HunspellSpellChecker::Reset() {
|
2006-12-24 22:52:54 +01:00
|
|
|
delete hunspell;
|
|
|
|
hunspell = NULL;
|
2006-12-26 01:12:18 +01:00
|
|
|
delete conv;
|
|
|
|
conv = NULL;
|
2010-06-03 22:32:25 +02:00
|
|
|
delete rconv;
|
|
|
|
rconv = NULL;
|
2007-01-02 01:47:47 +01:00
|
|
|
affpath.Clear();
|
|
|
|
dicpath.Clear();
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Can add to dictionary?
|
|
|
|
/// @param word Word to check.
|
|
|
|
/// @return Whether word can be added or not.
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2006-12-26 02:08:46 +01:00
|
|
|
bool HunspellSpellChecker::CanAddWord(wxString word) {
|
|
|
|
if (!hunspell) return false;
|
2010-06-03 22:32:25 +02:00
|
|
|
try {
|
2010-06-03 22:54:46 +02:00
|
|
|
conv->Convert(STD_STR(word));
|
2010-06-03 22:32:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (agi::charset::ConvError const&) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-12-26 02:08:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Add word to dictionary
|
|
|
|
/// @param word Word to add.
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2006-12-25 06:43:00 +01:00
|
|
|
void HunspellSpellChecker::AddWord(wxString word) {
|
2007-01-02 01:47:47 +01:00
|
|
|
// Dictionary OK?
|
|
|
|
if (!hunspell) return;
|
|
|
|
|
|
|
|
// Add to currently loaded file
|
2008-01-15 18:24:49 +01:00
|
|
|
#ifdef WITH_OLD_HUNSPELL
|
2010-06-03 22:54:46 +02:00
|
|
|
hunspell->put_word(conv->Convert(STD_STR(word)).c_str());
|
2008-01-15 18:24:49 +01:00
|
|
|
#else
|
2010-06-03 22:54:46 +02:00
|
|
|
hunspell->add(conv->Convert(STD_STR(word)).c_str());
|
2008-01-15 18:24:49 +01:00
|
|
|
#endif
|
2007-01-02 01:47:47 +01:00
|
|
|
|
2008-01-14 03:01:50 +01:00
|
|
|
// Ensure that the path exists
|
|
|
|
wxFileName fn(usrdicpath);
|
|
|
|
if (!fn.DirExists()) {
|
|
|
|
wxFileName::Mkdir(fn.GetPath());
|
|
|
|
}
|
|
|
|
|
2007-01-02 01:47:47 +01:00
|
|
|
// Load dictionary
|
|
|
|
wxArrayString dic;
|
2008-01-14 03:01:50 +01:00
|
|
|
bool added = false;
|
|
|
|
if (fn.FileExists()) { // Even if you ever want to remove this "if", keep the braces, so the stream closes at the end
|
2007-01-02 01:47:47 +01:00
|
|
|
bool first = true;
|
2010-06-03 22:32:25 +02:00
|
|
|
TextFileReader reader(usrdicpath, L"UTF-8");
|
|
|
|
while (reader.HasMoreLines()) {
|
|
|
|
wxString curLine = reader.ReadLineFromFile();
|
2008-01-14 03:01:50 +01:00
|
|
|
if (curLine.IsEmpty()) continue;
|
2007-01-02 01:47:47 +01:00
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
if (curLine.IsNumber()) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if word to be added goes here
|
|
|
|
if (!added && curLine.Lower() > word.Lower()) {
|
|
|
|
dic.Add(word);
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to memory dictionary
|
|
|
|
dic.Add(curLine);
|
|
|
|
}
|
|
|
|
}
|
2008-01-14 03:01:50 +01:00
|
|
|
|
|
|
|
// Not added yet
|
|
|
|
if (!added) dic.Add(word);
|
2009-08-01 06:37:29 +02:00
|
|
|
|
2007-01-02 01:47:47 +01:00
|
|
|
// Write back to disk
|
2010-06-03 22:32:25 +02:00
|
|
|
try {
|
|
|
|
TextFileWriter writer(usrdicpath, L"UTF-8");
|
|
|
|
writer.WriteLineToFile(wxString::Format(L"%i", dic.Count()));
|
|
|
|
for (unsigned int i=0;i<dic.Count();i++) writer.WriteLineToFile(dic[i]);
|
|
|
|
}
|
|
|
|
catch (const wchar_t*) {
|
|
|
|
// Failed to open file
|
|
|
|
}
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Check if the word is valid.
|
|
|
|
/// @param word Word to check
|
|
|
|
/// @return Whether word is valid or not.
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2006-12-24 22:52:54 +01:00
|
|
|
bool HunspellSpellChecker::CheckWord(wxString word) {
|
|
|
|
if (!hunspell) return true;
|
2010-06-03 22:32:25 +02:00
|
|
|
try {
|
2010-06-03 22:54:46 +02:00
|
|
|
return hunspell->spell(conv->Convert(STD_STR(word)).c_str()) == 1;
|
2010-06-03 22:32:25 +02:00
|
|
|
}
|
|
|
|
catch (agi::charset::ConvError const&) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Get suggestions for word.
|
|
|
|
/// @param word Word to get suggestions for
|
|
|
|
/// @return List of suggestions
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2006-12-24 22:52:54 +01:00
|
|
|
wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) {
|
|
|
|
wxArrayString suggestions;
|
2010-06-03 22:32:25 +02:00
|
|
|
if (!hunspell) return suggestions;
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2010-06-03 22:32:25 +02:00
|
|
|
try {
|
2006-12-25 06:43:00 +01:00
|
|
|
// Grab raw from Hunspell
|
|
|
|
char **results;
|
2010-06-03 22:54:46 +02:00
|
|
|
int n = hunspell->suggest(&results,conv->Convert(STD_STR(word)).c_str());
|
2006-12-25 06:43:00 +01:00
|
|
|
|
|
|
|
// Convert each
|
|
|
|
for (int i=0;i<n;i++) {
|
2010-06-03 22:32:25 +02:00
|
|
|
suggestions.Add(rconv->Convert(results[i]));
|
2006-12-25 06:43:00 +01:00
|
|
|
delete results[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
delete results;
|
|
|
|
}
|
2010-06-03 22:32:25 +02:00
|
|
|
catch (agi::charset::ConvError const&) {
|
|
|
|
return suggestions;
|
|
|
|
}
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2006-12-24 22:52:54 +01:00
|
|
|
return suggestions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Get list of available dictionaries.
|
|
|
|
/// @return List of available dictionaries
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2006-12-24 22:52:54 +01:00
|
|
|
wxArrayString HunspellSpellChecker::GetLanguageList() {
|
2007-01-01 05:15:54 +01:00
|
|
|
// Get dir name
|
2010-05-21 03:13:36 +02:00
|
|
|
wxString path = StandardPaths::DecodePathMaybeRelative(lagi_wxString(OPT_GET("Path/Dictionary")->GetString()), _T("?data")) + _T("/");
|
2006-12-24 22:52:54 +01:00
|
|
|
wxArrayString list;
|
2007-01-09 02:52:30 +01:00
|
|
|
wxFileName folder(path);
|
|
|
|
if (!folder.DirExists()) return list;
|
2007-01-01 05:15:54 +01:00
|
|
|
|
|
|
|
// Get file lists
|
|
|
|
wxArrayString dic;
|
|
|
|
wxDir::GetAllFiles(path,&dic,_T("*.dic"),wxDIR_FILES);
|
|
|
|
wxArrayString aff;
|
|
|
|
wxDir::GetAllFiles(path,&aff,_T("*.aff"),wxDIR_FILES);
|
|
|
|
|
|
|
|
// For each dictionary match, see if it can find the corresponding .aff
|
|
|
|
for (unsigned int i=0;i<dic.Count();i++) {
|
2007-04-04 22:42:44 +02:00
|
|
|
wxString curAff = dic[i].Left(dic[i].Length()-4) + _T(".aff");
|
2007-01-01 05:15:54 +01:00
|
|
|
for (unsigned int j=0;j<aff.Count();j++) {
|
|
|
|
// Found match
|
|
|
|
if (curAff == aff[j]) {
|
|
|
|
wxFileName fname(curAff);
|
|
|
|
list.Add(fname.GetName());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return list
|
2006-12-24 22:52:54 +01:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-08-01 06:37:29 +02:00
|
|
|
/// @brief Set language.
|
|
|
|
/// @param language Language to set
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2006-12-24 22:52:54 +01:00
|
|
|
void HunspellSpellChecker::SetLanguage(wxString language) {
|
2007-01-02 00:47:09 +01:00
|
|
|
// Unload
|
2007-01-02 01:47:47 +01:00
|
|
|
Reset();
|
2007-01-02 00:47:09 +01:00
|
|
|
if (language.IsEmpty()) return;
|
|
|
|
|
2007-01-01 05:15:54 +01:00
|
|
|
// Get dir name
|
2008-06-01 05:44:41 +02:00
|
|
|
//FIXME: this should use ?user instead of ?data; however, since it apparently works already on win32, I'm not gonna mess with it right now :p
|
2010-05-21 03:13:36 +02:00
|
|
|
wxString path = StandardPaths::DecodePathMaybeRelative(lagi_wxString(OPT_GET("Path/Dictionary")->GetString()), _T("?data")) + _T("/");
|
2008-01-14 03:01:50 +01:00
|
|
|
wxString userPath = StandardPaths::DecodePath(_T("?user/dictionaries/user_"));
|
2007-01-01 05:15:54 +01:00
|
|
|
|
|
|
|
// Get affix and dictionary paths
|
2009-07-23 19:02:19 +02:00
|
|
|
affpath = wxString::Format("%s%s.aff", path, language);
|
|
|
|
dicpath = wxString::Format("%s%s.dic", path, language);
|
|
|
|
usrdicpath = wxString::Format("%s%s.dic", userPath, language);
|
2007-01-01 05:15:54 +01:00
|
|
|
|
2010-06-01 10:21:30 +02:00
|
|
|
LOG_I("dictionary/file") << dicpath;
|
2008-06-01 05:44:41 +02:00
|
|
|
|
2007-01-01 05:15:54 +01:00
|
|
|
// Check if language is available
|
|
|
|
if (!wxFileExists(affpath) || !wxFileExists(dicpath)) return;
|
|
|
|
|
|
|
|
// Load
|
2009-07-14 23:28:49 +02:00
|
|
|
hunspell = new Hunspell(affpath.mb_str(csConvLocal),dicpath.mb_str(csConvLocal));
|
2007-01-01 05:15:54 +01:00
|
|
|
conv = NULL;
|
2008-01-14 03:01:50 +01:00
|
|
|
if (hunspell) {
|
2010-06-03 22:32:25 +02:00
|
|
|
conv = new agi::charset::IconvWrapper("wchar_t", hunspell->get_dic_encoding());
|
|
|
|
rconv = new agi::charset::IconvWrapper(hunspell->get_dic_encoding(), "wchar_t");
|
|
|
|
try {
|
|
|
|
TextFileReader reader(usrdicpath, L"UTF-8");
|
|
|
|
while (reader.HasMoreLines()) {
|
|
|
|
wxString curLine = reader.ReadLineFromFile();
|
2008-01-14 03:01:50 +01:00
|
|
|
if (curLine.IsEmpty() || curLine.IsNumber()) continue;
|
2008-01-15 18:24:49 +01:00
|
|
|
#ifdef WITH_OLD_HUNSPELL
|
2010-06-03 22:54:46 +02:00
|
|
|
hunspell->put_word(conv->Convert(STD_STR(curLine)).c_str());
|
2008-01-15 18:24:49 +01:00
|
|
|
#else
|
2010-06-03 22:54:46 +02:00
|
|
|
hunspell->add(conv->Convert(STD_STR(curLine)).c_str());
|
2008-01-15 18:24:49 +01:00
|
|
|
#endif
|
2008-01-14 03:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
2010-06-03 22:32:25 +02:00
|
|
|
catch (const wchar_t *) {
|
|
|
|
// file not found
|
|
|
|
}
|
2008-01-14 03:01:50 +01:00
|
|
|
}
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
2007-12-31 07:46:22 +01:00
|
|
|
|
|
|
|
#endif // WITH_HUNSPELL
|