Changeset 11158 in ntrip for trunk/BNC/src/bncutils.cpp


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (4 days ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/bncutils.cpp

    r11096 r11158  
    4343#include <math.h>
    4444
    45 #include <QRegExp>
     45#include <QRegularExpression>
    4646#include <QStringList>
    4747#include <QDateTime>
    … …  
    156156}
    157157
    158 //
     158// Replace each ${NAME} by the environment variable NAME (empty if not set);
     159// BNC's own file name placeholders are kept
    159160////////////////////////////////////////////////////////////////////////////
    160161void expandEnvVar(QString& str) {
    161162
    162   QRegExp rx("(\\$\\{.+\\})");
    163 
    164   if (rx.indexIn(str) != -1) {
    165     QStringListIterator it(rx.capturedTexts());
    166     if (it.hasNext()) {
    167       QString rxStr  = it.next();
    168       QString envVar = rxStr.mid(2,rxStr.length()-3);
    169       str.replace(rxStr, qgetenv(envVar.toLatin1()));
    170     }
    171   }
     163  static const QStringList placeholders = QStringList() << "GPSWD" << "V3OBS" << "V3PROD";
     164
     165  QString result;
     166  int     last = 0;
     167  QRegularExpressionMatchIterator it = QRegularExpression("\\$\\{([^}]+)\\}").globalMatch(str);
     168  while (it.hasNext()) {
     169    QRegularExpressionMatch match = it.next();
     170    QString name = match.captured(1);
     171    result += str.mid(last, match.capturedStart() - last);
     172    result += placeholders.contains(name) ? match.captured(0)
     173                                          : QString::fromUtf8(qgetenv(name.toLatin1()));
     174    last = match.capturedEnd();
     175  }
     176  str = result + str.mid(last);
    172177}
    173178
Note: See TracChangeset for help on using the changeset viewer.