diff --git a/assets/HypertextPages/chat.html b/assets/HypertextPages/chat.html
index 809d6b4..61255d5 100644
--- a/assets/HypertextPages/chat.html
+++ b/assets/HypertextPages/chat.html
@@ -1,25 +1,25 @@
-
-
-
-
-
- Веб-Чат
-
-
-
-
-
-
-
-
+
+
+
+
+
+ Веб-Чат
+
+
+
+
+
+
+
+
diff --git a/src/http_server/new_york_transit_line/alotalot.cpp b/src/http_server/new_york_transit_line/alotalot.cpp
index 09b9cbd..517b270 100644
--- a/src/http_server/new_york_transit_line/alotalot.cpp
+++ b/src/http_server/new_york_transit_line/alotalot.cpp
@@ -43,7 +43,7 @@ namespace nytl {
}
bool isSPACE(char ch) {
- return ch == ' ' || ch == '\r' || ch == '\t' || ch == '\r';
+ return ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n';
}
bool isUname(const std::string &str) {
diff --git a/src/http_server/new_york_transit_line/core.h b/src/http_server/new_york_transit_line/core.h
index 46ff468..384bbdc 100644
--- a/src/http_server/new_york_transit_line/core.h
+++ b/src/http_server/new_york_transit_line/core.h
@@ -26,7 +26,8 @@ namespace nytl {
std::vector splitIntoLines(const std::string& str);
std::string concatenateLines(const std::vector& lines);
-
+ void one_part_update_min_start_wsp_non_empty(const std::string& str, bool is_first, size_t& min);
+ std::string one_part_cut_excess_tab(const std::string& str, bool is_first, size_t cut);
void parse_bare_file(const std::string& filename, const std::string& content,
global_elem_set_t& result);
diff --git a/src/http_server/new_york_transit_line/parser.cpp b/src/http_server/new_york_transit_line/parser.cpp
index 6fbf7f3..9fb7b5b 100644
--- a/src/http_server/new_york_transit_line/parser.cpp
+++ b/src/http_server/new_york_transit_line/parser.cpp
@@ -34,54 +34,6 @@ namespace nytl {
return "";
}
- void parse_bare_file(const std::string& filename, const std::string& content,
- global_elem_set_t& result)
- {
- ASSERT(result.count(filename) == 0, "Repeated element " + filename);
- std::vector lines;
- bool had_nw_line = false;
- size_t smallest_tab;
- std::string current_line;
- auto finish = [&]() {
- size_t tab_sz = first_nw_char(current_line);
- if (tab_sz == current_line.size()) {
- if (had_nw_line)
- lines.emplace_back();
- } else {
- if (had_nw_line) {
- if (smallest_tab > tab_sz)
- smallest_tab = tab_sz;
- } else {
- smallest_tab = tab_sz;
- had_nw_line = true;
- }
- lines.push_back(current_line);
- }
- current_line.clear();
- };
- for (char ch: content) {
- if (ch == '\n') {
- finish();
- } else {
- current_line += ch;
- }
- }
- finish();
- while (!lines.empty() && lines.back().empty())
- lines.pop_back();
-
- for (std::string& line: lines) {
- if (!line.empty()) {
- assert(line.size() > smallest_tab);
- line = line.substr(smallest_tab);
- }
- }
- Element& el = result[filename];
- el.parts = {ElementPart{element_part_types::code}};
- std::string lines_cat = concatenateLines(lines);
- el.parts[0].when_code.lines = mv(lines_cat);
- }
-
int peep(ParsingContext &ctx) {
if (ctx.text.size() <= ctx.pos)
return EOFVAL;
@@ -115,7 +67,7 @@ namespace nytl {
}
std::vector splitIntoLines(const std::string &str) {
- std::vector result;
+ std::vector result = {""};
for (char ch: str) {
if (ch == '\n')
result.emplace_back();
@@ -136,9 +88,43 @@ namespace nytl {
return result;
}
+ void one_part_update_min_start_wsp_non_empty(const std::string& str, bool is_first, size_t& min) {
+ std::vector lines = splitIntoLines(str);
+ size_t L = lines.size();
+ for (size_t i = is_first ? 0 : 1; i < L; i++) {
+ size_t first_nw = first_nw_char(lines[i]);
+ if (first_nw < lines[i].size())
+ min = std::min(min, first_nw);
+ }
+ }
+
+ std::string one_part_cut_excess_tab(const std::string& str, bool is_first, size_t cut) {
+ std::vector lines = splitIntoLines(str);
+ size_t L = lines.size();
+ for (size_t i = is_first ? 0 : 1; i < L; i++) {
+ if (!is_space_only(lines[i]))
+ lines[i] = lines[i].substr(cut);
+ }
+ return concatenateLines(lines);
+ }
+
+ void parse_bare_file(const std::string& filename, const std::string& content,
+ global_elem_set_t& result)
+ {
+ ASSERT(result.count(filename) == 0, "Repeated element " + filename);
+ std::string P = clement_lstrip(content);
+ rstrip(P);
+ size_t cut = 9999999999999;
+ one_part_update_min_start_wsp_non_empty(P, true, cut);
+ P = one_part_cut_excess_tab(P, true, cut);
+ Element& el = result[filename];
+ el.parts = {ElementPart{element_part_types::code}};
+ el.parts[0].when_code.lines = mv(P);
+ }
+
void parse_special_file(const std::string& filename, const std::string& content,
std::map& result)
{
- THROW("Don't know how to parse it yet");
+ // THROW("Don't know how to parse it yet");
}
}
diff --git a/src/http_server/nytl_tests/test0.cpp b/src/http_server/nytl_tests/test0.cpp
index 4f0423f..9d930f8 100644
--- a/src/http_server/nytl_tests/test0.cpp
+++ b/src/http_server/nytl_tests/test0.cpp
@@ -11,7 +11,7 @@ int main(int argc, char** argv) {
std::string dir_path = argv[1];
nytl::Templater templater(nytl::TemplaterSettings{nytl::TemplaterDetourRules{dir_path}});
templater.update();
- std::string answer = templater.render("chat", {});
+ std::string answer = templater.render("list-rooms", {});
printf("%s\n<>\n", answer.c_str());
std::string answer2 = templater.render("test", {});
printf("%s\n<>\n", answer.c_str());