From 4716b633e2b55aa8a2a145d0057a450eb525a36f Mon Sep 17 00:00:00 2001 From: Flexus <37239071+EnergyFlexus@users.noreply.github.com> Date: Wed, 14 Sep 2022 18:01:46 +0300 Subject: [PATCH] Hyphen test add --- .gitignore | 1 + Common/3dParty/hyphen/.gitignore | 5 ++ Common/3dParty/hyphen/test/main.cpp | 91 +++++++++++++++++++++++++++++ Common/3dParty/hyphen/test/test.pro | 25 ++++++++ 4 files changed, 122 insertions(+) create mode 100644 Common/3dParty/hyphen/.gitignore create mode 100644 Common/3dParty/hyphen/test/main.cpp create mode 100644 Common/3dParty/hyphen/test/test.pro diff --git a/.gitignore b/.gitignore index 8cb8cb83c4..edd2496b41 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ Thumbs.db *.opendb DesktopEditor/fontengine/js/common/freetype-2.10.4 +*_resource.rc diff --git a/Common/3dParty/hyphen/.gitignore b/Common/3dParty/hyphen/.gitignore new file mode 100644 index 0000000000..476026af48 --- /dev/null +++ b/Common/3dParty/hyphen/.gitignore @@ -0,0 +1,5 @@ +hyphen +test.pro.user +*.dic +msvc_make.bat +build-test-* \ No newline at end of file diff --git a/Common/3dParty/hyphen/test/main.cpp b/Common/3dParty/hyphen/test/main.cpp new file mode 100644 index 0000000000..2819ac9c50 --- /dev/null +++ b/Common/3dParty/hyphen/test/main.cpp @@ -0,0 +1,91 @@ +#include +#include + +#include "./../hyphen/hyphen.h" + +int main(int argc, char *argv[]) +{ + HyphenDict *dict; + + std::string dict_filename = PRO_DIR; + std::string words_filename = PRO_DIR; + std::string result_filename = PRO_DIR; + + // set your filenames here + dict_filename += "hyph_ru_RU.dic"; + words_filename += "words.txt"; + result_filename += "result.txt"; + + // load the hyphenation dictionary + dict = hnj_hyphen_load(dict_filename.c_str()); + + std::ifstream fin(words_filename); + if(!fin.is_open()) + { + std::cerr << "could not open " << words_filename << "!" << std::endl; + return -1; + } + + std::ofstream fout(result_filename); + if(!fout.is_open()) + { + std::cerr << "could not open " << result_filename << "!" << std::endl; + return -1; + } + + while(!fin.eof()) + { + char **rep = NULL; + int *pos = NULL; + int *cut = NULL; + + std::string word; + + fin >> word; + int n = word.size(); + char *hword = new char[n * 2]; + char *hyphens = new char[n + 5]; + + /** + * @brief + * input data: + * + * word: input word + * word_size: byte length of the input word + * hyphens: allocated character buffer (size = word_size + 5) + * hyphenated_word: allocated character buffer (size ~ word_size * 2) or NULL + * rep, pos, cut: pointers (point to the allocated and _zeroed_ buffers + * (size=word_size) or with NULL value) or NULL + * + * output data: + * + * hyphens: hyphenation vector (hyphenation points signed with odd numbers). + * hyphenated_word: hyphenated input word (hyphens signed with `='). + * optional (NULL input). + * rep: NULL (only standard hyph.), or replacements (hyphenation points + * signed with `=' in replacements). + * pos: NULL, or difference of the actual position and the beginning + * positions of the change in input words. + * cut: NULL, or counts of the removed characters of the original words + * at hyphenation. + * + * Note: rep, pos, cut are complementary arrays to the hyphens, indexed with the + * character positions of the input word. + */ + hnj_hyphen_hyphenate2(dict, word.c_str(), n, hyphens, hword, &rep, &pos, &cut); + + fout << hword << ' '; + + delete[] hword; + delete[] hyphens; + } + fin.close(); + fout.close(); +} + + + + + + + diff --git a/Common/3dParty/hyphen/test/test.pro b/Common/3dParty/hyphen/test/test.pro new file mode 100644 index 0000000000..787a92ef45 --- /dev/null +++ b/Common/3dParty/hyphen/test/test.pro @@ -0,0 +1,25 @@ +QT -= core +QT -= gui + +TARGET = test +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +CORE_ROOT_DIR = $$PWD/../../../../../core +PWD_ROOT_DIR = $$PWD + +include($$CORE_ROOT_DIR/Common/base.pri) + +INCLUDEPATH += $$PWD_ROOT_DIR/../hyphen + +DEFINES += PRO_DIR=\\\"$$PWD/\\\" + +HEADERS += $$PWD_ROOT_DIR/../hyphen/hyphen.h +HEADERS += $$PWD_ROOT_DIR/../hyphen/hnjalloc.h + +SOURCES += $$PWD_ROOT_DIR/../hyphen/hyphen.c +SOURCES += $$PWD_ROOT_DIR/../hyphen/hnjalloc.c + +SOURCES += main.cpp