Skip to content

Commit

Permalink
Use QString::compare(QStringView, Qt::CaseSensitivity) (GPSBabel#965)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
tsteven4 authored Dec 29, 2022
1 parent 33473e9 commit 7da564a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion garmin_device_xml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down
18 changes: 9 additions & 9 deletions garmin_txt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion gbfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions gpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions lowranceusr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ozi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion shape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions unicsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions xcsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,19 +676,19 @@ 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;
}
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;
Expand All @@ -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;
Expand Down

0 comments on commit 7da564a

Please sign in to comment.