mirror of
http://git.sesse.net/plocate
synced 2025-10-06 03:02:39 +02:00
Fix a warning with -Wvla (MB_CUR_MAX is not a compile-time constant).
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "unique_sort.h"
|
#include "unique_sort.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <memory>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
@@ -171,6 +172,7 @@ void parse_trigrams_ignore_case(const string &needle, vector<TrigramDisjunction>
|
|||||||
// involving ICU or the likes.
|
// involving ICU or the likes.
|
||||||
mbtowc(nullptr, 0, 0);
|
mbtowc(nullptr, 0, 0);
|
||||||
const char *ptr = needle.c_str();
|
const char *ptr = needle.c_str();
|
||||||
|
unique_ptr<char[]> buf(new char[MB_CUR_MAX]);
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
wchar_t ch;
|
wchar_t ch;
|
||||||
int ret = mbtowc(&ch, ptr, strlen(ptr));
|
int ret = mbtowc(&ch, ptr, strlen(ptr));
|
||||||
@@ -179,17 +181,16 @@ void parse_trigrams_ignore_case(const string &needle, vector<TrigramDisjunction>
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[MB_CUR_MAX];
|
|
||||||
vector<string> alt;
|
vector<string> alt;
|
||||||
alt.push_back(string(ptr, ret));
|
alt.push_back(string(ptr, ret));
|
||||||
ptr += ret;
|
ptr += ret;
|
||||||
if (towlower(ch) != wint_t(ch)) {
|
if (towlower(ch) != wint_t(ch)) {
|
||||||
ret = wctomb(buf, towlower(ch));
|
ret = wctomb(buf.get(), towlower(ch));
|
||||||
alt.push_back(string(buf, ret));
|
alt.push_back(string(buf.get(), ret));
|
||||||
}
|
}
|
||||||
if (towupper(ch) != wint_t(ch) && towupper(ch) != towlower(ch)) {
|
if (towupper(ch) != wint_t(ch) && towupper(ch) != towlower(ch)) {
|
||||||
ret = wctomb(buf, towupper(ch));
|
ret = wctomb(buf.get(), towupper(ch));
|
||||||
alt.push_back(string(buf, ret));
|
alt.push_back(string(buf.get(), ret));
|
||||||
}
|
}
|
||||||
alternatives_for_cp.push_back(move(alt));
|
alternatives_for_cp.push_back(move(alt));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user