summaryrefslogtreecommitdiffstats
path: root/src/field.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/field.cpp')
-rw-r--r--src/field.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/field.cpp b/src/field.cpp
index 4ad2fa7..793de90 100644
--- a/src/field.cpp
+++ b/src/field.cpp
@@ -32,6 +32,7 @@ namespace {
using Tellico::Data::Field;
//these get overwritten, but are here since they're static
+TQStringList Field::s_articles;
TQStringList Field::s_articlesApos;
TQRegExp Field::s_delimiter = TQRegExp(TQString::fromLatin1("\\s*;\\s*"));
@@ -171,7 +172,7 @@ const TQString& Field::defaultValue() const {
}
void Field::setDefaultValue(const TQString& value_) {
- if(m_type != Choice || m_allowed.findIndex(value_) > -1) {
+ if(value_.isEmpty() || m_type != Choice || m_allowed.findIndex(value_) > -1) {
setProperty(TQString::fromLatin1("default"), value_);
}
}
@@ -260,8 +261,7 @@ TQString Field::formatTitle(const TQString& title_) {
if(Config::autoFormat()) {
const TQString lower = newTitle.lower();
// TODO if the title has ",the" at the end, put it at the front
- const TQStringList& articles = Config::articleList();
- for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articles.constBegin(); it != s_articles.constEnd(); ++it) {
// assume white space is already stripped
// the articles are already in lower-case
if(lower.startsWith(*it + TQChar(' '))) {
@@ -415,7 +415,7 @@ TQString Field::capitalize(TQString str_) {
TQString word = str_.mid(0, pos);
// now check to see if words starts with apostrophe list
- for(TQStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articlesApos.constBegin(); it != s_articlesApos.constEnd(); ++it) {
if(word.lower().startsWith(*it)) {
uint l = (*it).length();
str_.replace(l, 1, str_.at(l).upper());
@@ -432,7 +432,7 @@ TQString Field::capitalize(TQString str_) {
word = str_.mid(pos+1, nextPos-pos-1);
bool aposMatch = false;
// now check to see if words starts with apostrophe list
- for(TQStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articlesApos.constBegin(); it != s_articlesApos.constEnd(); ++it) {
if(word.lower().startsWith(*it)) {
uint l = (*it).length();
str_.replace(pos+l+1, 1, str_.at(pos+l+1).upper());
@@ -455,8 +455,7 @@ TQString Field::capitalize(TQString str_) {
TQString Field::sortKeyTitle(const TQString& title_) {
const TQString lower = title_.lower();
- const TQStringList& articles = Config::articleList();
- for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articles.constBegin(); it != s_articles.constEnd(); ++it) {
// assume white space is already stripped
// the articles are already in lower-case
if(lower.startsWith(*it + TQChar(' '))) {
@@ -464,7 +463,7 @@ TQString Field::sortKeyTitle(const TQString& title_) {
}
}
// check apostrophes, too
- for(TQStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articlesApos.constBegin(); it != s_articlesApos.constEnd(); ++it) {
if(lower.startsWith(*it)) {
return title_.mid((*it).length());
}
@@ -474,9 +473,9 @@ TQString Field::sortKeyTitle(const TQString& title_) {
// articles should all be in lower-case
void Field::articlesUpdated() {
- const TQStringList articles = Config::articleList();
+ s_articles = Config::articleList();
s_articlesApos.clear();
- for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articles.constBegin(); it != s_articles.constEnd(); ++it) {
if((*it).endsWith(TQChar('\''))) {
s_articlesApos += (*it);
}
@@ -581,11 +580,10 @@ long Field::getID() {
}
void Field::stripArticles(TQString& value) {
- const TQStringList articles = Config::articleList();
- if(articles.isEmpty()) {
+ if(s_articles.isEmpty()) {
return;
}
- for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) {
+ for(TQStringList::ConstIterator it = s_articles.constBegin(); it != s_articles.constEnd(); ++it) {
TQRegExp rx(TQString::fromLatin1("\\b") + *it + TQString::fromLatin1("\\b"));
value.remove(rx);
}