00001
00002
00003
00004
00005
00006
00007
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <thmlmorph.h>
00011 #ifndef __GNUC__
00012 #else
00013 #include <unixstr.h>
00014 #endif
00015
00016
00017 const char ThMLMorph::on[] = "On";
00018 const char ThMLMorph::off[] = "Off";
00019 const char ThMLMorph::optName[] = "Morphological Tags";
00020 const char ThMLMorph::optTip[] = "Toggles Morphological Tags On and Off if they exist";
00021
00022
00023 ThMLMorph::ThMLMorph() {
00024 option = false;
00025 options.push_back(on);
00026 options.push_back(off);
00027 }
00028
00029
00030 ThMLMorph::~ThMLMorph() {
00031 }
00032
00033 void ThMLMorph::setOptionValue(const char *ival)
00034 {
00035 option = (!stricmp(ival, on));
00036 }
00037
00038 const char *ThMLMorph::getOptionValue()
00039 {
00040 return (option) ? on:off;
00041 }
00042
00043 char ThMLMorph::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
00044 {
00045 if (!option) {
00046 char *to, *from, token[2048];
00047 int tokpos = 0;
00048 bool intoken = false;
00049 int len;
00050 bool lastspace = false;
00051
00052 len = strlen(text) + 1;
00053 if (len < maxlen) {
00054 memmove(&text[maxlen - len], text, len);
00055 from = &text[maxlen - len];
00056 }
00057 else from = text;
00058
00059 for (to = text; *from; from++) {
00060 if (*from == '<') {
00061 intoken = true;
00062 tokpos = 0;
00063 token[0] = 0;
00064 token[1] = 0;
00065 token[2] = 0;
00066 continue;
00067 }
00068 if (*from == '>') {
00069 intoken = false;
00070 if (!strnicmp(token, "sync type=\"morph\" ", 18)) {
00071 if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
00072 if (lastspace)
00073 to--;
00074 }
00075 continue;
00076 }
00077
00078 *to++ = '<';
00079 for (char *tok = token; *tok; tok++)
00080 *to++ = *tok;
00081 *to++ = '>';
00082 continue;
00083 }
00084 if (intoken) {
00085 if (tokpos < 2045)
00086 token[tokpos++] = *from;
00087 token[tokpos+2] = 0;
00088 }
00089 else {
00090 *to++ = *from;
00091 lastspace = (*from == ' ');
00092 }
00093 }
00094 *to++ = 0;
00095 *to = 0;
00096 }
00097 return 0;
00098 }