From 7da564a27e7d664dd0bf5924d6651f6d0a626084 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Thu, 29 Dec 2022 12:02:28 -0700 Subject: [PATCH] Use QString::compare(QStringView, Qt::CaseSensitivity) (#965) * use QString::compare(QString, Qt::CaseSensitivity) instead of case_ignore_strcmp with a QString and a character literal. * use QString::compare(QStringView, Qt::CaseSensitivity) instead of QString::compare(QLatin1String, Qt::CaseSensitivity). * compare QStrings to character literals instead of string literals that only contain one character. --- garmin_device_xml.cc | 2 +- garmin_txt.cc | 18 +++++++++--------- gbfile.cc | 2 +- gpx.cc | 4 ++-- lowranceusr.cc | 4 ++-- ozi.cc | 2 +- shape.cc | 2 +- unicsv.cc | 22 +++++++++++----------- xcsv.cc | 14 +++++++------- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/garmin_device_xml.cc b/garmin_device_xml.cc index f880d0c96..2b43a9e94 100644 --- a/garmin_device_xml.cc +++ b/garmin_device_xml.cc @@ -42,7 +42,7 @@ jmp_buf gdx_jmp_buf; static void type_s(xg_string args, const QXmlStreamAttributes*) { - type = args.compare(QLatin1String("GPSData")); + type = args.compare(u"GPSData"); } void device_s(xg_string args, const QXmlStreamAttributes*) diff --git a/garmin_txt.cc b/garmin_txt.cc index 46d4cd3f1..dd24e4197 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -1391,23 +1391,23 @@ garmin_txt_read() auto linetype = lineparts.at(0); lineparts.removeFirst(); - if (case_ignore_strcmp(linetype, "Header") == 0) { + if (linetype.compare(u"Header", Qt::CaseInsensitive) == 0) { parse_header(lineparts); - } else if (case_ignore_strcmp(linetype, "Grid") == 0) { + } else if (linetype.compare(u"Grid", Qt::CaseInsensitive) == 0) { parse_grid(lineparts); - } else if (case_ignore_strcmp(linetype, "Datum") == 0) { + } else if (linetype.compare(u"Datum", Qt::CaseInsensitive) == 0) { parse_datum(lineparts); - } else if (case_ignore_strcmp(linetype, "Waypoint") == 0) { + } else if (linetype.compare(u"Waypoint", Qt::CaseInsensitive) == 0) { parse_waypoint(lineparts); - } else if (case_ignore_strcmp(linetype, "Route Waypoint") == 0) { + } else if (linetype.compare(u"Route Waypoint", Qt::CaseInsensitive) == 0) { parse_route_waypoint(lineparts); - } else if (case_ignore_strcmp(linetype, "Trackpoint") == 0) { + } else if (linetype.compare(u"Trackpoint", Qt::CaseInsensitive) == 0) { parse_track_waypoint(lineparts); - } else if (case_ignore_strcmp(linetype, "Route") == 0) { + } else if (linetype.compare(u"Route", Qt::CaseInsensitive) == 0) { parse_route_header(lineparts); - } else if (case_ignore_strcmp(linetype, "Track") == 0) { + } else if (linetype.compare(u"Track", Qt::CaseInsensitive) == 0) { parse_track_header(lineparts); - } else if (case_ignore_strcmp(linetype, "Map") == 0) /* do nothing */ ; + } else if (linetype.compare(u"Map", Qt::CaseInsensitive) == 0) /* do nothing */ ; else { fatal(MYNAME ": Unknown identifier (%s) at line %d!\n", qPrintable(linetype), current_line); } diff --git a/gbfile.cc b/gbfile.cc index d3d6b9ec4..cc810fa1c 100644 --- a/gbfile.cc +++ b/gbfile.cc @@ -542,7 +542,7 @@ gbfopen(const QString& filename, const char* mode, const char* module) file->filewrite = memapi_write; } else { file->name = xstrdup(filename); - file->is_pipe = (filename == "-"); + file->is_pipe = (filename == '-'); /* Do we have a '.gz' extension in the filename ? */ int len = strlen(file->name); diff --git a/gpx.cc b/gpx.cc index f671f42b8..e034de254 100644 --- a/gpx.cc +++ b/gpx.cc @@ -656,7 +656,7 @@ GpxFormat::gpx_end(QStringView /*unused*/) * last date we saw in this log. */ case tt_cache_log_type: - if ((cdatastr.compare(QLatin1String("Found it")) == 0) && + if ((cdatastr.compare(u"Found it") == 0) && (0 == wpt_tmp->gc_data->last_found.toTime_t())) { wpt_tmp->AllocGCData()->last_found = gc_log_date; } @@ -1154,7 +1154,7 @@ GpxFormat::fprint_xml_chain(XmlTag* tag, const Waypoint* wpt) const fprint_xml_chain(tag->child, wpt); } if (wpt && wpt->gc_data->exported.isValid() && - tag->tagname.compare(QLatin1String("groundspeak:cache")) == 0) { + tag->tagname.compare(u"groundspeak:cache") == 0) { writer->writeTextElement(QStringLiteral("time"), wpt->gc_data->exported.toPrettyString()); } diff --git a/lowranceusr.cc b/lowranceusr.cc index 975eae8c2..e7bb1d39b 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -1346,7 +1346,7 @@ LowranceusrFormat::lowranceusr_waypt_disp(const Waypoint* wpt) const gbfputint32(waypt_time, file_out); - if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(QLatin1String("Geocache Found")) == 0) { + if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) { SymbolId = lowranceusr_find_icon_number_from_desc(get_cache_icon(wpt)); } else { SymbolId = lowranceusr_find_icon_number_from_desc(wpt->icon_descr); @@ -1407,7 +1407,7 @@ LowranceusrFormat::lowranceusr4_waypt_disp(const Waypoint* wpt) gbfputint32(2, file_out); int SymbolId, ColorId; - if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(QLatin1String("Geocache Found")) == 0) { + if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) { if (writing_version == 4) { SymbolId = lowranceusr4_find_icon_number_from_desc(wpt->icon_descr); } else { diff --git a/ozi.cc b/ozi.cc index 658a8a26b..3bb429898 100644 --- a/ozi.cc +++ b/ozi.cc @@ -233,7 +233,7 @@ ozi_openfile(const QString& fname) * mytrack.plt, mytrack-1.plt...unless we're writing to stdout. */ - if (fname == "-") { + if (fname == '-') { if (stream == nullptr) { ozi_open_io(fname, QFile::WriteOnly); } diff --git a/shape.cc b/shape.cc index 874ddb0aa..94321902b 100644 --- a/shape.cc +++ b/shape.cc @@ -193,7 +193,7 @@ ShapeFormat::rd_init(const QString& fname) const char* codepage = DBFGetCodePage(ihandledb); if (codepage) { QString qcodepage(codepage); - if (qcodepage.compare(QLatin1String("UTF-8"), Qt::CaseInsensitive)) { + if (qcodepage.compare(u"UTF-8", Qt::CaseInsensitive)) { warning(MYNAME ": dbf file %s is in code page %s, but we always process dbf files as UTF-8.\n",qPrintable(ifname),codepage); } } else { diff --git a/unicsv.cc b/unicsv.cc index 0f710b666..ad6590c1f 100644 --- a/unicsv.cc +++ b/unicsv.cc @@ -324,14 +324,14 @@ UnicsvFormat::unicsv_parse_time(const QString& str, int* msec, time_t* date) status_type UnicsvFormat::unicsv_parse_status(const QString& str) { - if (str.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 || - str.compare(QLatin1String("yes"), Qt::CaseInsensitive) == 0 || - str == "1") { + if (str.compare(u"true", Qt::CaseInsensitive) == 0 || + str.compare(u"yes", Qt::CaseInsensitive) == 0 || + str == '1') { return status_true; } - if (str.compare(QLatin1String("false"), Qt::CaseInsensitive) == 0 || - str.compare(QLatin1String("no"), Qt::CaseInsensitive) == 0 || - str == "0") { + if (str.compare(u"false", Qt::CaseInsensitive) == 0 || + str.compare(u"no", Qt::CaseInsensitive) == 0 || + str == '0') { return status_false; } return status_unknown; @@ -668,15 +668,15 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf) if (unicsv_detect) { unicsv_data_type = trkdata; } - if (case_ignore_strcmp(value, "none") == 0) { + if (value.compare(u"none", Qt::CaseInsensitive) == 0) { wpt->fix = fix_none; - } else if (case_ignore_strcmp(value, "2d") == 0) { + } else if (value.compare(u"2d", Qt::CaseInsensitive) == 0) { wpt->fix = fix_2d; - } else if (case_ignore_strcmp(value, "3d") == 0) { + } else if (value.compare(u"3d", Qt::CaseInsensitive) == 0) { wpt->fix = fix_3d; - } else if (case_ignore_strcmp(value, "dgps") == 0) { + } else if (value.compare(u"dgps", Qt::CaseInsensitive) == 0) { wpt->fix = fix_dgps; - } else if (case_ignore_strcmp(value, "pps") == 0) { + } else if (value.compare(u"pps", Qt::CaseInsensitive) == 0) { wpt->fix = fix_pps; } else { wpt->fix = fix_unknown; diff --git a/xcsv.cc b/xcsv.cc index f062444a4..9425e56d8 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -676,9 +676,9 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: break; case XcsvStyle::XT_GEOCACHE_ISAVAILABLE: gc_data = wpt->AllocGCData(); - if (case_ignore_strcmp(value.trimmed(), "False") == 0) { + if (value.trimmed().compare(u"False", Qt::CaseInsensitive) == 0) { gc_data->is_available = status_false; - } else if (case_ignore_strcmp(value.trimmed(), "True") == 0) { + } else if (value.trimmed().compare(u"True", Qt::CaseInsensitive) == 0) { gc_data->is_available = status_true; } else { gc_data->is_available = status_unknown; @@ -686,9 +686,9 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: break; case XcsvStyle::XT_GEOCACHE_ISARCHIVED: gc_data = wpt->AllocGCData(); - if (case_ignore_strcmp(value.trimmed(), "False") == 0) { + if (value.trimmed().compare(u"False", Qt::CaseInsensitive) == 0) { gc_data->is_archived = status_false; - } else if (case_ignore_strcmp(value.trimmed(), "True") == 0) { + } else if (value.trimmed().compare(u"True", Qt::CaseInsensitive) == 0) { gc_data->is_archived = status_true; } else { gc_data->is_archived = status_unknown; @@ -711,11 +711,11 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: case XcsvStyle::XT_GPS_FIX: wpt->fix = (fix_type)(xstrtoi(s, nullptr, 10)-(fix_type)1); if (wpt->fix < fix_2d) { - if (!case_ignore_strcmp(value, "none")) { + if (!value.compare(u"none", Qt::CaseInsensitive)) { wpt->fix = fix_none; - } else if (!case_ignore_strcmp(value, "dgps")) { + } else if (!value.compare(u"dgps", Qt::CaseInsensitive)) { wpt->fix = fix_dgps; - } else if (!case_ignore_strcmp(value, "pps")) { + } else if (!value.compare(u"pps", Qt::CaseInsensitive)) { wpt->fix = fix_pps; } else { wpt->fix = fix_unknown;