Modules
ADT Database GTK2 GUI IP PiJAX Public Sql Stdio Subversion System Tools Xosd lua v4l2 wx
Recent Changes
Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0
Popular Downloads
Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48
|
Module Information
Public.Tools.Language.Hyphenate
Viewing contents of Public_Tools_Language_Hyphenate-1.2/hyphenate.cmod
/*! @module Public
*/
/*! @module Tools
*/
/*! @module Language
*/
#define _GNU_SOURCE
#define DEFAULT_CMOD_STORAGE
#include "hyphenate_config.h"
#include "util.h"
#include "hyphen-2.8.6/hyphen.h"
/*! @class Hyphenate
*/
PIKECLASS Hyphenate
{
CVAR HyphenDict * dict;
/*! @decl void create(string appname)
*! Creates a new Hyphenate object
*!
*/
PIKEFUN void create(string dictionary)
{
HyphenDict * hd;
char * dn;
printf("create()\n");
dn = strdup(dictionary->str);
hd = hnj_hyphen_load(dn);
if(!hd)
{
Pike_error("unable to load hyphenation dictionary.\n");
}
THIS->dict = hd;
pop_n_elems(args);
}
PIKEFUN string low_hyphenate(string word)
{
int k, n, i, j, c;
char** rep;
int* pos;
int* cut;
int nHyphCount;
char *hyphens;
char *hyphword;
rep = NULL; // Will be allocated by the algorithm
pos = NULL; // Idem
cut = NULL; // Idem
k = word->len * (1 << word->size_shift);
/* set aside some buffers to hold lower cased */
/* and hyphen information */
hyphens = (char *)malloc(k+5);
if (k > 0) {
if(hnj_hyphen_hyphenate2(THIS->dict, word->str, word->len, hyphens,
NULL, &rep, &pos, &cut))
{
free(hyphens);
pop_n_elems(args);
Pike_error("hyphenation error\n");
}
/* now backfill hyphens[] for any removed periods */
for (c = word->len; c < k; c++) hyphens[c] = '0';
hyphens[k] = '\0';
/* now create a new char string showing hyphenation positions */
/* count the hyphens and allocate space for the new hypehanted string */
nHyphCount = 0;
for(i = 0; i < word->len; i++)
{
if(hyphens[i]&1)
nHyphCount++;
}
hyphword = (char *) malloc(k+1+nHyphCount);
j = 0;
for (i = 0; i < word->len; i++)
{
hyphword[j++] = word->str[i];
if (hyphens[i]&1)
{
hyphword[j++] = '-';
}
}
hyphword[j] = '\0';
pop_n_elems(args);
push_text(hyphword);
free(hyphens);
free(hyphword);
// }
}
}
/*! @decl string hyphenate(string word)
*!
*! Break a word into its possible hyphenations.
*/
PIKEFUN string hyphenate(string word)
{
f_lower_case(1);
f_string_to_utf8(1);
f_Hyphenate_low_hyphenate(1);
if(Pike_sp[-1].type == T_STRING)
f_utf8_to_string(1);
}
INIT
{
THIS->dict = NULL;
}
EXIT
{
HyphenDict * hd;
printf("end\n");
if(THIS && THIS->dict != NULL)
{
printf("freeing\n");
hd = THIS->dict;
printf("dict: %p\n", hd);
hnj_hyphen_free(hd);
}
}
}
/*! @endclass
*/
/*! @endmodule
*/
/*! @endmodule
*/
/*! @endmodule
*/
|
|
|