-
Notifications
You must be signed in to change notification settings - Fork 185
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
Move non-templated function definitions out of header files in mrtrix.h and stats.h #2809
Changes from all commits
907d057
af3ae46
9c4be7e
318ac47
ff98d70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
|
||
#include "connectome/connectome.h" | ||
|
||
#include <iomanip> | ||
|
||
using namespace MR; | ||
using namespace App; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,8 @@ | |||||
|
||||||
#include "mrtrix.h" | ||||||
|
||||||
#include <cstdarg> | ||||||
|
||||||
namespace MR { | ||||||
|
||||||
/************************************************************************ | ||||||
|
@@ -128,4 +130,138 @@ bool match(const std::string &pattern, const std::string &text, bool ignore_case | |||||
return __match(pattern.c_str(), text.c_str()); | ||||||
} | ||||||
|
||||||
std::istream &getline(std::istream &stream, std::string &string) { | ||||||
std::getline(stream, string); | ||||||
if (!string.empty()) | ||||||
if (string[string.size() - 1] == 015) | ||||||
string.resize(string.size() - 1); | ||||||
return stream; | ||||||
} | ||||||
|
||||||
std::string &add_line(std::string &original, const std::string &new_line) { | ||||||
return original.empty() ? (original = new_line) : (original += "\n" + new_line); | ||||||
} | ||||||
|
||||||
std::string shorten(const std::string &text, size_t longest, size_t prefix) { | ||||||
if (text.size() > longest) | ||||||
return (text.substr(0, prefix) + "..." + text.substr(text.size() - longest + prefix + 3)); | ||||||
else | ||||||
return text; | ||||||
} | ||||||
|
||||||
std::string lowercase(const std::string &string) { | ||||||
std::string ret; | ||||||
ret.resize(string.size()); | ||||||
transform(string.begin(), string.end(), ret.begin(), tolower); | ||||||
return ret; | ||||||
} | ||||||
|
||||||
std::string uppercase(const std::string &string) { | ||||||
std::string ret; | ||||||
ret.resize(string.size()); | ||||||
transform(string.begin(), string.end(), ret.begin(), toupper); | ||||||
return ret; | ||||||
} | ||||||
|
||||||
std::string printf(const char *format, ...) { | ||||||
size_t len = 0; | ||||||
va_list list1, list2; | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
va_start(list1, format); | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
va_copy(list2, list1); | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
len = vsnprintf(nullptr, 0, format, list1) + 1; | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
va_end(list1); | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
VLA(buf, char, len); | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
vsnprintf(buf, len, format, list2); | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
va_end(list2); | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return buf; | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
std::string strip(const std::string &string, const std::string &ws, bool left, bool right) { | ||||||
const std::string::size_type start = (left ? string.find_first_not_of(ws) : 0); | ||||||
if (start == std::string::npos) | ||||||
return ""; | ||||||
const std::string::size_type end = (right ? string.find_last_not_of(ws) + 1 : std::string::npos); | ||||||
return string.substr(start, end - start); | ||||||
} | ||||||
|
||||||
std::string unquote(const std::string &string) { | ||||||
if (string.size() <= 2) | ||||||
return string; | ||||||
if (!(string.front() == '\"' && string.back() == '\"')) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
Suggested change
|
||||||
return string; | ||||||
std::string substring = string.substr(1, string.size() - 2); | ||||||
if (std::none_of(substring.begin(), substring.end(), [](const char &c) { return c == '\"'; })) | ||||||
return substring; | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return string; | ||||||
} | ||||||
|
||||||
void replace(std::string &string, char orig, char final) { | ||||||
for (auto &c : string) | ||||||
if (c == orig) | ||||||
c = final; | ||||||
} | ||||||
|
||||||
void replace(std::string &str, const std::string &from, const std::string &to) { | ||||||
if (from.empty()) | ||||||
return; | ||||||
size_t start_pos = 0; | ||||||
while ((start_pos = str.find(from, start_pos)) != std::string::npos) { | ||||||
str.replace(start_pos, from.length(), to); | ||||||
start_pos += to.length(); | ||||||
} | ||||||
} | ||||||
|
||||||
std::vector<std::string> split_lines(const std::string &string, bool ignore_empty_fields, size_t num) { | ||||||
return split(string, "\n", ignore_empty_fields, num); | ||||||
} | ||||||
|
||||||
size_t char_is_dash(const char *arg) { | ||||||
assert(arg != nullptr); | ||||||
if (arg[0] == '-') | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return 1; | ||||||
if (arg[0] == '\0' || arg[1] == '\0' || arg[2] == '\0') | ||||||
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
daljit46 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return 0; | ||||||
const unsigned char *uarg = reinterpret_cast<const unsigned char *>(arg); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast] const unsigned char *uarg = reinterpret_cast<const unsigned char *>(arg);
^ |
||||||
if (uarg[0] == 0xE2 && uarg[1] == 0x80 && (uarg[2] >= 0x90 && uarg[2] <= 0x95)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[0] == 0xE2 && uarg[1] == 0x80 && (uarg[2] >= 0x90 && uarg[2] <= 0x95))
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[0] == 0xE2 && uarg[1] == 0x80 && (uarg[2] >= 0x90 && uarg[2] <= 0x95))
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[0] == 0xE2 && uarg[1] == 0x80 && (uarg[2] >= 0x90 && uarg[2] <= 0x95))
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[0] == 0xE2 && uarg[1] == 0x80 && (uarg[2] >= 0x90 && uarg[2] <= 0x95))
^ |
||||||
return 3; | ||||||
if (uarg[0] == 0xEF) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[0] == 0xEF) {
^ |
||||||
if (uarg[1] == 0xB9 && (uarg[2] == 0x98 || uarg[2] == 0xA3)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[1] == 0xB9 && (uarg[2] == 0x98 || uarg[2] == 0xA3))
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[1] == 0xB9 && (uarg[2] == 0x98 || uarg[2] == 0xA3))
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[1] == 0xB9 && (uarg[2] == 0x98 || uarg[2] == 0xA3))
^ |
||||||
return 3; | ||||||
if (uarg[1] == 0xBC && uarg[2] == 0x8D) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[1] == 0xBC && uarg[2] == 0x8D)
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] if (uarg[1] == 0xBC && uarg[2] == 0x8D)
^ |
||||||
return 3; | ||||||
} | ||||||
return 0; | ||||||
} | ||||||
|
||||||
bool is_dash(const std::string &arg) { | ||||||
const size_t nbytes = char_is_dash(arg.c_str()); | ||||||
return nbytes != 0 && nbytes == arg.size(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: implicit conversion bool -> 'size_t' (aka 'unsigned long') [readability-implicit-bool-conversion]
Suggested change
|
||||||
} | ||||||
|
||||||
bool consume_dash(const char *&arg) { | ||||||
size_t nbytes = char_is_dash(arg); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'nbytes' of type 'size_t' (aka 'unsigned long') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
arg += nbytes; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] arg += nbytes;
^ |
||||||
return nbytes != 0; | ||||||
} | ||||||
|
||||||
std::string join(const std::vector<std::string> &V, const std::string &delimiter) { | ||||||
std::string ret; | ||||||
if (V.empty()) | ||||||
return ret; | ||||||
ret = V[0]; | ||||||
for (std::vector<std::string>::const_iterator i = V.begin() + 1; i != V.end(); ++i) | ||||||
ret += delimiter + *i; | ||||||
return ret; | ||||||
} | ||||||
|
||||||
std::string join(const char *const *null_terminated_array, const std::string &delimiter) { | ||||||
std::string ret; | ||||||
if (!null_terminated_array) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: implicit conversion 'const char *const *' -> bool [readability-implicit-bool-conversion]
Suggested change
|
||||||
return ret; | ||||||
ret = null_terminated_array[0]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] ret = null_terminated_array[0];
^ |
||||||
for (const char *const *p = null_terminated_array + 1; *p; ++p) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] for (const char *const *p = null_terminated_array + 1; *p; ++p)
^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: implicit conversion 'const char *' -> bool [readability-implicit-bool-conversion]
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic] for (const char *const *p = null_terminated_array + 1; *p; ++p)
^ |
||||||
ret += delimiter + *p; | ||||||
return ret; | ||||||
} | ||||||
|
||||||
} // namespace MR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: do not use 'else' after 'return' [readability-else-after-return]