Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CompareNumbers with in-place numeric comparisons. #4550

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 7 additions & 36 deletions gdal/frmts/wcs/wcsutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "ogr_spatialref.h"
#include "wcsutils.h"
#include <algorithm>
#include <string>

#define DIGITS "0123456789"

Expand All @@ -46,45 +47,15 @@ void Swap(double &a, double &b)

int CompareNumbers(const std::string &a, const std::string &b)
{
size_t a_dot = a.find(".");
size_t b_dot = b.find(".");
std::string a_p = a.substr(0, a_dot);
std::string b_p = b.substr(0, b_dot);
int d = (int)(a_p.length()) - (int)(b_p.length());
if (d < 0) {
for (int i = 0; i < -1*d; ++i) {
a_p = "0" + a_p;
}
} else if (d > 0) {
for (int i = 0; i < d; ++i) {
b_p = "0" + b_p;
}
}
int c = a_p.compare(b_p);
if (c < 0) {
return -1;
} else if (c > 0) {
return 1;
}
a_p = a_dot == std::string::npos ? a : a.substr(a_dot + 1);
b_p = b_dot == std::string::npos ? b : b.substr(b_dot + 1);
d = (int)(a_p.length()) - (int)(b_p.length());
if (d < 0) {
for (int i = 0; i < -1*d; ++i) {
a_p = a_p + "0";
}
} else if (d > 0) {
for (int i = 0; i < d; ++i) {
b_p = b_p + "0";
}
}
c = a_p.compare(b_p);
if (c < 0) {
double ad = std::stod(a);
rouault marked this conversation as resolved.
Show resolved Hide resolved
double bd = std::stod(b);
if (ad < bd) {
return -1;
} else if (c > 0) {
} else if (ad > bd) {
return 1;
} else {
return 0;
}
return 0;
}

CPLString URLEncode(const CPLString &str)
Expand Down