diff --git a/plugins/channelrx/demodais/aisdemodgui.cpp b/plugins/channelrx/demodais/aisdemodgui.cpp index 2542ae7ca8..ad02fc9586 100644 --- a/plugins/channelrx/demodais/aisdemodgui.cpp +++ b/plugins/channelrx/demodais/aisdemodgui.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -636,9 +636,10 @@ void AISDemodGUI::filterRow(int row) bool hidden = false; if (m_settings.m_filterMMSI != "") { - QRegExp re(m_settings.m_filterMMSI); + QRegularExpression re(QRegularExpression::anchoredPattern(m_settings.m_filterMMSI)); QTableWidgetItem *fromItem = ui->messages->item(row, MESSAGE_COL_MMSI); - if (!re.exactMatch(fromItem->text())) + QRegularExpressionMatch match = re.match(fromItem->text()); + if (!match.hasMatch()) hidden = true; } ui->messages->setRowHidden(row, hidden); diff --git a/plugins/channelrx/demodapt/aptdemodgui.cpp b/plugins/channelrx/demodapt/aptdemodgui.cpp index 32408006be..2cf848bda9 100644 --- a/plugins/channelrx/demodapt/aptdemodgui.cpp +++ b/plugins/channelrx/demodapt/aptdemodgui.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/plugins/channelrx/demoddab/dabdemodgui.cpp b/plugins/channelrx/demoddab/dabdemodgui.cpp index aad6b22963..889a41334f 100644 --- a/plugins/channelrx/demoddab/dabdemodgui.cpp +++ b/plugins/channelrx/demoddab/dabdemodgui.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include "dabdemodgui.h" @@ -423,9 +423,10 @@ void DABDemodGUI::filterRow(int row) bool hidden = false; if (m_settings.m_filter != "") { - QRegExp re(m_settings.m_filter); + QRegularExpression re(m_settings.m_filter); QTableWidgetItem *fromItem = ui->programs->item(row, PROGRAMS_COL_NAME); - if (re.indexIn(fromItem->text()) == -1) + QRegularExpressionMatch match = re.match(fromItem->text()); + if (!match.hasMatch()) hidden = true; } ui->programs->setRowHidden(row, hidden); diff --git a/plugins/channelrx/demoddsc/dscdemodgui.cpp b/plugins/channelrx/demoddsc/dscdemodgui.cpp index 2fd2c25a5b..cbade9cbd7 100644 --- a/plugins/channelrx/demoddsc/dscdemodgui.cpp +++ b/plugins/channelrx/demoddsc/dscdemodgui.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -467,8 +466,9 @@ void DSCDemodGUI::filterRow(int row) if (m_settings.m_filter != "") { QTableWidgetItem *item = ui->messages->item(row, m_settings.m_filterColumn); - QRegExp re(m_settings.m_filter); - if (!re.exactMatch(item->text())) { + QRegularExpression re(m_settings.m_filter); + QRegularExpressionMatch match = re.match(item->text()); + if (!match.hasMatch()) { hidden = true; } } diff --git a/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp b/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp index e66af8551e..d94497b102 100644 --- a/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp +++ b/plugins/channelrx/demodendoftrain/endoftraindemodgui.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -345,9 +345,10 @@ void EndOfTrainDemodGUI::filterRow(int row) bool hidden = false; if (m_settings.m_filterFrom != "") { - QRegExp re(m_settings.m_filterFrom); + QRegularExpression re(QRegularExpression::anchoredPattern(m_settings.m_filterFrom)); QTableWidgetItem *fromItem = ui->packets->item(row, PACKETS_COL_ADDRESS); - if (!re.exactMatch(fromItem->text())) + QRegularExpressionMatch match = re.match(fromItem->text()); + if (!match.hasMatch()) hidden = true; } ui->packets->setRowHidden(row, hidden); diff --git a/plugins/channelrx/demodpacket/packetdemodgui.cpp b/plugins/channelrx/demodpacket/packetdemodgui.cpp index a53c99aad1..ce80591766 100644 --- a/plugins/channelrx/demodpacket/packetdemodgui.cpp +++ b/plugins/channelrx/demodpacket/packetdemodgui.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include @@ -330,16 +330,18 @@ void PacketDemodGUI::filterRow(int row) bool hidden = false; if (m_settings.m_filterFrom != "") { - QRegExp re(m_settings.m_filterFrom); + QRegularExpression re(QRegularExpression::anchoredPattern(m_settings.m_filterFrom)); QTableWidgetItem *fromItem = ui->packets->item(row, PACKET_COL_FROM); - if (!re.exactMatch(fromItem->text())) + QRegularExpressionMatch match = re.match(fromItem->text()); + if (!match.hasMatch()) hidden = true; } if (m_settings.m_filterTo != "") { - QRegExp re(m_settings.m_filterTo); + QRegularExpression re(QRegularExpression::anchoredPattern(m_settings.m_filterTo)); QTableWidgetItem *toItem = ui->packets->item(row, PACKET_COL_TO); - if (!re.exactMatch(toItem->text())) + QRegularExpressionMatch match = re.match(toItem->text()); + if (!match.hasMatch()) hidden = true; } if (m_settings.m_filterPID != "") diff --git a/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp b/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp index 178f50213c..4d88bb9c12 100644 --- a/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp +++ b/plugins/channelrx/demodradiosonde/radiosondedemodgui.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -473,9 +473,10 @@ void RadiosondeDemodGUI::filterRow(int row) bool hidden = false; if (m_settings.m_filterSerial != "") { - QRegExp re(m_settings.m_filterSerial); + QRegularExpression re(QRegularExpression::anchoredPattern(m_settings.m_filterSerial)); QTableWidgetItem *fromItem = ui->frames->item(row, FRAME_COL_SERIAL); - if (!re.exactMatch(fromItem->text())) + QRegularExpressionMatch match = re.match(fromItem->text()); + if (!match.hasMatch()) hidden = true; } ui->frames->setRowHidden(row, hidden); diff --git a/plugins/channelrx/radioastronomy/radioastronomygui.cpp b/plugins/channelrx/radioastronomy/radioastronomygui.cpp index d26eddbd46..e5c9f1f28a 100644 --- a/plugins/channelrx/radioastronomy/radioastronomygui.cpp +++ b/plugins/channelrx/radioastronomy/radioastronomygui.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -6054,10 +6054,11 @@ void RadioAstronomyGUI::networkManagerFinished(QNetworkReply *reply) else { QString answer = reply->readAll(); - QRegExp re("a href=\\\"download.php([^\"]*)\""); - if (re.indexIn(answer) != -1) + QRegularExpression re("a href=\\\"download.php([^\"]*)\""); + QRegularExpressionMatch match = re.match(answer); + if (match.hasMatch()) { - QString filename = re.capturedTexts()[1]; + QString filename = match.capturedTexts()[1]; qDebug() << "RadioAstronomyGUI: Downloading LAB reference data: " << filename; m_dlm.download(QUrl("https://www.astro.uni-bonn.de/hisurvey/euhou/LABprofile/download.php" + filename), m_filenameLAB); } diff --git a/plugins/feature/aprs/aprsgui.cpp b/plugins/feature/aprs/aprsgui.cpp index 8b111bfc8e..4265813736 100644 --- a/plugins/feature/aprs/aprsgui.cpp +++ b/plugins/feature/aprs/aprsgui.cpp @@ -1147,9 +1147,10 @@ void APRSGUI::filterMessageRow(int row) bool hidden = false; if (m_settings.m_filterAddressee != "") { - QRegExp re(m_settings.m_filterAddressee); + QRegularExpression re(m_settings.m_filterAddressee); QTableWidgetItem *addressee = ui->messagesTable->item(row, MESSAGE_COL_ADDRESSEE); - if (!re.exactMatch(addressee->text())) + QRegularExpressionMatch match = re.match(addressee->text()); + if (!match.hasMatch()) hidden = true; } ui->messagesTable->setRowHidden(row, hidden); diff --git a/plugins/feature/satellitetracker/satnogs.h b/plugins/feature/satellitetracker/satnogs.h index c9b3177cbe..83ec03a9fe 100644 --- a/plugins/feature/satellitetracker/satnogs.h +++ b/plugins/feature/satellitetracker/satnogs.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include struct SatNogsTransmitter { @@ -196,10 +196,11 @@ struct SatNogsSatellite { // tle0 is of the form: // MOZHAYETS 4 (RS-22) // GOES 9 [-] - QRegExp re("([A-Za-z0-9\\- ]+)([\\(]([A-Z0-9\\- ]+)[\\)])?"); - if (re.indexIn(tle->m_tle0) != -1) + QRegularExpression re("([A-Za-z0-9\\- ]+)([\\(]([A-Z0-9\\- ]+)[\\)])?"); + QRegularExpressionMatch match = re.match(tle->m_tle0); + if (match.hasMatch()) { - QStringList groups = re.capturedTexts(); + QStringList groups = match.capturedTexts(); m_name = groups[1].trimmed(); if ((groups.size() >= 4) && (groups[3] != "-") && !groups[3].isEmpty()) m_names = QStringList({groups[3].trimmed()}); diff --git a/plugins/feature/startracker/startrackergui.cpp b/plugins/feature/startracker/startrackergui.cpp index 852a71e343..cf3f5f7550 100644 --- a/plugins/feature/startracker/startrackergui.cpp +++ b/plugins/feature/startracker/startrackergui.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -1253,8 +1253,8 @@ void StarTrackerGUI::plotGalacticLineOfSight() } // Calculate Galactic longitude we're observing - float ra = Astronomy::raToDecimal(m_settings.m_ra); - float dec = Astronomy::decToDecimal(m_settings.m_dec); + float ra = Units::raToDecimal(m_settings.m_ra); + float dec = Units::decToDecimal(m_settings.m_dec); double l, b; Astronomy::equatorialToGalactic(ra, dec, l, b); @@ -1365,8 +1365,8 @@ void StarTrackerGUI::plotSkyTemperatureChart() } QScatterSeries *series = new QScatterSeries(); - float ra = Astronomy::raToDecimal(m_settings.m_ra); - float dec = Astronomy::decToDecimal(m_settings.m_dec); + float ra = Units::raToDecimal(m_settings.m_ra); + float dec = Units::decToDecimal(m_settings.m_dec); double beamWidth = m_settings.m_beamwidth; // Ellipse not supported, so draw circle on shorter axis @@ -1664,8 +1664,8 @@ void StarTrackerGUI::plotElevationLineChart() } else { - rd.ra = Astronomy::raToDecimal(m_settings.m_ra); - rd.dec = Astronomy::decToDecimal(m_settings.m_dec); + rd.ra = Units::raToDecimal(m_settings.m_ra); + rd.dec = Units::decToDecimal(m_settings.m_dec); aa = Astronomy::raDecToAzAlt(rd, m_settings.m_latitude, m_settings.m_longitude, dt, !m_settings.m_jnow); } @@ -1850,8 +1850,8 @@ void StarTrackerGUI::plotElevationPolarChart() } else { - rd.ra = Astronomy::raToDecimal(m_settings.m_ra); - rd.dec = Astronomy::decToDecimal(m_settings.m_dec); + rd.ra = Units::raToDecimal(m_settings.m_ra); + rd.dec = Units::decToDecimal(m_settings.m_dec); aa = Astronomy::raDecToAzAlt(rd, m_settings.m_latitude, m_settings.m_longitude, dt, !m_settings.m_jnow); } @@ -2282,12 +2282,13 @@ bool StarTrackerGUI::readSolarFlux() // 000000 000019 000027 000037 000056 000073 000116 000202 000514 sfu // Occasionally, file will contain ////// in a column, presumably to indicate no data // Values can be negative - QRegExp re("([0-9]{2})([0-9]{2})([0-9]{2}) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+)"); + QRegularExpression re("([0-9]{2})([0-9]{2})([0-9]{2}) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+) (-?[0-9\\/]+)"); + QRegularExpressionMatch match = re.match(string); - if (re.indexIn(string) != -1) + if (match.hasMatch()) { for (int i = 0; i < 8; i++) - m_solarFluxes[i] = re.capturedTexts()[i+4].toInt(); + m_solarFluxes[i] = match.capturedTexts()[i+4].toInt(); m_solarFluxesValid = true; displaySolarFlux(); plotChart(); @@ -2322,11 +2323,12 @@ void StarTrackerGUI::networkManagerFinished(QNetworkReply *reply) else { QString answer = reply->readAll(); - QRegExp re("\\Observed Flux Density\\<\\/th\\>\\([0-9]+(\\.[0-9]+)?)\\<\\/td\\>"); + QRegularExpression re("\\Observed Flux Density\\<\\/th\\>\\([0-9]+(\\.[0-9]+)?)\\<\\/td\\>"); + QRegularExpressionMatch match = re.match(answer); - if (re.indexIn(answer) != -1) + if (match.hasMatch()) { - m_solarFlux = re.capturedTexts()[1].toDouble(); + m_solarFlux = match.capturedTexts()[1].toDouble(); displaySolarFlux(); } else diff --git a/plugins/feature/startracker/startrackerworker.cpp b/plugins/feature/startracker/startrackerworker.cpp index 4f004625d4..b37bfdbed9 100644 --- a/plugins/feature/startracker/startrackerworker.cpp +++ b/plugins/feature/startracker/startrackerworker.cpp @@ -580,8 +580,8 @@ void StarTrackerWorker::update() else { // Convert RA/Dec to Alt/Az - rd.ra = Astronomy::raToDecimal(m_settings.m_ra); - rd.dec = Astronomy::decToDecimal(m_settings.m_dec); + rd.ra = Units::raToDecimal(m_settings.m_ra); + rd.dec = Units::decToDecimal(m_settings.m_dec); aa = Astronomy::raDecToAzAlt(rd, m_settings.m_latitude, m_settings.m_longitude, dt, !m_settings.m_jnow); Astronomy::equatorialToGalactic(rd.ra, rd.dec, l, b); } diff --git a/sdrbase/util/aprs.cpp b/sdrbase/util/aprs.cpp index 10fab703fc..36b954c40d 100644 --- a/sdrbase/util/aprs.cpp +++ b/sdrbase/util/aprs.cpp @@ -17,7 +17,6 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include #include #include #include @@ -407,34 +406,37 @@ bool APRSPacket::parseDataExension(QString& info, int& idx) QString s = info.right(remainingLength); // Course and speed - QRegExp courseSpeed("^([0-9]{3})\\/([0-9]{3})"); - if (courseSpeed.indexIn(s) >= 0) + QRegularExpression courseSpeed("^([0-9]{3})\\/([0-9]{3})"); + QRegularExpressionMatch match; + match = courseSpeed.match(s); + if (match.hasMatch()) { - m_course = courseSpeed.capturedTexts()[1].toInt(); - m_speed = courseSpeed.capturedTexts()[2].toInt(); + m_course = match.capturedTexts()[1].toInt(); + m_speed = match.capturedTexts()[2].toInt(); m_hasCourseAndSpeed = true; idx += 7; return true; } // Station radio details - QRegExp phg("^PHG([0-9])([0-9])([0-9])([0-9])"); - if (phg.indexIn(s) >= 0) + QRegularExpression phg("^PHG([0-9])([0-9])([0-9])([0-9])"); + match = phg.match(s); + if (match.hasMatch()) { // Transmitter power - int powerCode = phg.capturedTexts()[1].toInt(); + int powerCode = match.capturedTexts()[1].toInt(); int powerMap[] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}; m_powerWatts = powerMap[powerCode]; // Antenna height - int heightCode = phg.capturedTexts()[2].toInt(); + int heightCode = match.capturedTexts()[2].toInt(); m_antennaHeightFt = heightMap[heightCode]; // Antenna gain - m_antennaGainDB = phg.capturedTexts()[3].toInt(); + m_antennaGainDB = match.capturedTexts()[3].toInt(); // Antenna directivity - int directivityCode = phg.capturedTexts()[4].toInt(); + int directivityCode = match.capturedTexts()[4].toInt(); m_antennaDirectivity = directivityMap[directivityCode]; m_hasStationDetails = true; @@ -444,31 +446,33 @@ bool APRSPacket::parseDataExension(QString& info, int& idx) } // Radio range - QRegExp rng("^RNG([0-9]{4})"); - if (rng.indexIn(s) >= 0) + QRegularExpression rng("^RNG([0-9]{4})"); + match = rng.match(s); + if (match.hasMatch()) { - m_radioRangeMiles = rng.capturedTexts()[1].toInt(); + m_radioRangeMiles = match.capturedTexts()[1].toInt(); m_hasRadioRange = true; idx += 7; return true; } // Omni-DF strength - QRegExp dfs("^DFS([0-9])([0-9])([0-9])([0-9])"); - if (dfs.indexIn(s) >= 0) + QRegularExpression dfs("^DFS([0-9])([0-9])([0-9])([0-9])"); + match = dfs.match(s); + if (match.hasMatch()) { // Strength S-points - m_dfStrength = dfs.capturedTexts()[1].toInt(); + m_dfStrength = match.capturedTexts()[1].toInt(); // Antenna height - int heightCode = dfs.capturedTexts()[2].toInt(); + int heightCode = match.capturedTexts()[2].toInt(); m_dfHeightFt = heightMap[heightCode]; // Antenna gain - m_dfGainDB = dfs.capturedTexts()[3].toInt(); + m_dfGainDB = match.capturedTexts()[3].toInt(); // Antenna directivity - int directivityCode = dfs.capturedTexts()[4].toInt(); + int directivityCode = match.capturedTexts()[4].toInt(); m_dfAntennaDirectivity = directivityMap[directivityCode]; m_hasDf = true; @@ -487,14 +491,14 @@ bool APRSPacket::parseComment(QString& info, int& idx) m_comment = info.right(commentLength); // Comment can contain altitude anywhere in it. Of the form /A=001234 in feet - QRegExp re("\\/A=([0-9]{6})"); - int pos = re.indexIn(m_comment); - if (pos >= 0) + QRegularExpression re("\\/A=([0-9]{6})"); + QRegularExpressionMatch match = re.match(m_comment); + if (match.hasMatch()) { - m_altitudeFt = re.capturedTexts()[1].toInt(); + m_altitudeFt = match.capturedTexts()[1].toInt(); m_hasAltitude = true; // Strip it out of comment if at start of string - if (pos == 0) + if (match.capturedStart(0) == 0) m_comment = m_comment.mid(9); } } @@ -755,18 +759,20 @@ bool APRSPacket::parseStatus(QString& info, int& idx) { QString remaining = info.mid(idx); - QRegExp timestampRE("^([0-9]{6})z"); // DHM timestamp - QRegExp maidenheadRE("^([A-Z]{2}[0-9]{2}[A-Z]{0,2})[/\\\\]."); // Maidenhead grid locator and symbol + QRegularExpression timestampRE("^([0-9]{6})z"); // DHM timestamp + QRegularExpression maidenheadRE("^([A-Z]{2}[0-9]{2}[A-Z]{0,2})[/\\\\]."); // Maidenhead grid locator and symbol + QRegularExpressionMatch matchTimestamp = timestampRE.match(remaining); + QRegularExpressionMatch matchMaidenhead = maidenheadRE.match(remaining); - if (timestampRE.indexIn(remaining) >= 0) + if (matchTimestamp.hasMatch()) { parseTime(info, idx); m_status = info.mid(idx); idx += m_status.length(); } - else if (maidenheadRE.indexIn(remaining) >= 0) + else if (matchMaidenhead.hasMatch()) { - m_maidenhead = maidenheadRE.capturedTexts()[1]; + m_maidenhead = matchMaidenhead.capturedTexts()[1]; idx += m_maidenhead.length(); m_symbolTable = info[idx++].toLatin1(); m_symbolCode = info[idx++].toLatin1(); @@ -959,10 +965,11 @@ bool APRSPacket::parseMessage(QString& info, int& idx) else { // Check for message number - QRegExp noRE("\\{([0-9]{1,5})$"); - if (noRE.indexIn(m_message) >= 0) + QRegularExpression noRE("\\{([0-9]{1,5})$"); + QRegularExpressionMatch match = noRE.match(m_message); + if (match.hasMatch()) { - m_messageNo = noRE.capturedTexts()[1]; + m_messageNo = match.capturedTexts()[1]; m_message = m_message.left(m_message.length() - m_messageNo.length() - 1); } } diff --git a/sdrbase/util/astronomy.cpp b/sdrbase/util/astronomy.cpp index 9c86ab4cfa..927088b879 100644 --- a/sdrbase/util/astronomy.cpp +++ b/sdrbase/util/astronomy.cpp @@ -20,7 +20,6 @@ #include -#include #include #include @@ -701,40 +700,6 @@ double Astronomy::refractionPAL(double alt, double pressure, double temperature, return z-Units::radiansToDegrees(zr); } -double Astronomy::raToDecimal(const QString& value) -{ - QRegExp decimal("^([0-9]+(\\.[0-9]+)?)"); - QRegExp hms("^([0-9]+)[ h]([0-9]+)[ m]([0-9]+(\\.[0-9]+)?)s?"); - - if (decimal.exactMatch(value)) - return decimal.capturedTexts()[0].toDouble(); - else if (hms.exactMatch(value)) - { - return Units::hoursMinutesSecondsToDecimal( - hms.capturedTexts()[1].toDouble(), - hms.capturedTexts()[2].toDouble(), - hms.capturedTexts()[3].toDouble()); - } - return 0.0; -} - -double Astronomy::decToDecimal(const QString& value) -{ - QRegExp decimal("^(-?[0-9]+(\\.[0-9]+)?)"); - QRegExp dms(QString("^(-?[0-9]+)[ %1d]([0-9]+)[ 'm]([0-9]+(\\.[0-9]+)?)[\"s]?").arg(QChar(0xb0))); - - if (decimal.exactMatch(value)) - return decimal.capturedTexts()[0].toDouble(); - else if (dms.exactMatch(value)) - { - return Units::degreesMinutesSecondsToDecimal( - dms.capturedTexts()[1].toDouble(), - dms.capturedTexts()[2].toDouble(), - dms.capturedTexts()[3].toDouble()); - } - return 0.0; -} - double Astronomy::lstAndRAToLongitude(double lst, double raHours) { double longitude = lst - (raHours * 15.0); // Convert hours to degrees diff --git a/sdrbase/util/astronomy.h b/sdrbase/util/astronomy.h index 7d9665a904..1bb65a8f33 100644 --- a/sdrbase/util/astronomy.h +++ b/sdrbase/util/astronomy.h @@ -64,9 +64,6 @@ class SDRBASE_API Astronomy { static double refractionSaemundsson(double alt, double pressure, double temperature); static double refractionPAL(double alt, double pressure, double temperature, double humidity, double frequency, double latitude, double heightAboveSeaLevel, double temperatureLapseRate); - static double raToDecimal(const QString& value); - static double decToDecimal(const QString& value); - static double lstAndRAToLongitude(double lst, double raHours); static void equatorialToGalactic(double ra, double dec, double& l, double& b); diff --git a/sdrbase/util/fits.cpp b/sdrbase/util/fits.cpp index 70145f28b9..f91cddf303 100644 --- a/sdrbase/util/fits.cpp +++ b/sdrbase/util/fits.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -49,59 +49,73 @@ FITS::FITS(QString resourceName) : int hLen = std::min((qint64)m_headerSize * 3, m_fileSize); // Could possibly be bigger QByteArray headerBytes = m_data.left(hLen); QString header = QString::fromLatin1(headerBytes); - QRegExp widthRE("NAXIS1 *= *([0-9]+)"); - QRegExp heightRE("NAXIS2 *= *([0-9]+)"); - QRegExp bitsPerPixelRE("BITPIX *= *(-?[0-9]+)"); - QRegExp bzeroRE("BZERO *= *([0-9]+)"); - QRegExp bscaleRE("BSCALE *= *(-?[0-9]+(.[0-9]+)?)"); - QRegExp buintRE("BUNIT *= *\\'([A-Z ]+)\\'"); - QRegExp cdelt1RE("CDELT1 *= *(-?[0-9]+(.[0-9]+)?)"); - QRegExp cdelt2RE("CDELT2 *= *(-?[0-9]+(.[0-9]+)?)"); - QRegExp endRE("END {77}"); - - if (widthRE.indexIn(header) != -1) - m_width = widthRE.capturedTexts()[1].toInt(); + QRegularExpression widthRE("NAXIS1 *= *([0-9]+)"); + QRegularExpression heightRE("NAXIS2 *= *([0-9]+)"); + QRegularExpression bitsPerPixelRE("BITPIX *= *(-?[0-9]+)"); + QRegularExpression bzeroRE("BZERO *= *([0-9]+)"); + QRegularExpression bscaleRE("BSCALE *= *(-?[0-9]+(.[0-9]+)?)"); + QRegularExpression buintRE("BUNIT *= *\\'([A-Z ]+)\\'"); + QRegularExpression cdelt1RE("CDELT1 *= *(-?[0-9]+(.[0-9]+)?)"); + QRegularExpression cdelt2RE("CDELT2 *= *(-?[0-9]+(.[0-9]+)?)"); + QRegularExpression endRE("END {77}"); + QRegularExpressionMatch match; + + match = widthRE.match(header); + if (match.hasMatch()) + m_width = match.capturedTexts()[1].toInt(); else { qWarning() << "FITS: NAXIS1 missing"; return; } - if (heightRE.indexIn(header) != -1) - m_height = heightRE.capturedTexts()[1].toInt(); + + match = heightRE.match(header); + if (match.hasMatch()) + m_height = match.capturedTexts()[1].toInt(); else { qWarning() << "FITS: NAXIS2 missing"; return; } - if (bitsPerPixelRE.indexIn(header) != -1) - m_bitsPerPixel = bitsPerPixelRE.capturedTexts()[1].toInt(); + + match = bitsPerPixelRE.match(header); + if (match.hasMatch()) + m_bitsPerPixel = match.capturedTexts()[1].toInt(); else { qWarning() << "FITS: BITPIX missing"; return; } + m_bytesPerPixel = abs(m_bitsPerPixel)/8; - if (bzeroRE.indexIn(header) != -1) - m_bzero = bzeroRE.capturedTexts()[1].toInt(); + match = bzeroRE.match(header); + if (match.hasMatch()) + m_bzero = match.capturedTexts()[1].toInt(); else m_bzero = 0; - if (bscaleRE.indexIn(header) != -1) - m_bscale = bscaleRE.capturedTexts()[1].toDouble(); + + match = bscaleRE.match(header); + if (match.hasMatch()) + m_bscale = match.capturedTexts()[1].toDouble(); else m_bscale = 1.0; - if (cdelt1RE.indexIn(header) != -1) - m_cdelta1 = cdelt1RE.capturedTexts()[1].toDouble(); + match = cdelt1RE.match(header); + if (match.hasMatch()) + m_cdelta1 = match.capturedTexts()[1].toDouble(); else m_cdelta1 = 0.0; - if (cdelt2RE.indexIn(header) != -1) - m_cdelta2 = cdelt2RE.capturedTexts()[1].toDouble(); + + match = cdelt2RE.match(header); + if (match.hasMatch()) + m_cdelta2 = match.capturedTexts()[1].toDouble(); else m_cdelta2 = 0.0; - if (buintRE.indexIn(header) != -1) + match = buintRE.match(header); + if (match.hasMatch()) { - m_buint = buintRE.capturedTexts()[1].trimmed(); + m_buint = match.capturedTexts()[1].trimmed(); if (m_buint.contains("MILLI")) m_uintScale = 0.001f; else @@ -109,8 +123,10 @@ FITS::FITS(QString resourceName) : } else m_uintScale = 1.0f; - int endIdx = endRE.indexIn(header); - if (endIdx == -1) + + match = endRE.match(header); + int endIdx = match.capturedStart(0); + if (!match.hasMatch()) { qWarning() << "FITS: END missing"; return; diff --git a/sdrbase/util/maidenhead.cpp b/sdrbase/util/maidenhead.cpp index 640738b06c..8d60b5be7e 100644 --- a/sdrbase/util/maidenhead.cpp +++ b/sdrbase/util/maidenhead.cpp @@ -19,7 +19,7 @@ #include -#include +#include #include "maidenhead.h" @@ -83,6 +83,6 @@ bool Maidenhead::isMaidenhead(const QString& maidenhead) int length = maidenhead.length(); if ((length != 4) && (length != 6) && (length != 8)) return false; - QRegExp re("[A-Ra-r][A-Ra-r][0-9][0-9]([A-Xa-x][A-Xa-x]([0-9][0-9])?)?"); - return re.exactMatch(maidenhead); + QRegularExpression re(QRegularExpression::anchoredPattern("[A-Ra-r][A-Ra-r][0-9][0-9]([A-Xa-x][A-Xa-x]([0-9][0-9])?)?")); + return re.match(maidenhead).hasMatch(); } diff --git a/sdrbase/util/units.h b/sdrbase/util/units.h index 59ad21f6d5..edfe1f847a 100644 --- a/sdrbase/util/units.h +++ b/sdrbase/util/units.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "export.h" @@ -158,35 +158,35 @@ class SDRBASE_API Units // Also supports decimal degrees static bool degreeMinuteAndSecondsToDecimalDegrees(const QString& string, float& degrees) { - QRegExp decimal("(-?[0-9]+(\\.[0-9]+)?)"); - if (decimal.exactMatch(string)) + QRegularExpression decimal(QRegularExpression::anchoredPattern("(-?[0-9]+(\\.[0-9]+)?)")); + QRegularExpressionMatch match; + match = decimal.match(string); + if (match.hasMatch()) { - degrees = decimal.capturedTexts()[1].toFloat(); + degrees = match.capturedTexts()[1].toFloat(); return true; } - QRegExp dms(QString("(-)?([0-9]+)[%1d](([0-9]+)['m](([0-9]+(\\.[0-9]+)?)[\"s])?)?").arg(QChar(0xb0))); - if (dms.exactMatch(string)) + + QRegularExpression dms(QRegularExpression::anchoredPattern(QString("(-)?([0-9]+)[%1d](([0-9]+)['m](([0-9]+(\\.[0-9]+)?)[\"s])?)?").arg(QChar(0xb0)))); + match = dms.match(string); + if (match.hasMatch()) { float d = 0.0f; bool neg = false; - for (int i = 0; i < dms.captureCount(); i++) { - qDebug() << dms.capturedTexts()[i]; - } if (dms.captureCount() >= 1) { - neg = dms.capturedTexts()[1] == "-"; + neg = match.capturedTexts()[1] == "-"; } if (dms.captureCount() >= 3) { - d = dms.capturedTexts()[2].toFloat(); + d = match.capturedTexts()[2].toFloat(); } float m = 0.0f; if (dms.captureCount() >= 5) { - m = dms.capturedTexts()[4].toFloat(); + m = match.capturedTexts()[4].toFloat(); } float s = 0.0f; if (dms.captureCount() >= 7) { - s = dms.capturedTexts()[6].toFloat(); + s = match.capturedTexts()[6].toFloat(); } - qDebug() << neg << d << m << s; degrees = d + m/60.0 + s/(60.0*60.0); if (neg) { degrees = -degrees; @@ -271,24 +271,29 @@ class SDRBASE_API Units // We support both decimal and DMS formats static bool stringToLatitudeAndLongitude(const QString& string, float& latitude, float& longitude) { - QRegExp decimal("(-?[0-9]+(\\.[0-9]+)?) *,? *(-?[0-9]+(\\.[0-9]+)?)"); - if (decimal.exactMatch(string)) + QRegularExpressionMatch match; + + QRegularExpression decimal(QRegularExpression::anchoredPattern("(-?[0-9]+(\\.[0-9]+)?) *,? *(-?[0-9]+(\\.[0-9]+)?)")); + match = decimal.match(string); + if (match.hasMatch()) { - latitude = decimal.capturedTexts()[1].toFloat(); - longitude = decimal.capturedTexts()[3].toFloat(); + latitude = match.capturedTexts()[1].toFloat(); + longitude = match.capturedTexts()[3].toFloat(); return true; } - QRegExp dms(QString("([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([NS]) *,? *([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([EW])").arg(QChar(0xb0))); - if (dms.exactMatch(string)) + + QRegularExpression dms(QRegularExpression::anchoredPattern(QString("([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([NS]) *,? *([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([EW])").arg(QChar(0xb0)))); + match = dms.match(string); + if (match.hasMatch()) { - float latD = dms.capturedTexts()[1].toFloat(); - float latM = dms.capturedTexts()[2].toFloat(); - float latS = dms.capturedTexts()[3].toFloat(); - bool north = dms.capturedTexts()[5] == "N"; - float lonD = dms.capturedTexts()[6].toFloat(); - float lonM = dms.capturedTexts()[7].toFloat(); - float lonS = dms.capturedTexts()[8].toFloat(); - bool east = dms.capturedTexts()[10] == "E"; + float latD = match.capturedTexts()[1].toFloat(); + float latM = match.capturedTexts()[2].toFloat(); + float latS = match.capturedTexts()[3].toFloat(); + bool north = match.capturedTexts()[5] == "N"; + float lonD = match.capturedTexts()[6].toFloat(); + float lonM = match.capturedTexts()[7].toFloat(); + float lonS = match.capturedTexts()[8].toFloat(); + bool east = match.capturedTexts()[10] == "E"; latitude = latD + latM/60.0 + latS/(60.0*60.0); if (!north) latitude = -latitude; @@ -297,17 +302,19 @@ class SDRBASE_API Units longitude = -longitude; return true; } - QRegExp dms2(QString("([0-9]+)([NS])([0-9]{2})([0-9]{2}) *,?([0-9]+)([EW])([0-9]{2})([0-9]{2})")); - if (dms2.exactMatch(string)) + + QRegularExpression dms2(QRegularExpression::anchoredPattern(QString("([0-9]+)([NS])([0-9]{2})([0-9]{2}) *,?([0-9]+)([EW])([0-9]{2})([0-9]{2})"))); + match = dms2.match(string); + if (match.hasMatch()) { - float latD = dms2.capturedTexts()[1].toFloat(); - bool north = dms2.capturedTexts()[2] == "N"; - float latM = dms2.capturedTexts()[3].toFloat(); - float latS = dms2.capturedTexts()[4].toFloat(); - float lonD = dms2.capturedTexts()[5].toFloat(); - bool east = dms2.capturedTexts()[6] == "E"; - float lonM = dms2.capturedTexts()[7].toFloat(); - float lonS = dms2.capturedTexts()[8].toFloat(); + float latD = match.capturedTexts()[1].toFloat(); + bool north = match.capturedTexts()[2] == "N"; + float latM = match.capturedTexts()[3].toFloat(); + float latS = match.capturedTexts()[4].toFloat(); + float lonD = match.capturedTexts()[5].toFloat(); + bool east = match.capturedTexts()[6] == "E"; + float lonM = match.capturedTexts()[7].toFloat(); + float lonS = match.capturedTexts()[8].toFloat(); latitude = latD + latM/60.0 + latS/(60.0*60.0); if (!north) latitude = -latitude; @@ -316,18 +323,20 @@ class SDRBASE_API Units longitude = -longitude; return true; } + // 512255.5900N 0024400.6105W as used on aviation charts - QRegExp dms3(QString("(\\d{2})(\\d{2})((\\d{2})(\\.\\d+)?)([NS]) *,?(\\d{3})(\\d{2})((\\d{2})(\\.\\d+)?)([EW])")); - if (dms3.exactMatch(string)) + QRegularExpression dms3(QRegularExpression::anchoredPattern(QString("(\\d{2})(\\d{2})((\\d{2})(\\.\\d+)?)([NS]) *,?(\\d{3})(\\d{2})((\\d{2})(\\.\\d+)?)([EW])"))); + match = dms3.match(string); + if (match.hasMatch()) { - float latD = dms3.capturedTexts()[1].toFloat(); - float latM = dms3.capturedTexts()[2].toFloat(); - float latS = dms3.capturedTexts()[3].toFloat(); - bool north = dms3.capturedTexts()[6] == "N"; - float lonD = dms3.capturedTexts()[7].toFloat(); - float lonM = dms3.capturedTexts()[8].toFloat(); - float lonS = dms3.capturedTexts()[9].toFloat(); - bool east = dms3.capturedTexts()[12] == "E"; + float latD = match.capturedTexts()[1].toFloat(); + float latM = match.capturedTexts()[2].toFloat(); + float latS = match.capturedTexts()[3].toFloat(); + bool north = match.capturedTexts()[6] == "N"; + float lonD = match.capturedTexts()[7].toFloat(); + float lonM = match.capturedTexts()[8].toFloat(); + float lonS = match.capturedTexts()[9].toFloat(); + bool east = match.capturedTexts()[12] == "E"; latitude = latD + latM/60.0 + latS/(60.0*60.0); if (!north) latitude = -latitude; @@ -348,17 +357,19 @@ class SDRBASE_API Units // 107.1324 -34.233 static bool stringToRADec(const QString& string, float& ra, float& dec) { - QRegExp dms("([0-9]+)[ :h]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s? *,? *([+-]?[0-9]+)[ :d]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s?"); - if (dms.exactMatch(string)) + QRegularExpressionMatch match; + QRegularExpression dms(QRegularExpression::anchoredPattern("([0-9]+)[ :h]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s? *,? *([+-]?[0-9]+)[ :d]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s?")); + match = dms.match(string); + if (match.hasMatch()) { - int raHours = dms.capturedTexts()[1].toInt(); - int raMins = dms.capturedTexts()[2].toInt(); - float raSecs = dms.capturedTexts()[3].toFloat(); + int raHours = match.capturedTexts()[1].toInt(); + int raMins = match.capturedTexts()[2].toInt(); + float raSecs = match.capturedTexts()[3].toFloat(); ra = raHours + raMins / 60.0f + raSecs / (60.0f * 60.0f); qDebug() << ra << raHours << raMins << raSecs; - int decDegs = dms.capturedTexts()[5].toInt(); - int decMins = dms.capturedTexts()[6].toInt(); - float decSecs = dms.capturedTexts()[7].toFloat(); + int decDegs = match.capturedTexts()[5].toInt(); + int decMins = match.capturedTexts()[6].toInt(); + float decSecs = match.capturedTexts()[7].toFloat(); bool neg = decDegs < 0; dec = abs(decDegs) + decMins / 60.0f + decSecs / (60.0f * 60.0f); if (neg) { @@ -366,16 +377,56 @@ class SDRBASE_API Units } return true; } - QRegExp decimal("([0-9]+(\\.[0-9]+)?) *,? *([+-]?[0-9]+(\\.[0-9]+)?)"); - if (decimal.exactMatch(string)) + + QRegularExpression decimal(QRegularExpression::anchoredPattern("([0-9]+(\\.[0-9]+)?) *,? *([+-]?[0-9]+(\\.[0-9]+)?)")); + match = decimal.match(string); + if (match.hasMatch()) { - ra = decimal.capturedTexts()[1].toFloat(); - dec = decimal.capturedTexts()[3].toFloat(); + ra = match.capturedTexts()[1].toFloat(); + dec = match.capturedTexts()[3].toFloat(); return true; } return false; } + static double raToDecimal(const QString& value) + { + QRegularExpression decimal(QRegularExpression::anchoredPattern("^([0-9]+(\\.[0-9]+)?)")); + QRegularExpression hms(QRegularExpression::anchoredPattern("^([0-9]+)[ h]([0-9]+)[ m]([0-9]+(\\.[0-9]+)?)s?")); + QRegularExpressionMatch decimalMatch = decimal.match(value); + QRegularExpressionMatch hmsMatch = hms.match(value); + + if (decimalMatch.hasMatch()) + return decimalMatch.capturedTexts()[0].toDouble(); + else if (hmsMatch.hasMatch()) + { + return Units::hoursMinutesSecondsToDecimal( + hmsMatch.capturedTexts()[1].toDouble(), + hmsMatch.capturedTexts()[2].toDouble(), + hmsMatch.capturedTexts()[3].toDouble()); + } + return 0.0; + } + + static double decToDecimal(const QString& value) + { + QRegularExpression decimal(QRegularExpression::anchoredPattern("^(-?[0-9]+(\\.[0-9]+)?)")); + QRegularExpression dms(QRegularExpression::anchoredPattern(QString("^(-?[0-9]+)[ %1d]([0-9]+)[ 'm]([0-9]+(\\.[0-9]+)?)[\"s]?").arg(QChar(0xb0)))); + QRegularExpressionMatch decimalMatch = decimal.match(value); + QRegularExpressionMatch dmsMatch = dms.match(value); + + if (decimalMatch.hasMatch()) + return decimalMatch.capturedTexts()[0].toDouble(); + else if (dmsMatch.hasMatch()) + { + return Units::degreesMinutesSecondsToDecimal( + dmsMatch.capturedTexts()[1].toDouble(), + dmsMatch.capturedTexts()[2].toDouble(), + dmsMatch.capturedTexts()[3].toDouble()); + } + return 0.0; + } + static float solarFluxUnitsToJansky(float sfu) { return sfu * 10000.0f;