// Find the end of line and strip the leading/trailing spaces
string::const_iterator J;
I += Length + 1;
- for (; isspace(*I) != 0 && I < Message.end(); ++I);
+ for (; isspace_ascii(*I) != 0 && I < Message.end(); ++I);
for (J = I; *J != '\n' && J < Message.end(); ++J);
- for (; J > I && isspace(J[-1]) != 0; --J);
+ for (; J > I && isspace_ascii(J[-1]) != 0; --J);
return string(I,J);
}
return false;
// No data
+#if EAGAIN != EWOULDBLOCK
if (Res < 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
+#else
+ if (Res < 0 && errno == EAGAIN)
+#endif
return true;
if (Res < 0)
return false;
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
- return 0;
+ return -1;
}
/*}}}*/
// Hex2Num - Convert a long hex number into a buffer /*{{{*/
// ---------------------------------------------------------------------
/* The length of the buffer must be exactly 1/2 the length of the string. */
bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length)
+{
+ return Hex2Num(APT::StringView(Str), Num, Length);
+}
+
+bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length)
{
if (Str.length() != Length*2)
return false;
// Convert each digit. We store it in the same order as the string
int J = 0;
- for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2)
+ for (auto I = Str.begin(); I != Str.end();J++, I += 2)
{
- if (isxdigit(*I) == 0 || isxdigit(I[1]) == 0)
+ int first_half = HexDigit(I[0]);
+ int second_half;
+ if (first_half < 0)
return false;
- Num[J] = HexDigit(I[0]) << 4;
- Num[J] += HexDigit(I[1]);
+ second_half = HexDigit(I[1]);
+ if (second_half < 0)
+ return false;
+ Num[J] = first_half << 4;
+ Num[J] += second_half;
}
return true;
return VerStr.substr(i+1);
}
/*}}}*/
+
// tolower_ascii - tolower() function that ignores the locale /*{{{*/
// ---------------------------------------------------------------------
/* This little function is the most called method we have and tries
therefore to do the absolut minimum - and is notable faster than
standard tolower/toupper and as a bonus avoids problems with different
locales - we only operate on ascii chars anyway. */
+#undef tolower_ascii
+int tolower_ascii(int const c) APT_CONST APT_COLD;
int tolower_ascii(int const c)
{
- if (c >= 'A' && c <= 'Z')
- return c + 32;
- return c;
+ return tolower_ascii_inline(c);
}
/*}}}*/
therefore to do the absolut minimum - and is notable faster than
standard isspace() and as a bonus avoids problems with different
locales - we only operate on ascii chars anyway. */
+#undef isspace_ascii
+int isspace_ascii(int const c) APT_CONST APT_COLD;
int isspace_ascii(int const c)
{
- return (c == ' '
- || c == '\f'
- || c == '\n'
- || c == '\r'
- || c == '\t'
- || c == '\v');
+ return isspace_ascii_inline(c);
}
/*}}}*/