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 "options.h"
|
|
|
|
#include "spellchecker_hunspell.h"
|
|
|
|
#include "standard_paths.h"
|
|
|
|
#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-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;
|
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;
|
2007-08-07 22:45:41 +02:00
|
|
|
wxCharBuffer buffer = word.mb_str(*conv);
|
|
|
|
return (buffer.data() != NULL);
|
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
|
|
|
|
hunspell->put_word(word.mb_str(*conv));
|
|
|
|
#else
|
2008-01-11 01:38:47 +01:00
|
|
|
hunspell->add(word.mb_str(*conv));
|
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;
|
|
|
|
wxString curLine;
|
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;
|
2008-01-14 03:01:50 +01:00
|
|
|
wxFileInputStream in(usrdicpath);
|
2007-01-02 01:47:47 +01:00
|
|
|
if (!in.IsOk()) return;
|
|
|
|
wxTextInputStream textIn(in,_T(" \t"),*conv);
|
|
|
|
|
|
|
|
// Read it
|
|
|
|
while (in.CanRead() && !in.Eof()) {
|
|
|
|
// Read line
|
|
|
|
curLine = textIn.ReadLine();
|
|
|
|
curLine.Trim();
|
2008-01-14 03:01:50 +01:00
|
|
|
if (curLine.IsEmpty()) continue;
|
2007-01-02 01:47:47 +01:00
|
|
|
|
|
|
|
// First
|
|
|
|
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
|
2008-01-14 03:01:50 +01:00
|
|
|
wxFileOutputStream out(usrdicpath);
|
2007-01-02 01:47:47 +01:00
|
|
|
if (!out.IsOk()) return;
|
|
|
|
wxTextOutputStream textOut(out,wxEOL_UNIX,*conv);
|
|
|
|
textOut.WriteString(wxString::Format(_T("%i"),dic.Count())+_T("\n"));
|
|
|
|
for (unsigned int i=0;i<dic.Count();i++) textOut.WriteString(dic[i]+_T("\n"));
|
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;
|
2006-12-26 02:08:46 +01:00
|
|
|
wxCharBuffer buf = word.mb_str(*conv);
|
|
|
|
if (buf) return (hunspell->spell(buf) == 1);
|
|
|
|
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) {
|
2006-12-25 06:43:00 +01:00
|
|
|
// Array
|
2006-12-24 22:52:54 +01:00
|
|
|
wxArrayString suggestions;
|
2006-12-25 06:43:00 +01:00
|
|
|
|
|
|
|
// Get suggestions
|
|
|
|
if (hunspell) {
|
2007-01-01 05:15:54 +01:00
|
|
|
// Word
|
|
|
|
wxCharBuffer buf = word.mb_str(*conv);
|
|
|
|
if (!buf) return suggestions;
|
|
|
|
|
2006-12-25 06:43:00 +01:00
|
|
|
// Grab raw from Hunspell
|
|
|
|
char **results;
|
2006-12-26 02:08:46 +01:00
|
|
|
int n = hunspell->suggest(&results,buf);
|
2006-12-25 06:43:00 +01:00
|
|
|
|
|
|
|
// Convert each
|
|
|
|
for (int i=0;i<n;i++) {
|
2006-12-26 01:12:18 +01:00
|
|
|
wxString current(results[i],*conv);
|
2006-12-25 06:43:00 +01:00
|
|
|
suggestions.Add(current);
|
|
|
|
delete results[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete
|
|
|
|
delete results;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return them
|
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) {
|
2009-07-14 23:28:49 +02:00
|
|
|
conv = new AegisubCSConv(wxString(hunspell->get_dic_encoding(),wxConvUTF8));
|
2008-01-14 03:01:50 +01:00
|
|
|
|
|
|
|
// Load user dictionary
|
|
|
|
if (wxFileExists(usrdicpath)) {
|
|
|
|
wxFileInputStream in(usrdicpath);
|
|
|
|
if (!in.IsOk()) return;
|
|
|
|
wxTextInputStream textIn(in,_T(" \t"),*conv);
|
|
|
|
while (in.CanRead() && !in.Eof()) {
|
|
|
|
// Read line
|
|
|
|
wxString curLine = textIn.ReadLine();
|
|
|
|
curLine.Trim();
|
|
|
|
if (curLine.IsEmpty() || curLine.IsNumber()) continue;
|
2008-01-15 18:24:49 +01:00
|
|
|
#ifdef WITH_OLD_HUNSPELL
|
|
|
|
hunspell->put_word(curLine.mb_str(*conv));
|
|
|
|
#else
|
2008-01-14 03:01:50 +01:00
|
|
|
hunspell->add(curLine.mb_str(*conv));
|
2008-01-15 18:24:49 +01:00
|
|
|
#endif
|
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
|