diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-02 06:40:27 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-02 06:40:27 +0000 |
commit | 2595a15ebeb6fc46b7cb241d01ec0c2460ec2111 (patch) | |
tree | 18a8f0f4ac5a86dacfa74c3537551ec39bc85e75 /src/isbnvalidator.cpp | |
parent | 1d90725a4001fab9d3922b2cbcceeee5e2d1686f (diff) | |
download | tellico-2595a15ebeb6fc46b7cb241d01ec0c2460ec2111.tar.gz tellico-2595a15ebeb6fc46b7cb241d01ec0c2460ec2111.zip |
TQt4 port tellico
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1239054 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/isbnvalidator.cpp')
-rw-r--r-- | src/isbnvalidator.cpp | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/src/isbnvalidator.cpp b/src/isbnvalidator.cpp index 91ed099..6eb2636 100644 --- a/src/isbnvalidator.cpp +++ b/src/isbnvalidator.cpp @@ -17,8 +17,8 @@ using Tellico::ISBNValidator; //static -QString ISBNValidator::isbn10(QString isbn13) { - if(!isbn13.startsWith(QString::fromLatin1("978"))) { +TQString ISBNValidator::isbn10(TQString isbn13) { + if(!isbn13.startsWith(TQString::tqfromLatin1("978"))) { myDebug() << "ISBNValidator::isbn10() - can't convert, must start with 978: " << isbn13 << endl; return isbn13; } @@ -32,73 +32,73 @@ QString ISBNValidator::isbn10(QString isbn13) { return isbn13; } -QString ISBNValidator::isbn13(QString isbn10) { +TQString ISBNValidator::isbn13(TQString isbn10) { isbn10.remove('-'); - if(isbn10.startsWith(QString::fromLatin1("978")) || - isbn10.startsWith(QString::fromLatin1("979"))) { + if(isbn10.startsWith(TQString::tqfromLatin1("978")) || + isbn10.startsWith(TQString::tqfromLatin1("979"))) { return isbn10; } // remove checksum isbn10.truncate(isbn10.length()-1); // begins with 978 - isbn10.prepend(QString::fromLatin1("978")); + isbn10.prepend(TQString::tqfromLatin1("978")); // add new checksum isbn10 += checkSum13(isbn10); staticFixup(isbn10); return isbn10; } -QString ISBNValidator::cleanValue(QString isbn) { - isbn.remove(QRegExp(QString::fromLatin1("[^xX0123456789]"))); +TQString ISBNValidator::cleanValue(TQString isbn) { + isbn.remove(TQRegExp(TQString::tqfromLatin1("[^xX0123456789]"))); return isbn; } -ISBNValidator::ISBNValidator(QObject* parent_, const char* name_/*=0*/) - : QValidator(parent_, name_) { +ISBNValidator::ISBNValidator(TQObject* tqparent_, const char* name_/*=0*/) + : TQValidator(tqparent_, name_) { } -QValidator::State ISBNValidator::validate(QString& input_, int& pos_) const { - if(input_.startsWith(QString::fromLatin1("978")) || - input_.startsWith(QString::fromLatin1("979"))) { +TQValidator::State ISBNValidator::validate(TQString& input_, int& pos_) const { + if(input_.startsWith(TQString::tqfromLatin1("978")) || + input_.startsWith(TQString::tqfromLatin1("979"))) { return validate13(input_, pos_); } else { return validate10(input_, pos_); } } -void ISBNValidator::fixup(QString& input_) const { +void ISBNValidator::fixup(TQString& input_) const { return staticFixup(input_); } -void ISBNValidator::staticFixup(QString& input_) { - if((input_.startsWith(QString::fromLatin1("978")) - || input_.startsWith(QString::fromLatin1("979"))) - && input_.contains(QRegExp(QString::fromLatin1("\\d"))) > 10) { +void ISBNValidator::staticFixup(TQString& input_) { + if((input_.startsWith(TQString::tqfromLatin1("978")) + || input_.startsWith(TQString::tqfromLatin1("979"))) + && input_.tqcontains(TQRegExp(TQString::tqfromLatin1("\\d"))) > 10) { return fixup13(input_); } return fixup10(input_); } -QValidator::State ISBNValidator::validate10(QString& input_, int& pos_) const { +TQValidator::State ISBNValidator::validate10(TQString& input_, int& pos_) const { // first check to see if it's a "perfect" ISBN // A perfect ISBN has 9 digits plus either an 'X' or another digit // A perfect ISBN may have 2 or 3 hyphens // The final digit or 'X' is the correct check sum - static const QRegExp isbn(QString::fromLatin1("(\\d-?){9,11}-[\\dX]")); + static const TQRegExp isbn(TQString::tqfromLatin1("(\\d-?){9,11}-[\\dX]")); uint len = input_.length(); /* // Don't do this since the hyphens may be in the wrong place, can't put that in a regexp if(isbn.exactMatch(input_) // put the exactMatch() first since I use matchedLength() later && (len == 12 || len == 13) && input_[len-1] == checkSum(input_)) { - return QValidator::Acceptable; + return TQValidator::Acceptable; } */ // two easy invalid cases are too many hyphens and the 'X' not in the last position - if(input_.contains('-') > 3 - || input_.contains('X', false) > 1 - || (input_.find('X', 0, false) != -1 && input_[len-1].upper() != 'X')) { - return QValidator::Invalid; + if(input_.tqcontains('-') > 3 + || input_.tqcontains('X', false) > 1 + || (input_.tqfind('X', 0, false) != -1 && input_[len-1].upper() != 'X')) { + return TQValidator::Invalid; } // remember if the cursor is at the end @@ -113,8 +113,8 @@ QValidator::State ISBNValidator::validate10(QString& input_, int& pos_) const { // fix the case where the user attempts to delete the checksum; the // solution is to delete the last digit as well - static const QRegExp digit(QString::fromLatin1("\\d")); - if(atEnd && input_.contains(digit) == 9 && input_[len-1] == '-') { + static const TQRegExp digit(TQString::tqfromLatin1("\\d")); + if(atEnd && input_.tqcontains(digit) == 9 && input_[len-1] == '-') { input_.truncate(len-2); pos_ -= 2; len -= 2; @@ -128,30 +128,30 @@ QValidator::State ISBNValidator::validate10(QString& input_, int& pos_) const { } if(isbn.exactMatch(input_) && (len == 12 || len == 13)) { - return QValidator::Acceptable; + return TQValidator::Acceptable; } else { - return QValidator::Intermediate; + return TQValidator::Intermediate; } } -QValidator::State ISBNValidator::validate13(QString& input_, int& pos_) const { +TQValidator::State ISBNValidator::validate13(TQString& input_, int& pos_) const { // first check to see if it's a "perfect" ISBN13 // A perfect ISBN13 has 13 digits // A perfect ISBN13 may have 3 or 4 hyphens // The final digit is the correct check sum - static const QRegExp isbn(QString::fromLatin1("(\\d-?){13,17}")); + static const TQRegExp isbn(TQString::tqfromLatin1("(\\d-?){13,17}")); uint len = input_.length(); - const uint countX = input_.contains('X', false); + const uint countX = input_.tqcontains('X', false); // two easy invalid cases are too many hyphens or 'X' - if(input_.contains('-') > 4 || countX > 1) { - return QValidator::Invalid; + if(input_.tqcontains('-') > 4 || countX > 1) { + return TQValidator::Invalid; } // now, it's not certain that we're getting a EAN-13, // it could be a ISBN-10 from Nigeria or Indonesia if(countX > 0 && (input_[len-1].upper() != 'X' || len > 13)) { - return QValidator::Invalid; + return TQValidator::Invalid; } // remember if the cursor is at the end @@ -166,8 +166,8 @@ QValidator::State ISBNValidator::validate13(QString& input_, int& pos_) const { // fix the case where the user attempts to delete the checksum; the // solution is to delete the last digit as well - static const QRegExp digit(QString::fromLatin1("\\d")); - const uint countN = input_.contains(digit); + static const TQRegExp digit(TQString::tqfromLatin1("\\d")); + const uint countN = input_.tqcontains(digit); if(atEnd && (countN == 12 || countN == 9) && input_[len-1] == '-') { input_.truncate(len-2); pos_ -= 2; @@ -187,22 +187,22 @@ QValidator::State ISBNValidator::validate13(QString& input_, int& pos_) const { } if(isbn.exactMatch(input_)) { - return QValidator::Acceptable; + return TQValidator::Acceptable; } else { - return QValidator::Intermediate; + return TQValidator::Intermediate; } } -void ISBNValidator::fixup10(QString& input_) { +void ISBNValidator::fixup10(TQString& input_) { if(input_.isEmpty()) { return; } - //replace "x" with "X" - input_.replace('x', QString::fromLatin1("X")); + //tqreplace "x" with "X" + input_.tqreplace('x', TQString::tqfromLatin1("X")); // remove invalid chars - static const QRegExp badChars(QString::fromLatin1("[^\\d-X]")); + static const TQRegExp badChars(TQString::tqfromLatin1("[^\\d-X]")); input_.remove(badChars); // special case for EAN values that start with 978 or 979. That's the case @@ -214,8 +214,8 @@ void ISBNValidator::fixup10(QString& input_) { // I consider the likelihood that someone wants to input an EAN to be higher than someone // using a Nigerian ISBN and not noticing that the checksum gets added automatically. if(input_.length() > 12 - && (input_.startsWith(QString::fromLatin1("978")) - || input_.startsWith(QString::fromLatin1("979")))) { + && (input_.startsWith(TQString::tqfromLatin1("978")) + || input_.startsWith(TQString::tqfromLatin1("979")))) { // Strip the first 4 characters (the invalid publisher) input_ = input_.right(input_.length() - 3); } @@ -226,11 +226,11 @@ void ISBNValidator::fixup10(QString& input_) { // the user inserts one, then be sure to put it back // Find the first hyphen. If there is none, - // input_.find('-') returns -1 and hyphen2_position = 0 - int hyphen2_position = input_.find('-') + 1; + // input_.tqfind('-') returns -1 and hyphen2_position = 0 + int hyphen2_position = input_.tqfind('-') + 1; // Find the second one. If none, hyphen2_position = -2 - hyphen2_position = input_.find('-', hyphen2_position) - 1; + hyphen2_position = input_.tqfind('-', hyphen2_position) - 1; // The second hyphen can not be in the last characters if(hyphen2_position >= 9) { @@ -240,7 +240,7 @@ void ISBNValidator::fixup10(QString& input_) { // Remove all existing hyphens. We will insert ours. input_.remove('-'); // the only place that 'X' can be is last spot - for(int xpos = input_.find('X'); xpos > -1; xpos = input_.find('X', xpos+1)) { + for(int xpos = input_.tqfind('X'); xpos > -1; xpos = input_.tqfind('X', xpos+1)) { if(xpos < 9) { // remove if not 10th char input_.remove(xpos, 1); --xpos; @@ -251,8 +251,8 @@ void ISBNValidator::fixup10(QString& input_) { // If we can find it, add the checksum // but only if not started with 978 or 979 if(input_.length() > 8 - && !input_.startsWith(QString::fromLatin1("978")) - && !input_.startsWith(QString::fromLatin1("979"))) { + && !input_.startsWith(TQString::tqfromLatin1("978")) + && !input_.startsWith(TQString::tqfromLatin1("979"))) { input_[9] = checkSum10(input_); } @@ -287,13 +287,13 @@ void ISBNValidator::fixup10(QString& input_) { } } -void ISBNValidator::fixup13(QString& input_) { +void ISBNValidator::fixup13(TQString& input_) { if(input_.isEmpty()) { return; } // remove invalid chars - static const QRegExp badChars(QString::fromLatin1("[^\\d-]")); + static const TQRegExp badChars(TQString::tqfromLatin1("[^\\d-]")); input_.remove(badChars); // hyphen placement for some languages publishers is well-defined @@ -301,17 +301,17 @@ void ISBNValidator::fixup13(QString& input_) { // some countries have ill-defined second hyphen positions, and if // the user inserts one, then be sure to put it back - QString after = input_.mid(3); + TQString after = input_.mid(3); if(after[0] == '-') { after = after.mid(1); } // Find the first hyphen. If there is none, - // input_.find('-') returns -1 and hyphen2_position = 0 - int hyphen2_position = after.find('-') + 1; + // input_.tqfind('-') returns -1 and hyphen2_position = 0 + int hyphen2_position = after.tqfind('-') + 1; // Find the second one. If none, hyphen2_position = -2 - hyphen2_position = after.find('-', hyphen2_position) - 1; + hyphen2_position = after.tqfind('-', hyphen2_position) - 1; // The second hyphen can not be in the last characters if(hyphen2_position >= 9) { @@ -359,7 +359,7 @@ void ISBNValidator::fixup13(QString& input_) { input_ = input_.left(3) + '-' + after; } -QChar ISBNValidator::checkSum10(const QString& input_) { +TQChar ISBNValidator::checkSum10(const TQString& input_) { uint sum = 0; uint multiplier = 10; @@ -370,21 +370,21 @@ QChar ISBNValidator::checkSum10(const QString& input_) { sum %= 11; sum = 11-sum; - QChar c; + TQChar c; if(sum == 10) { c = 'X'; } else if(sum == 11) { c = '0'; } else { - c = QString::number(sum)[0]; + c = TQString::number(sum)[0]; } return c; } -QChar ISBNValidator::checkSum13(const QString& input_) { +TQChar ISBNValidator::checkSum13(const TQString& input_) { uint sum = 0; - const uint len = QMIN(12, input_.length()); + const uint len = TQMIN(12, input_.length()); // hyphens are already gone, only use first twelve digits for(uint i = 0; i < len; ++i) { sum += input_[i].digitValue() * (1 + 2*(i%2)); @@ -393,11 +393,11 @@ QChar ISBNValidator::checkSum13(const QString& input_) { sum %= 10; sum = 10-sum; - QChar c; + TQChar c; if(sum == 10) { c = '0'; } else { - c = QString::number(sum)[0]; + c = TQString::number(sum)[0]; } return c; } |