Hyphen test add

This commit is contained in:
Flexus
2022-09-14 18:01:46 +03:00
parent 0949f112d0
commit 4716b633e2
4 changed files with 122 additions and 0 deletions

1
.gitignore vendored
View File

@ -40,3 +40,4 @@ Thumbs.db
*.opendb *.opendb
DesktopEditor/fontengine/js/common/freetype-2.10.4 DesktopEditor/fontengine/js/common/freetype-2.10.4
*_resource.rc

5
Common/3dParty/hyphen/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
hyphen
test.pro.user
*.dic
msvc_make.bat
build-test-*

View File

@ -0,0 +1,91 @@
#include <fstream>
#include <iostream>
#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();
}

View File

@ -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