Update to 1.11.0-beta1
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h> /* required for tolower() */
|
||||
#include <sstream>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <errno.h> // required by vsnprintf implementation for MSVC
|
||||
@@ -61,7 +62,7 @@ int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
|
||||
{
|
||||
ptrdiff_t diff = last - str;
|
||||
if (diff < 0) return 0;
|
||||
return min((int)diff, vsnprintf(str, diff + 1, format, ap));
|
||||
return std::min(static_cast<int>(diff), vsnprintf(str, diff + 1, format, ap));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,18 +185,11 @@ void str_fix_scc_encoded(char *str, const char *last)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?' (if not ignored)
|
||||
* @param str the string to validate
|
||||
* @param last the last valid character of str
|
||||
* @param settings the settings for the string validation.
|
||||
*/
|
||||
void str_validate(char *str, const char *last, StringValidationSettings settings)
|
||||
template <class T>
|
||||
static void str_validate(T &dst, const char *str, const char *last, StringValidationSettings settings)
|
||||
{
|
||||
/* Assume the ABSOLUTE WORST to be in str as it comes from the outside. */
|
||||
|
||||
char *dst = str;
|
||||
while (str <= last && *str != '\0') {
|
||||
size_t len = Utf8EncodedCharLen(*str);
|
||||
/* If the character is unknown, i.e. encoded length is 0
|
||||
@@ -219,7 +213,7 @@ void str_validate(char *str, const char *last, StringValidationSettings settings
|
||||
do {
|
||||
*dst++ = *str++;
|
||||
} while (--len != 0);
|
||||
} else if ((settings & SVS_ALLOW_NEWLINE) != 0 && c == '\n') {
|
||||
} else if ((settings & SVS_ALLOW_NEWLINE) != 0 && c == '\n') {
|
||||
*dst++ = *str++;
|
||||
} else {
|
||||
if ((settings & SVS_ALLOW_NEWLINE) != 0 && c == '\r' && str[1] == '\n') {
|
||||
@@ -231,10 +225,40 @@ void str_validate(char *str, const char *last, StringValidationSettings settings
|
||||
if ((settings & SVS_REPLACE_WITH_QUESTION_MARK) != 0) *dst++ = '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?' (if not ignored)
|
||||
* @param str the string to validate
|
||||
* @param last the last valid character of str
|
||||
* @param settings the settings for the string validation.
|
||||
*/
|
||||
void str_validate(char *str, const char *last, StringValidationSettings settings)
|
||||
{
|
||||
char *dst = str;
|
||||
str_validate(dst, str, last, settings);
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?' (if not ignored)
|
||||
* @param str the string to validate
|
||||
* @param settings the settings for the string validation.
|
||||
*/
|
||||
std::string str_validate(const std::string &str, StringValidationSettings settings)
|
||||
{
|
||||
auto buf = str.data();
|
||||
auto last = buf + str.size();
|
||||
|
||||
std::ostringstream dst;
|
||||
std::ostreambuf_iterator<char> dst_iter(dst);
|
||||
str_validate(dst_iter, buf, last, settings);
|
||||
|
||||
return dst.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?'.
|
||||
@@ -338,6 +362,17 @@ bool strtolower(char *str)
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool strtolower(std::string &str, std::string::size_type offs)
|
||||
{
|
||||
bool changed = false;
|
||||
for (auto ch = str.begin() + offs; ch != str.end(); ++ch) {
|
||||
auto new_ch = static_cast<char>(tolower(static_cast<unsigned char>(*ch)));
|
||||
changed |= new_ch != *ch;
|
||||
*ch = new_ch;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only allow certain keys. You can define the filter to be used. This makes
|
||||
* sure no invalid keys can get into an editbox, like BELL.
|
||||
@@ -479,11 +514,13 @@ size_t Utf8Decode(WChar *c, const char *s)
|
||||
|
||||
/**
|
||||
* Encode a unicode character and place it in the buffer.
|
||||
* @tparam T Type of the buffer.
|
||||
* @param buf Buffer to place character.
|
||||
* @param c Unicode character to encode.
|
||||
* @return Number of characters in the encoded sequence.
|
||||
*/
|
||||
size_t Utf8Encode(char *buf, WChar c)
|
||||
template <class T>
|
||||
inline size_t Utf8Encode(T buf, WChar c)
|
||||
{
|
||||
if (c < 0x80) {
|
||||
*buf = c;
|
||||
@@ -510,6 +547,16 @@ size_t Utf8Encode(char *buf, WChar c)
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t Utf8Encode(char *buf, WChar c)
|
||||
{
|
||||
return Utf8Encode<char *>(buf, c);
|
||||
}
|
||||
|
||||
size_t Utf8Encode(std::ostreambuf_iterator<char> &buf, WChar c)
|
||||
{
|
||||
return Utf8Encode<std::ostreambuf_iterator<char> &>(buf, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Properly terminate an UTF8 string to some maximum length
|
||||
* @param s string to check if it needs additional trimming
|
||||
@@ -583,7 +630,7 @@ int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
|
||||
}
|
||||
|
||||
#ifdef WITH_ICU_I18N
|
||||
if (_current_collator != nullptr) {
|
||||
if (_current_collator) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int result = _current_collator->compareUTF8(s1, s2, status);
|
||||
if (U_SUCCESS(status)) return result;
|
||||
|
||||
Reference in New Issue
Block a user