123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- // RAN - 2015-06-26 - Fixed the issue with the leading zeros in Zulu
-
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
-
- #include <QDebug>
- #include <QString>
- #include <cstdlib>
-
- #include <QMessageBox>
- #include <QMap>
- #include "functions.h"
- #ifdef _WIN32
- #include <windows.h>
- #else
- #include <unistd.h>
- #endif
-
-
- // =========================================================
- // Sort Functions
- // =========================================================
-
- bool validateSorts(const QString &a, const QString &b, const QString &c) {
- return (a.length() * b.length() * c.length() > 0);
- }
-
-
- void mySortAlpha(QString &a, QString &b, QString &c) {
- if (a > b ) {
- if (c > a) swap(b,c);
- else if (b > c) swap(a,b);
- else {
- QString tmp = a;
- a = b; b = c; c = tmp;
- }
- }
- else {
- if (a > c) {
- QString tmp = c;
- c = b; b = a; a = tmp;
- }
- else if (b > c) swap(b,c);
- else {
- // they are already in order :-)
- }
- }
- }
-
- void mySortBeta(QString &a, QString &b, QString &c) {
- if (a > b ) {
- if (c > a) swap(a,b);
- else if (b > c) swap(a,c);
- else {
- QString tmp = a;
- a = b; b = c; c = tmp;
- }
- }
- else {
- if (a > c) {
- QString tmp = c;
- c = b; b = a; a = tmp;
- }
- else if (b > c) swap(b,c);
- else {
- // they are already in order :-)
- }
- }
- }
-
- void mySortGamma(QString &a, QString &b, QString &c) {
- if (a > b ) {
- if (c > a) swap(a,b);
- else if (b > c) swap(a,c);
- else {
- QString tmp = a;
- a = c; c = b; b = tmp;
- }
- }
- else {
- if (a > c) {
- QString tmp = c;
- c = b; b = a; a = tmp;
- }
- else if (b > c) swap(b,c);
- else {
- // they are already in order :-)
- }
- }
- }
-
- void mySortDelta(QString &a, QString &b, QString &c) {
- if (a < b ) {
- if (c < a) swap(a,b);
- else if (b < c) swap(a,c);
- else {
- QString tmp = a;
- a = b; b = c; c = tmp;
- }
- }
- else {
- if (a > c) {
- QString tmp = c;
- c = b; b = a; a = tmp;
- }
- else if (b > c) swap(b,c);
- else {
- // they are already in order :-)
- }
- }
- }
-
-
-
-
- // =========================================================
- // Rock Paper Scissor Functions
- // =========================================================
-
-
- int RPSAlpha(char p1, char p2) {
- p1 = toupper(p1);
- p2 = toupper(p2);
- if ( p1 == 'P' ) {
- if ( p2 == 'P' ) return TIE;
- else if (p2 == 'R') return P1_WON;
- else return P2_WON;
- }
-
- else if (p1 == 'R') {
- if ( p2 == 'R' ) return TIE;
- else if (p2 == 'S') return P1_WON;
- else return P2_WON;
- }
-
- else {
- if ( p2 == 'S' ) return TIE;
- else if (p2 == 'P') return P1_WON;
- else return P2_WON;
- }
- }
-
-
- int RPSBeta(char p1, char p2) {
- p1 = toupper(p1);
- p2 = toupper(p2);
- if ( p1 == 'P' ) {
- if ( p2 == 'S' ) return TIE;
- else if (p2 == 'R') return P1_WON;
- else return P2_WON;
- }
- else if (p1 == 'R') {
- if ( p2 == 'S' ) return TIE;
- else if (p2 == 'P') return P1_WON;
- else return P2_WON;
- }
-
- else {
- if ( p2 == 'S' ) return TIE;
- else if (p2 == 'R') return P1_WON;
- else return P2_WON;
- }
- }
-
-
-
- int RPSGamma(char p1, char p2) {
- p1 = toupper(p1);
- p2 = toupper(p2);
- if ( p1 == 'P' ) {
- if ( p2 == 'P' ) return TIE;
- else if (p2 == 'S') return P1_WON;
- else return P2_WON;
- }
- else if (p1 == 'R') {
- if ( p2 == 'R' ) return TIE;
- else if (p2 == 'P') return P1_WON;
- else return P2_WON;
- }
- else {
- if ( p2 == 'P' ) return TIE;
- else if (p2 == 'S') return P1_WON;
- else return P2_WON;
- }
- }
-
-
- int RPSDelta(char p1, char p2) {
- p1 = toupper(p1);
- p2 = toupper(p2);
- if ( p1 == 'P' ) {
- if ( p2 == 'P' ) return TIE;
- else if (p2 == 'S') return P1_WON;
- else return P2_WON;
- }
- else if (p1 == 'R') {
- if ( p2 == 'R' ) return TIE;
- else if (p2 == 'P') return P1_WON;
- else return P2_WON;
- }
- else {
- if ( p2 == 'P' ) return TIE;
- else if (p2 == 'S') return P1_WON;
- else return P2_WON;
- }
- }
-
- // =========================================================
- // Check Words Functions
- // =========================================================
-
-
-
- QMap<int,QString> M;
-
- void initCheckWMaps() {
-
- M[1] = "one"; M[2] = "two"; M[3] = "three"; M[4] = "four";
- M[5] = "five"; M[6] = "six";
- M[7] = "seven"; M[8] = "eight"; M[9] = "nine"; M[10] = "ten";
- M[11] = "eleven"; M[12] = "twelve"; M[13] = "thirteen"; M[14] = "fourteen";
- M[15] = "fifteen"; M[16] = "sixteen"; M[17] = "seventeen"; M[18] = "eighteen";
- M[19] = "nineteen";
- M[20] = "twenty"; M[30] = "thirty"; M[40] = "fourty"; M[50] = "fifty";
- M[60] = "sixty"; M[70] = "seventy"; M[80] = "eighty"; M[90] = "ninety";
- }
-
-
- bool validateCheckQty(QString st, unsigned int &qty) {
- int i = 0;
- for (i = 0; i < st.length() ; i++) {
- if (!st[i].isDigit()) return false;
- }
-
- if (i > 9) return false;
-
- qty = st.toInt();
- return true;
- }
-
-
-
- QString wordForNumber(unsigned int n) {
- QString st;
-
- int tens = n % 100;
- if (tens == 0)
- st = "";
- else if (tens <= 20)
- st = M[n];
- else {
- st = M[10 * (tens/10)];
- if (tens % 10)
- st.append(" " + M[tens % 10]);
- }
-
- n = n / 100;
- if (n) st.prepend(M[n % 10] + " hundred" + (st.length() > 0 ? " " : ""));
-
- return st;
- }
-
-
-
- QString checkWAlpha(unsigned int n) {
- QString st;
-
- // the cents
- st = wordForNumber(n % 1000);
-
- // the thousands
- n = n / 1000;
- if (n % 1000) st.prepend( wordForNumber(n % 1000) + " thousand" + (st.length() > 0 ? " " : ""));
-
- // the millions
- n = n / 1000;
- if (n % 1000) st.prepend( wordForNumber(n % 1000) + " million" + (st.length() > 0 ? " " : ""));
-
- return st;
- }
-
-
- QString checkWBeta(unsigned int n) {
- QString st;
-
- st = wordForNumber(n % 1000);
- n = n / 1000;
- if (n % 1000) st.append( wordForNumber(n % 1000) + " thousand" + (st.length() > 0 ? " " : ""));
- n = n / 1000;
- if (n % 1000) st.append( wordForNumber(n % 1000) + " million" + (st.length() > 0 ? " " : ""));
-
- return st;
- }
-
-
- QString checkWGamma(unsigned int n) {
- QString st;
-
- st = wordForNumber(n % 10);
- n = n / 1000;
- if (n % 1000) st.append( wordForNumber(n % 10) + " thousand" + (st.length() > 0 ? " " : ""));
- n = n / 1000;
- if (n % 1000) st.append( wordForNumber(n % 10) + " million" + (st.length() > 0 ? " " : ""));
-
- return st;
- }
-
-
-
- QString checkWDelta(unsigned int n) {
- QString st;
-
- n /= 10;
- st = wordForNumber(n % 1000);
- n = n / 1000;
- if (n % 1000) st.prepend( wordForNumber(n % 1000) + " thousand" + (st.length() > 0 ? " " : ""));
- n = n / 1000;
- if (n % 1000) st.prepend( wordForNumber(n % 1000) + " million" + (st.length() > 0 ? " " : ""));
-
- return st;
- }
-
-
- // =========================================================
- // Zulu Functions
- // =========================================================
-
-
- bool validZuluTime(const QString &time, const QString &zone, int &hours, int &minutes) {
- int i = 0;
- for (i = 0; i< time.size(); i++)
- if (!time[i].isDigit()) return false;
-
- if (i != 4) return false;
- hours = time.mid(0,2).toInt();
- minutes = time.mid(2,2).toInt();
-
- if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)
- return false;
-
- if (zone.length() < 1 || !zone[0].isLetter() || toupper(zone.toStdString()[0]) == 'J') return false;
- return true;
- }
-
-
- QString zuluAlpha(int hours, int minutes, char zone) {
- int diff = 0;
- zone = toupper(zone);
- if (zone <= 'I') diff = zone - 'A' + 1;
- else if (zone <= 'M') diff = 10 + (zone - 'K');
- else if (zone <= 'Y') diff = -(zone - 'N' + 1);
- else diff = 0;
-
- hours = (hours + (24 + diff) ) % 24;
-
- QString qstHours = QString::number(hours);
- if (qstHours.length() == 1) qstHours.prepend("0");
-
- QString qstMin = QString::number(minutes);
- if (qstMin.length() == 1) qstMin.prepend("0");
-
- return qstHours + qstMin;
- }
-
- QString zuluBeta(int hours, int minutes, char zone) {
- int diff = 0;
-
- if (zone <= 'I') diff = zone - 'B' + 1;
- else if (zone <= 'M') diff = 10 + (zone - 'M');
- else if (zone <= 'Y') diff = -(zone - 'N');
- diff = 0;
-
- hours = (hours + (24 + diff) ) % 24;
-
- return QString::number(hours) + QString::number(minutes);
- }
-
- QString zuluGamma(int hours, int minutes, char zone) {
- int diff = 0;
-
- if (zone <= 'I') diff = zone - 'A' + 1;
- else if (zone <= 'M') diff = 10 + (zone - 'M');
- else if (zone <= 'Y') diff = -(zone - 'N');
- else diff = 0;
-
- hours = (hours + (24 - diff) ) % 24;
-
- return QString::number(hours) + QString::number(minutes);
- }
-
- QString zuluDelta(int hours, int minutes, char zone) {
- int diff = 0;
-
- if (zone <= 'M') diff = zone - 'B' + 1;
- else if (zone <= 'Y') diff = -(zone - 'N');
- else diff = 0;
-
- hours = (hours + (24 - diff) ) % 24;
-
- return QString::number(hours) + QString::number(minutes);
- }
|