QOL improvements to docsearch: alphabetize, filter out unittests
This commit is contained in:
@@ -181,10 +181,10 @@ int common_prefix_length(string_view a, string_view b) {
|
||||
bool is_lua_id(string_view str) {
|
||||
if (str.size() == 0) return false;
|
||||
char c=str[0];
|
||||
if ((!ascii_isalpha(c)) && (c!='_')) return false;
|
||||
if (!ascii_isualpha(c)) return false;
|
||||
for (int i = 1; i < int(str.size()); i++) {
|
||||
char c = str[i];
|
||||
if ((!ascii_isalnum(c)) && (c!='_')) return false;
|
||||
if (!ascii_isualnum(c)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -200,15 +200,6 @@ bool is_lua_comment(string_view s) {
|
||||
return s.substr(start, 2) == "--";
|
||||
}
|
||||
|
||||
bool is_lua_function_prototype(string_view s) {
|
||||
int start = 0;
|
||||
while ((start < int(s.size())) && ((s[start]==' ') || (s[start]=='\t'))) start++;
|
||||
s.remove_prefix(start);
|
||||
if (!has_prefix(s, "function")) return false;
|
||||
s.remove_prefix(8);
|
||||
return ((!s.empty()) && (ascii_isspace(s[0])));
|
||||
}
|
||||
|
||||
bool is_whitespace(string_view s) {
|
||||
for (int i = 0; i < int(s.size()); i++) {
|
||||
if (!ascii_isspace(s[i])) {
|
||||
@@ -218,6 +209,46 @@ bool is_whitespace(string_view s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
string_view lua_function_proto_name(string_view s) {
|
||||
// Skip any leading whitespace.
|
||||
read_space(s);
|
||||
|
||||
// Skip over the word 'function'. If it's not there, fail.
|
||||
if (!read_prefix(s, "function")) return string_view();
|
||||
|
||||
// Skip whitespace. If there isn't any, fail.
|
||||
string_view w = read_space(s);
|
||||
if (w.empty()) return string_view();
|
||||
|
||||
// Read the function name
|
||||
string_view work = s;
|
||||
if (read_lua_identifier(work).empty()) return string_view();
|
||||
if (read_prefix(work, ".")) {
|
||||
if (read_lua_identifier(work).empty()) return string_view();
|
||||
}
|
||||
size_t namelen = s.size() - work.size();
|
||||
string_view fullname = s.substr(0, namelen);
|
||||
s.remove_prefix(namelen);
|
||||
|
||||
// Skip whitespace
|
||||
read_space(s);
|
||||
|
||||
// Make sure there's an open parentheses.
|
||||
if (!read_prefix(s, "(")) return string_view();
|
||||
|
||||
// This is where we stop parsing.
|
||||
return fullname;
|
||||
}
|
||||
|
||||
string_view read_space(string_view &source)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while ((pos < source.size()) && ascii_isspace(source[pos])) pos++;
|
||||
string_view result = source.substr(0, pos);
|
||||
source.remove_prefix(pos);
|
||||
return result;
|
||||
}
|
||||
|
||||
string_view read_to_sep(string_view &source, char sep) {
|
||||
size_t pos = source.find(sep);
|
||||
string_view result;
|
||||
@@ -282,7 +313,7 @@ string_view read_nbytes(string_view &source, int nbytes) {
|
||||
return result;
|
||||
}
|
||||
|
||||
string_view read_ascii_identifier(string_view &source) {
|
||||
string_view read_simple_identifier(string_view &source) {
|
||||
size_t len = 0;
|
||||
if ((len < source.size()) && (sv::ascii_isalpha(source[len]))) {
|
||||
len += 1;
|
||||
@@ -295,6 +326,19 @@ string_view read_ascii_identifier(string_view &source) {
|
||||
return result;
|
||||
}
|
||||
|
||||
string_view read_lua_identifier(string_view &source) {
|
||||
size_t len = 0;
|
||||
if ((len < source.size()) && (sv::ascii_isualpha(source[len]))) {
|
||||
len += 1;
|
||||
while ((len < source.size()) && (sv::ascii_isualnum(source[len]))) {
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
string_view result = source.substr(0, len);
|
||||
source.remove_prefix(len);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string_view read_number(string_view &source, bool plus, bool minus, bool dec, bool exp) {
|
||||
const char *p = source.data();
|
||||
const char *l = p + source.size();
|
||||
|
||||
Reference in New Issue
Block a user