summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-03-26 17:12:52 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-03-26 17:20:27 +0900
commitd64089632e82a2548752c7a6baaa68365a795a74 (patch)
tree57fc7b85a8c1290975d58fa4761b04a7695bf7e3 /src/util.h
parentc81b1321122e8509b55c94c0cbca0d8d6d319f0c (diff)
parenta7cd943a06b1a5ff4515b57060b84037f8d01f9f (diff)
Merge branch 'master' into random-webseeding
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h447
1 files changed, 212 insertions, 235 deletions
diff --git a/src/util.h b/src/util.h
index 6f681650..14b5d146 100644
--- a/src/util.h
+++ b/src/util.h
@@ -69,7 +69,7 @@
#endif // ENABLE_SSL
#ifndef HAVE_SIGACTION
-# define sigset_t int
+#define sigset_t int
#endif // HAVE_SIGACTION
namespace aria2 {
@@ -84,11 +84,12 @@ class Option;
#ifdef WORDS_BIGENDIAN
inline uint64_t ntoh64(uint64_t x) { return x; }
inline uint64_t hton64(uint64_t x) { return x; }
-#else // !WORDS_BIGENDIAN
-inline uint64_t byteswap64(uint64_t x) {
+#else // !WORDS_BIGENDIAN
+inline uint64_t byteswap64(uint64_t x)
+{
uint64_t v1 = ntohl(x & 0x00000000ffffffffllu);
uint64_t v2 = ntohl(x >> 32);
- return (v1 << 32)|v2;
+ return (v1 << 32) | v2;
}
inline uint64_t ntoh64(uint64_t x) { return byteswap64(x); }
inline uint64_t hton64(uint64_t x) { return byteswap64(x); }
@@ -102,60 +103,62 @@ std::wstring utf8ToWChar(const char* str);
std::string wCharToUtf8(const std::wstring& wsrc);
// replace any backslash '\' in |src| with '/' and returns it.
-std::string toForwardSlash(const std::string &src);
+std::string toForwardSlash(const std::string& src);
#else // !__MINGW32__
-# define utf8ToWChar(src) src
-# define utf8ToNative(src) src
+#define utf8ToWChar(src) src
+#define utf8ToNative(src) src
#endif // !__MINGW32__
namespace util {
extern const char DEFAULT_STRIP_CHARSET[];
-template<typename InputIterator>
-std::pair<InputIterator, InputIterator> stripIter
-(InputIterator first, InputIterator last,
- const char* chars = DEFAULT_STRIP_CHARSET)
+template <typename InputIterator>
+std::pair<InputIterator, InputIterator>
+stripIter(InputIterator first, InputIterator last,
+ const char* chars = DEFAULT_STRIP_CHARSET)
{
- for(; first != last && strchr(chars, *first) != 0; ++first);
- if(first == last) {
+ for (; first != last && strchr(chars, *first) != 0; ++first)
+ ;
+ if (first == last) {
return std::make_pair(first, last);
}
- InputIterator left = last-1;
- for(; left != first && strchr(chars, *left) != 0; --left);
- return std::make_pair(first, left+1);
+ InputIterator left = last - 1;
+ for (; left != first && strchr(chars, *left) != 0; --left)
+ ;
+ return std::make_pair(first, left + 1);
}
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last, char ch)
+template <typename InputIterator>
+InputIterator lstripIter(InputIterator first, InputIterator last, char ch)
{
- for(; first != last && *first == ch; ++first);
+ for (; first != last && *first == ch; ++first)
+ ;
return first;
}
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last, const char* chars)
+template <typename InputIterator>
+InputIterator lstripIter(InputIterator first, InputIterator last,
+ const char* chars)
{
- for(; first != last && strchr(chars, *first) != 0; ++first);
+ for (; first != last && strchr(chars, *first) != 0; ++first)
+ ;
return first;
}
-template<typename InputIterator>
-InputIterator lstripIter
-(InputIterator first, InputIterator last)
+template <typename InputIterator>
+InputIterator lstripIter(InputIterator first, InputIterator last)
{
return lstripIter(first, last, DEFAULT_STRIP_CHARSET);
}
-std::string strip
-(const std::string& str, const char* chars = DEFAULT_STRIP_CHARSET);
+std::string strip(const std::string& str,
+ const char* chars = DEFAULT_STRIP_CHARSET);
-template<typename InputIterator>
+template <typename InputIterator>
std::pair<std::pair<InputIterator, InputIterator>,
std::pair<InputIterator, InputIterator>>
-divide(InputIterator first, InputIterator last, char delim, bool strip=true)
+divide(InputIterator first, InputIterator last, char delim, bool strip = true)
{
auto dpos = std::find(first, last, delim);
if (dpos == last) {
@@ -171,25 +174,25 @@ divide(InputIterator first, InputIterator last, char delim, bool strip=true)
return {{first, dpos}, {dpos + 1, last}};
}
-template<typename T>
-std::string uitos(T n, bool comma = false)
+template <typename T> std::string uitos(T n, bool comma = false)
{
std::string res;
- if(n == 0) {
+ if (n == 0) {
res = "0";
return res;
}
int i = 0;
T t = n;
- for(; t; t /= 10, ++i);
- if(comma) {
- i += (i-1)/3;
+ for (; t; t /= 10, ++i)
+ ;
+ if (comma) {
+ i += (i - 1) / 3;
}
res.resize(i);
--i;
- for(int j = 0; n; --i, ++j, n /= 10) {
- res[i] = (n%10) + '0';
- if(comma && i > 1 && (j+1)%3 == 0) {
+ for (int j = 0; n; --i, ++j, n /= 10) {
+ res[i] = (n % 10) + '0';
+ if (comma && i > 1 && (j + 1) % 3 == 0) {
res[--i] = ',';
}
}
@@ -206,7 +209,8 @@ std::string itos(int64_t value, bool comma = false);
int64_t difftv(struct timeval tv1, struct timeval tv2);
int32_t difftvsec(struct timeval tv1, struct timeval tv2);
-std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
+std::string replace(const std::string& target, const std::string& oldstr,
+ const std::string& newstr);
std::string percentEncode(const unsigned char* target, size_t len);
@@ -229,8 +233,8 @@ bool isIso8859p1(unsigned char c);
bool isUtf8(const std::string& str);
-std::string percentDecode
-(std::string::const_iterator first, std::string::const_iterator last);
+std::string percentDecode(std::string::const_iterator first,
+ std::string::const_iterator last);
std::string torrentPercentEncode(const unsigned char* target, size_t len);
@@ -247,22 +251,22 @@ unsigned int hexCharToUInt(unsigned char ch);
// Converts hexadecimal ascii characters in [first, last) into packed
// binary form and return the result. If characters in given range is
// not well formed, then empty string is returned.
-template<typename InputIterator>
+template <typename InputIterator>
std::string fromHex(InputIterator first, InputIterator last)
{
std::string dest;
- size_t len = last-first;
- if(len%2) {
+ size_t len = last - first;
+ if (len % 2) {
return dest;
}
- for(; first != last; first += 2) {
+ for (; first != last; first += 2) {
unsigned char high = hexCharToUInt(*first);
- unsigned char low = hexCharToUInt(*(first+1));
- if(high == 255 || low == 255) {
+ unsigned char low = hexCharToUInt(*(first + 1));
+ if (high == 255 || low == 255) {
dest.clear();
return dest;
}
- dest += (high*16+low);
+ dest += (high * 16 + low);
}
return dest;
}
@@ -290,11 +294,10 @@ SegList<int> parseIntSegments(const std::string& src);
// If SIZE is omitted, SIZE=defaultSize is used.
//
// sample: head=512K,tail=512K
-void parsePrioritizePieceRange
-(std::vector<size_t>& result, const std::string& src,
- const std::vector<std::shared_ptr<FileEntry> >& fileEntries,
- size_t pieceLength,
- int64_t defaultSize = 1048576 /* 1MiB */);
+void parsePrioritizePieceRange(
+ std::vector<size_t>& result, const std::string& src,
+ const std::vector<std::shared_ptr<FileEntry>>& fileEntries,
+ size_t pieceLength, int64_t defaultSize = 1048576 /* 1MiB */);
// Converts ISO/IEC 8859-1 string src to utf-8.
std::string iso8859p1ToUtf8(const char* src, size_t len);
@@ -315,9 +318,9 @@ std::string iso8859p1ToUtf8(const std::string& src);
// succeeds, or -1. If there is enough room to store filename in
// |dest|, this function returns -1. If this function returns -1, the
// |dest|, |*charsetp| and |*charsetlenp| are undefined.
-ssize_t parse_content_disposition(char *dest, size_t destlen,
- const char **charsetp, size_t *charsetlenp,
- const char *in, size_t len);
+ssize_t parse_content_disposition(char* dest, size_t destlen,
+ const char** charsetp, size_t* charsetlenp,
+ const char* in, size_t len);
std::string getContentDispositionFilename(const std::string& header);
@@ -335,7 +338,7 @@ char toLowerChar(char c);
bool isNumericHost(const std::string& name);
-typedef void(*signal_handler_t)(int);
+typedef void (*signal_handler_t)(int);
void setGlobalSignalHandler(int signal, sigset_t* mask,
signal_handler_t handler, int flags);
@@ -352,20 +355,21 @@ int64_t getRealSize(const std::string& sizeWithUnit);
std::string abbrevSize(int64_t size);
-template<typename InputIterator, typename Output>
-void toStream
-(InputIterator first, InputIterator last, Output& os)
+template <typename InputIterator, typename Output>
+void toStream(InputIterator first, InputIterator last, Output& os)
{
os.printf("%s\n"
"idx|path/length\n"
- "===+===========================================================================\n", _("Files:"));
+ "===+=============================================================="
+ "=============\n",
+ _("Files:"));
int32_t count = 1;
- for(; first != last; ++first, ++count) {
+ for (; first != last; ++first, ++count) {
os.printf("%3d|%s\n"
" |%sB (%s)\n"
- "---+---------------------------------------------------------------------------\n",
- count,
- (*first)->getPath().c_str(),
+ "---+------------------------------------------------------------"
+ "---------------\n",
+ count, (*first)->getPath().c_str(),
util::abbrevSize((*first)->getLength()).c_str(),
util::uitos((*first)->getLength(), true).c_str());
}
@@ -375,14 +379,14 @@ void sleep(long seconds);
void usleep(long microseconds);
-template<typename InputIterator>
+template <typename InputIterator>
bool isNumber(InputIterator first, InputIterator last)
{
- if(first == last) {
+ if (first == last) {
return false;
}
- for(; first != last; ++first) {
- if('0' > *first || *first > '9') {
+ for (; first != last; ++first) {
+ if ('0' > *first || *first > '9') {
return false;
}
}
@@ -401,28 +405,28 @@ bool isLws(const char c);
bool isCRLF(const char c);
-template<typename InputIterator>
+template <typename InputIterator>
bool isLowercase(InputIterator first, InputIterator last)
{
- if(first == last) {
+ if (first == last) {
return false;
}
- for(; first != last; ++first) {
- if('a' > *first || *first > 'z') {
+ for (; first != last; ++first) {
+ if ('a' > *first || *first > 'z') {
return false;
}
}
return true;
}
-template<typename InputIterator>
+template <typename InputIterator>
bool isUppercase(InputIterator first, InputIterator last)
{
- if(first == last) {
+ if (first == last) {
return false;
}
- for(; first != last; ++first) {
- if('A' > *first || *first > 'Z') {
+ for (; first != last; ++first) {
+ if ('A' > *first || *first > 'Z') {
return false;
}
}
@@ -440,26 +444,27 @@ std::string toString(const std::shared_ptr<BinaryStream>& binaryStream);
void* allocateAlignedMemory(size_t alignment, size_t size);
#endif // HAVE_POSIX_MEMALIGN
-std::pair<std::string, uint16_t>
-getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len);
+Endpoint getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len);
std::string htmlEscape(const std::string& src);
// Joins path element specified in [first, last). If ".." is found,
// it eats the previous element if it exists. If "." is found, it
// is just ignored and it is not appeared in the result.
-template<typename InputIterator>
+template <typename InputIterator>
std::string joinPath(InputIterator first, InputIterator last)
{
std::vector<std::string> elements;
- for(;first != last; ++first) {
- if(*first == "..") {
- if(!elements.empty()) {
+ for (; first != last; ++first) {
+ if (*first == "..") {
+ if (!elements.empty()) {
elements.pop_back();
}
- } else if(*first == ".") {
+ }
+ else if (*first == ".") {
// do nothing
- } else {
+ }
+ else {
elements.push_back(*first);
}
}
@@ -468,127 +473,109 @@ std::string joinPath(InputIterator first, InputIterator last)
// Parses INDEX=PATH format string. INDEX must be an unsigned
// integer.
-std::pair<size_t, std::string>
-parseIndexPath(const std::string& line);
+std::pair<size_t, std::string> parseIndexPath(const std::string& line);
-std::vector<std::pair<size_t, std::string> > createIndexPaths(std::istream& i);
+std::vector<std::pair<size_t, std::string>> createIndexPaths(std::istream& i);
/**
* Take a string [first, last) which is a delimited list and add its
* elements into result as iterator pair. result is stored in out.
*/
-template<typename InputIterator, typename OutputIterator>
-OutputIterator splitIter
-(InputIterator first,
- InputIterator last,
- OutputIterator out,
- char delim,
- bool doStrip = false,
- bool allowEmpty = false)
+template <typename InputIterator, typename OutputIterator>
+OutputIterator splitIter(InputIterator first, InputIterator last,
+ OutputIterator out, char delim, bool doStrip = false,
+ bool allowEmpty = false)
{
- for(InputIterator i = first; i != last;) {
+ for (InputIterator i = first; i != last;) {
InputIterator j = std::find(i, last, delim);
std::pair<InputIterator, InputIterator> p(i, j);
- if(doStrip) {
+ if (doStrip) {
p = stripIter(i, j);
}
- if(allowEmpty || p.first != p.second) {
+ if (allowEmpty || p.first != p.second) {
*out++ = p;
}
i = j;
- if(j != last) {
+ if (j != last) {
++i;
}
}
- if(allowEmpty &&
- (first == last || *(last-1) == delim)) {
+ if (allowEmpty && (first == last || *(last - 1) == delim)) {
*out++ = std::make_pair(last, last);
}
return out;
}
-template<typename InputIterator, typename OutputIterator>
-OutputIterator splitIterM
-(InputIterator first,
- InputIterator last,
- OutputIterator out,
- const char* delims,
- bool doStrip = false,
- bool allowEmpty = false)
+template <typename InputIterator, typename OutputIterator>
+OutputIterator splitIterM(InputIterator first, InputIterator last,
+ OutputIterator out, const char* delims,
+ bool doStrip = false, bool allowEmpty = false)
{
size_t numDelims = strlen(delims);
- const char* dlast = delims+numDelims;
- for(InputIterator i = first; i != last;) {
+ const char* dlast = delims + numDelims;
+ for (InputIterator i = first; i != last;) {
InputIterator j = i;
- for(; j != last && std::find(delims, dlast, *j) == dlast; ++j);
+ for (; j != last && std::find(delims, dlast, *j) == dlast; ++j)
+ ;
std::pair<InputIterator, InputIterator> p(i, j);
- if(doStrip) {
+ if (doStrip) {
p = stripIter(i, j);
}
- if(allowEmpty || p.first != p.second) {
+ if (allowEmpty || p.first != p.second) {
*out++ = p;
}
i = j;
- if(j != last) {
+ if (j != last) {
++i;
}
}
- if(allowEmpty &&
- (first == last ||
- std::find(delims, dlast, *(last-1)) != dlast)) {
+ if (allowEmpty &&
+ (first == last || std::find(delims, dlast, *(last - 1)) != dlast)) {
*out++ = std::make_pair(last, last);
}
return out;
}
-template<typename InputIterator, typename OutputIterator>
-OutputIterator split
-(InputIterator first,
- InputIterator last,
- OutputIterator out,
- char delim,
- bool doStrip = false,
- bool allowEmpty = false)
+template <typename InputIterator, typename OutputIterator>
+OutputIterator split(InputIterator first, InputIterator last,
+ OutputIterator out, char delim, bool doStrip = false,
+ bool allowEmpty = false)
{
- for(InputIterator i = first; i != last;) {
+ for (InputIterator i = first; i != last;) {
InputIterator j = std::find(i, last, delim);
std::pair<InputIterator, InputIterator> p(i, j);
- if(doStrip) {
+ if (doStrip) {
p = stripIter(i, j);
}
- if(allowEmpty || p.first != p.second) {
+ if (allowEmpty || p.first != p.second) {
*out++ = std::string(p.first, p.second);
}
i = j;
- if(j != last) {
+ if (j != last) {
++i;
}
}
- if(allowEmpty &&
- (first == last || *(last-1) == delim)) {
+ if (allowEmpty && (first == last || *(last - 1) == delim)) {
*out++ = std::string(last, last);
}
return out;
}
-template<typename InputIterator1, typename InputIterator2>
-bool streq
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+bool streq(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
+ InputIterator2 last2)
{
- if(last1-first1 != last2-first2) {
+ if (last1 - first1 != last2 - first2) {
return false;
}
return std::equal(first1, last1, first2);
}
-template<typename InputIterator>
+template <typename InputIterator>
bool streq(InputIterator first, InputIterator last, const char* b)
{
- for(; first != last && *b != '\0'; ++first, ++b) {
- if(*first != *b) {
+ for (; first != last && *b != '\0'; ++first, ++b) {
+ if (*first != *b) {
return false;
}
}
@@ -598,45 +585,39 @@ bool streq(InputIterator first, InputIterator last, const char* b)
struct CaseCmp {
bool operator()(char lhs, char rhs) const
{
- if('A' <= lhs && lhs <= 'Z') {
- lhs += 'a'-'A';
+ if ('A' <= lhs && lhs <= 'Z') {
+ lhs += 'a' - 'A';
}
- if('A' <= rhs && rhs <= 'Z') {
- rhs += 'a'-'A';
+ if ('A' <= rhs && rhs <= 'Z') {
+ rhs += 'a' - 'A';
}
return lhs == rhs;
}
};
-template<typename InputIterator1, typename InputIterator2>
-InputIterator1 strifind
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+InputIterator1 strifind(InputIterator1 first1, InputIterator1 last1,
+ InputIterator2 first2, InputIterator2 last2)
{
return std::search(first1, last1, first2, last2, CaseCmp());
}
-template<typename InputIterator1, typename InputIterator2>
-bool strieq
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+bool strieq(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
+ InputIterator2 last2)
{
- if(last1-first1 != last2-first2) {
+ if (last1 - first1 != last2 - first2) {
return false;
}
return std::equal(first1, last1, first2, CaseCmp());
}
-template<typename InputIterator>
+template <typename InputIterator>
bool strieq(InputIterator first, InputIterator last, const char* b)
{
CaseCmp cmp;
- for(; first != last && *b != '\0'; ++first, ++b) {
- if(!cmp(*first, *b)) {
+ for (; first != last && *b != '\0'; ++first, ++b) {
+ if (!cmp(*first, *b)) {
return false;
}
}
@@ -646,24 +627,21 @@ bool strieq(InputIterator first, InputIterator last, const char* b)
bool strieq(const std::string& a, const char* b);
bool strieq(const std::string& a, const std::string& b);
-template<typename InputIterator1, typename InputIterator2>
-bool startsWith
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+bool startsWith(InputIterator1 first1, InputIterator1 last1,
+ InputIterator2 first2, InputIterator2 last2)
{
- if(last1-first1 < last2-first2) {
+ if (last1 - first1 < last2 - first2) {
return false;
}
return std::equal(first2, last2, first1);
}
-template<typename InputIterator>
+template <typename InputIterator>
bool startsWith(InputIterator first, InputIterator last, const char* b)
{
- for(; first != last && *b != '\0'; ++first, ++b) {
- if(*first != *b) {
+ for (; first != last && *b != '\0'; ++first, ++b) {
+ if (*first != *b) {
return false;
}
}
@@ -673,25 +651,22 @@ bool startsWith(InputIterator first, InputIterator last, const char* b)
bool startsWith(const std::string& a, const char* b);
bool startsWith(const std::string& a, const std::string& b);
-template<typename InputIterator1, typename InputIterator2>
-bool istartsWith
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+bool istartsWith(InputIterator1 first1, InputIterator1 last1,
+ InputIterator2 first2, InputIterator2 last2)
{
- if(last1-first1 < last2-first2) {
+ if (last1 - first1 < last2 - first2) {
return false;
}
return std::equal(first2, last2, first1, CaseCmp());
}
-template<typename InputIterator>
+template <typename InputIterator>
bool istartsWith(InputIterator first, InputIterator last, const char* b)
{
CaseCmp cmp;
- for(; first != last && *b != '\0'; ++first, ++b) {
- if(!cmp(*first, *b)) {
+ for (; first != last && *b != '\0'; ++first, ++b) {
+ if (!cmp(*first, *b)) {
return false;
}
}
@@ -699,41 +674,36 @@ bool istartsWith(InputIterator first, InputIterator last, const char* b)
}
bool istartsWith(const std::string& a, const char* b);
+bool istartsWith(const std::string& a, const std::string& b);
-template<typename InputIterator1, typename InputIterator2>
-bool endsWith
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+bool endsWith(InputIterator1 first1, InputIterator1 last1,
+ InputIterator2 first2, InputIterator2 last2)
{
- if(last1-first1 < last2-first2) {
+ if (last1 - first1 < last2 - first2) {
return false;
}
- return std::equal(first2, last2, last1-(last2-first2));
+ return std::equal(first2, last2, last1 - (last2 - first2));
}
bool endsWith(const std::string& a, const char* b);
bool endsWith(const std::string& a, const std::string& b);
-template<typename InputIterator1, typename InputIterator2>
-bool iendsWith
-(InputIterator1 first1,
- InputIterator1 last1,
- InputIterator2 first2,
- InputIterator2 last2)
+template <typename InputIterator1, typename InputIterator2>
+bool iendsWith(InputIterator1 first1, InputIterator1 last1,
+ InputIterator2 first2, InputIterator2 last2)
{
- if(last1-first1 < last2-first2) {
+ if (last1 - first1 < last2 - first2) {
return false;
}
- return std::equal(first2, last2, last1-(last2-first2), CaseCmp());
+ return std::equal(first2, last2, last1 - (last2 - first2), CaseCmp());
}
bool iendsWith(const std::string& a, const char* b);
bool iendsWith(const std::string& a, const std::string& b);
// Returns true if strcmp(a, b) < 0
-bool strless(const char* a, const char *b);
+bool strless(const char* a, const char* b);
void generateRandomData(unsigned char* data, size_t length);
@@ -741,8 +711,8 @@ void generateRandomData(unsigned char* data, size_t length);
// existing file is overwritten. Otherwise, this function doesn't do
// nothing. If data is saved successfully, return true. Otherwise
// returns false.
-bool saveAs
-(const std::string& filename, const std::string& data, bool overwrite=false);
+bool saveAs(const std::string& filename, const std::string& data,
+ bool overwrite = false);
// Prepend dir to relPath. If dir is empty, it prepends "." to relPath.
//
@@ -783,17 +753,16 @@ std::string escapePath(const std::string& s);
// of them is not valid numeric address, then returns false. bits is
// prefix bits. If bits is out of range, then bits is set to the
// length of binary representation of the address*8.
-bool inSameCidrBlock
-(const std::string& ip1, const std::string& ip2, size_t bits);
+bool inSameCidrBlock(const std::string& ip1, const std::string& ip2,
+ size_t bits);
// No throw
-void executeHookByOptName
-(const std::shared_ptr<RequestGroup>& group, const Option* option,
- PrefPtr pref);
+void executeHookByOptName(const std::shared_ptr<RequestGroup>& group,
+ const Option* option, PrefPtr pref);
// No throw
-void executeHookByOptName
-(const RequestGroup* group, const Option* option, PrefPtr pref);
+void executeHookByOptName(const RequestGroup* group, const Option* option,
+ PrefPtr pref);
std::string createSafePath(const std::string& dir, const std::string& filename);
@@ -814,49 +783,46 @@ std::string safeStrerror(int errNum);
// pair of iterator which can use as first parameter of next call of
// this function, and true. If no name is found, returns the pair of
// last and false.
-template<typename Iterator>
-std::pair<Iterator, bool>
-nextParam
-(std::string& name,
- std::string& value,
- Iterator first,
- Iterator last,
- char delim)
+template <typename Iterator>
+std::pair<Iterator, bool> nextParam(std::string& name, std::string& value,
+ Iterator first, Iterator last, char delim)
{
Iterator end = last;
- while(first != end) {
+ while (first != end) {
last = first;
Iterator parmnameFirst = first;
Iterator parmnameLast = first;
bool eqFound = false;
- for(; last != end; ++last) {
- if(*last == delim) {
+ for (; last != end; ++last) {
+ if (*last == delim) {
break;
- } else if(!eqFound && *last == '=') {
+ }
+ else if (!eqFound && *last == '=') {
eqFound = true;
parmnameFirst = first;
parmnameLast = last;
}
}
- std::pair<std::string::const_iterator,
- std::string::const_iterator> namep = std::make_pair(last, last);
- std::pair<std::string::const_iterator,
- std::string::const_iterator> valuep = std::make_pair(last, last);
- if(parmnameFirst == parmnameLast) {
- if(!eqFound) {
+ std::pair<std::string::const_iterator, std::string::const_iterator> namep =
+ std::make_pair(last, last);
+ std::pair<std::string::const_iterator, std::string::const_iterator> valuep =
+ std::make_pair(last, last);
+ if (parmnameFirst == parmnameLast) {
+ if (!eqFound) {
parmnameFirst = first;
parmnameLast = last;
namep = stripIter(parmnameFirst, parmnameLast);
}
- } else {
- first = parmnameLast+1;
+ }
+ else {
+ first = parmnameLast + 1;
namep = stripIter(parmnameFirst, parmnameLast);
valuep = stripIter(first, last);
}
- if(last != end) {
+ if (last != end) {
++last;
}
- if(namep.first != namep.second) {
+ if (namep.first != namep.second) {
name.assign(namep.first, namep.second);
value.assign(valuep.first, valuep.second);
return std::make_pair(last, true);
@@ -866,8 +832,7 @@ nextParam
return std::make_pair(end, false);
}
-template<typename T>
-std::shared_ptr<T> copy(const std::shared_ptr<T>& a)
+template <typename T> std::shared_ptr<T> copy(const std::shared_ptr<T>& a)
{
return std::make_shared<T>(*a.get());
}
@@ -890,6 +855,18 @@ bool tlsHostnameMatch(const std::string& pattern, const std::string& hostname);
TLSVersion toTLSVersion(const std::string& ver);
#endif // ENABLE_SSL
+#ifdef __MINGW32__
+// Formats error message for error code errNum, which is the return
+// value of GetLastError(). On error, this function returns empty
+// string.
+std::string formatLastError(int errNum);
+#endif // __MINGW32__
+
+// Sets file descriptor file FD_CLOEXEC to |fd|. This function is
+// noop for Mingw32 build, since we disable inheritance in
+// CreateProcess call.
+void make_fd_cloexec(int fd);
+
} // namespace util
} // namespace aria2