Klammerset: the @@@klammerset construct, its search path, and const correctness
The @@@klammerset system command formally declares a klammerset — a named, logically related group of klammer definitions — with an operative, idempotent declaration (:requires and :files load in order at the declaration point, relative to the declaring file). A bare symbol given to ktext -k, kdesc --input, or :requires resolves to x/x.k on the search path: the document's directory, then KLAMMERTEXT_KLAMMERSETS, then KLAMMERTEXT_HOME; kdesc --klammerset lists the available sets. sks/sks.k is the first declared klammerset, so `-k sks` loads the SKS by name. The engine's lookup classes were renamed *_set → *_registry to keep the two concepts apart, and the whole C++ tree now follows standard const-correctness conventions. tst/ gains klammerset_test.sh (18 cases). (from dev 64b1abf23e56)
This commit is contained in:
25
mac/util.cpp
25
mac/util.cpp
@@ -111,7 +111,7 @@ std::string regex_escape(const std::string& s)
|
||||
return result;
|
||||
}
|
||||
|
||||
strings_t regex_split(std::string s, std::regex re, bool trim_parts)
|
||||
strings_t regex_split(const std::string& s, const std::regex& re, bool trim_parts)
|
||||
{
|
||||
strings_t result = {};
|
||||
if (s.size() == 0) {
|
||||
@@ -134,17 +134,17 @@ strings_t word_split(const std::string& s)
|
||||
return regex_split(s, std::regex("\\s+"));
|
||||
}
|
||||
|
||||
bool is_in(std::string s, strings_t v)
|
||||
bool is_in(const std::string& s, const strings_t& v)
|
||||
{
|
||||
return find(v.begin(), v.end(), s) != v.end();
|
||||
}
|
||||
|
||||
bool is_not_in(std::string s, strings_t v)
|
||||
bool is_not_in(const std::string& s, const strings_t& v)
|
||||
{
|
||||
return find(v.begin(), v.end(), s) == v.end();
|
||||
}
|
||||
|
||||
strings_t find_all(std::string str, std::regex pattern, int match_group)
|
||||
strings_t find_all(const std::string& str, const std::regex& pattern, int match_group)
|
||||
{
|
||||
std::sregex_iterator end {};
|
||||
strings_t result;
|
||||
@@ -153,7 +153,7 @@ strings_t find_all(std::string str, std::regex pattern, int match_group)
|
||||
return result;
|
||||
}
|
||||
|
||||
strings_t find_all(std::string str, std::string pattern, int match_group)
|
||||
strings_t find_all(const std::string& str, const std::string& pattern, int match_group)
|
||||
{
|
||||
return find_all(str, std::regex(pattern), match_group);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ strings_t split_into_paragraphs(const std::string& s)
|
||||
|
||||
}
|
||||
|
||||
std::string add_margin(std::string s, unsigned int margin_size)
|
||||
std::string add_margin(const std::string& s, unsigned int margin_size)
|
||||
{
|
||||
auto margin = std::string(margin_size, ' ');
|
||||
return trim_right(
|
||||
@@ -297,7 +297,7 @@ std::string to_be(int count, bool present)
|
||||
return result;
|
||||
}
|
||||
|
||||
int max_length(strings_t ss)
|
||||
int max_length(const strings_t& ss)
|
||||
{
|
||||
size_t result = 0;
|
||||
for_each(ss.begin(), ss.end(),
|
||||
@@ -349,7 +349,7 @@ std::vector<std::pair<std::string, std::string>> environment_variables(bool allo
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string replace_environment_variables(std::string str)
|
||||
std::string replace_environment_variables(const std::string& str)
|
||||
{
|
||||
if (str.find('{') == std::string::npos || str.find('}') == std::string::npos) {
|
||||
return str;
|
||||
@@ -398,10 +398,10 @@ std::string abbrev(const std::string& s, unsigned int max_length, bool remove_ne
|
||||
return result;
|
||||
}
|
||||
|
||||
void remove_element(std::vector<std::string>& ss, std::string removed)
|
||||
void remove_element(std::vector<std::string>& ss, const std::string& removed)
|
||||
{
|
||||
ss.erase(std::remove_if(ss.begin(), ss.end(),
|
||||
[&removed](std::string s) { return s == removed; }),
|
||||
[&removed](const std::string& s) { return s == removed; }),
|
||||
ss.end());
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ std::string display_string(const std::string& s, unsigned int width, bool replac
|
||||
return result;
|
||||
}
|
||||
|
||||
std::pair<std::string,std::string> extract_parameter_type(std::string parameter_name)
|
||||
std::pair<std::string,std::string> extract_parameter_type(const std::string& parameter_name)
|
||||
{
|
||||
std::regex name_pat { R"((\w+)\.(\w+))" };
|
||||
std::smatch match {};
|
||||
@@ -487,7 +487,8 @@ std::string get_env_var(const std::string& var) {
|
||||
return val ? std::string(val) : "";
|
||||
}
|
||||
|
||||
std::string freplace(const std::string src, std::regex pattern, std::function<std::string(std::smatch)> func)
|
||||
std::string freplace(const std::string& src, const std::regex& pattern,
|
||||
const std::function<std::string(std::smatch)>& func)
|
||||
{
|
||||
std::string result {};
|
||||
std::smatch match;
|
||||
|
||||
Reference in New Issue
Block a user