aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/hyphenator.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc
index 8b927c71..3402a88f 100644
--- a/dw/hyphenator.cc
+++ b/dw/hyphenator.cc
@@ -49,9 +49,10 @@ Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack)
{
trie = NULL; // As long we are not sure whether a pattern file can be read.
- char buf[strlen (patFile) + 5 + 1];
+ char *buf = new char[strlen (patFile) + 5 + 1];
snprintf(buf, sizeof (buf), "%s.trie", patFile);
FILE *trieF = fopen (buf, "r");
+ delete[] buf;
if (trieF) {
trie = new Trie ();
@@ -118,10 +119,12 @@ Hyphenator *Hyphenator::getHyphenator (const char *lang)
if (hyphenator)
delete langString;
else {
- char patFile [strlen (DILLO_LIBDIR) + 13 + strlen (lang) + 4 + 1];
+ char *patFile =
+ new char[strlen (DILLO_LIBDIR) + 13 + strlen (lang) + 4 + 1];
snprintf (patFile, sizeof (patFile), "%s/hyphenation/%s.pat",
DILLO_LIBDIR, lang);
- char excFile [strlen (DILLO_LIBDIR) + 13 + strlen (lang) + 4 + 1];
+ char *excFile =
+ new char[strlen (DILLO_LIBDIR) + 13 + strlen (lang) + 4 + 1];
snprintf (excFile, sizeof(excFile), "%s/hyphenation/%s.exc",
DILLO_LIBDIR, lang);
@@ -130,6 +133,8 @@ Hyphenator *Hyphenator::getHyphenator (const char *lang)
hyphenator = new Hyphenator (patFile, excFile);
hyphenators->put (langString, hyphenator);
+ delete[] patFile;
+ delete[] excFile;
}
//lout::misc::StringBuffer sb;
@@ -144,7 +149,7 @@ void Hyphenator::insertPattern (TrieBuilder *trieBuilder, char *s)
// Convert the a pattern like 'a1bc3d4' into a string of chars 'abcd'
// and a list of points [ 0, 1, 0, 3, 4 ].
int l = strlen (s);
- char chars [l + 1];
+ char *chars = new char[l + 1];
SimpleVector<char> points (1);
// TODO numbers consisting of multiple digits?
@@ -171,6 +176,7 @@ void Hyphenator::insertPattern (TrieBuilder *trieBuilder, char *s)
//printf("insertPattern %s\n", chars);
trieBuilder->insert (chars, points.getArray ());
+ delete[] chars;
}
void Hyphenator::insertException (char *s)
@@ -182,7 +188,7 @@ void Hyphenator::insertException (char *s)
if((unsigned char)s[i] == 0xc2 && (unsigned char)s[i + 1] == 0xad)
breaks->put (new Integer (i - 2 * breaks->size()));
- char noHyphens[len - 2 * breaks->size() + 1];
+ char *noHyphens = new char[len - 2 * breaks->size() + 1];
int j = 0;
for (int i = 0; i < len; ) {
if(i < len - 1 &&
@@ -194,6 +200,7 @@ void Hyphenator::insertException (char *s)
noHyphens[j] = 0;
exceptions->put (new String (noHyphens), breaks);
+ delete noHyphens;
}
/**
@@ -313,7 +320,7 @@ void Hyphenator::hyphenateSingleWord(core::Platform *platform,
if (trie == NULL)
return;
- char work[strlen (wordLc) + 3];
+ char *work = new char[strlen (wordLc) + 3];
strcpy (work, ".");
strcat (work, wordLc);
strcat (work, ".");
@@ -336,6 +343,8 @@ void Hyphenator::hyphenateSingleWord(core::Platform *platform,
}
}
+ delete[] work;
+
// No hyphens in the first two chars or the last two.
// Characters are not bytes, so UTF-8 characters must be counted.
const char *s = nextUtf8Char (wordLc);