Initial revision of lua 'doc' function
This commit is contained in:
@@ -142,6 +142,28 @@ StringVec split(const std::string &s, char sep) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::string substr_nocr(const std::string &s, int start, int len) {
|
||||
if ((len > 0) && (s[start + len - 1] == '\r')) {
|
||||
len -= 1;
|
||||
}
|
||||
return s.substr(start, len);
|
||||
}
|
||||
|
||||
StringVec split_lines(const std::string &s) {
|
||||
StringVec result;
|
||||
int start = 0;
|
||||
for (int i = 0; i < int(s.size()); i++) {
|
||||
if (s[i]=='\n') {
|
||||
result.push_back(substr_nocr(s, start, i-start));
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
if (start < int(s.size())) {
|
||||
result.push_back(substr_nocr(s, start, s.size()-start));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string join(const StringVec &strs, const std::string &sep) {
|
||||
if (strs.empty()) return "";
|
||||
std::ostringstream oss;
|
||||
@@ -271,6 +293,12 @@ LuaSourcePtr make_lua_source(const std::string &code) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_lua_comment(const std::string &s) {
|
||||
int start = 0;
|
||||
while ((start < int(s.size())) && ((s[start]==' ') || (s[start]=='\t'))) start++;
|
||||
return s.substr(start, 2) == "--";
|
||||
}
|
||||
|
||||
static std::string get_file_contents(const std::string &fn) {
|
||||
std::ifstream fs(fn);
|
||||
std::stringstream buffer;
|
||||
@@ -329,7 +357,7 @@ std::ostream &operator<<(std::ostream &oss, const util::hex8 &v) {
|
||||
return oss;
|
||||
}
|
||||
|
||||
LuaDefine(unittests_util, "c") {
|
||||
LuaDefine(unittests_util, "", "some unit tests") {
|
||||
// Test the unioning of ID vectors.
|
||||
util::IdVector idv1,idv2;
|
||||
idv1.push_back(1);
|
||||
@@ -358,6 +386,15 @@ LuaDefine(unittests_util, "c") {
|
||||
LuaAssert(L, sv2[2]=="");
|
||||
LuaAssert(L, sv2[3]=="bar");
|
||||
|
||||
// Test the split_lines routine.
|
||||
util::StringVec sv3 = util::split_lines("foo\n\nbar\r\nbaz\r\n\r\n");
|
||||
LuaAssert(L, sv3.size() == 5);
|
||||
LuaAssert(L, sv3[0] == "foo");
|
||||
LuaAssert(L, sv3[1] == "");
|
||||
LuaAssert(L, sv3[2] == "bar");
|
||||
LuaAssert(L, sv3[3] == "baz");
|
||||
LuaAssert(L, sv3[4] == "");
|
||||
|
||||
// Test the repeat string routine.
|
||||
LuaAssertStrEq(L, util::repeat_string("abc", 3), "abcabcabc");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user