mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
comments and some improvements
This commit is contained in:
@@ -16,11 +16,17 @@ bool showTimes = false;
|
||||
std::chrono::high_resolution_clock::time_point start;
|
||||
std::chrono::high_resolution_clock::time_point end;
|
||||
|
||||
std::string wrapText(std::string text, size_t width) {
|
||||
/*
|
||||
* Pārveido teksta rindu tā, lai teksts nepārsniegtu doto
|
||||
* platumu. Pievieno nākamās rindās atstarpi ar platumu kurā sākas pirmās rindas
|
||||
* teksts.
|
||||
* */
|
||||
std::string wrapLine(std::string text, size_t width) {
|
||||
std::string result;
|
||||
size_t currentLineLength = 0;
|
||||
size_t wordStart = 0;
|
||||
|
||||
|
||||
// Nosaka, cik tālu no rindas sākuma atrodas teksts pirmā rindā.
|
||||
size_t preservedSpaceCount = 0;
|
||||
for (size_t i = 0; i < text.length(); ++i) {
|
||||
if (text[i] == '\t') {
|
||||
@@ -37,13 +43,15 @@ std::string wrapText(std::string text, size_t width) {
|
||||
|
||||
for (size_t i = wordStart; i < text.length(); ++i) {
|
||||
if (text[i] == ' ' || i == text.length() - 1) {
|
||||
size_t wordEnd = (i == text.length() - 1) ? i + 1 : i; // Handle the last word
|
||||
size_t wordLength = wordEnd - wordStart;
|
||||
if (currentLineLength + wordLength > width) {
|
||||
result += '\n';
|
||||
result.append(preservedSpaceCount / TABWIDTH, '\t');
|
||||
result.append(preservedSpaceCount % TABWIDTH, ' ');
|
||||
currentLineLength = preservedSpaceCount;
|
||||
// Ja vārds pārsniedz norādīto platumu, pievieno
|
||||
// jaunās rindas simbolu un turpina no iepriekš noteiktā attāluma.
|
||||
size_t wordEnd = (i == text.length() - 1) ? i + 1 : i;
|
||||
size_t wordLength = wordEnd - wordStart;
|
||||
if (currentLineLength + wordLength > width) {
|
||||
result += '\n';
|
||||
result.append(preservedSpaceCount / TABWIDTH, '\t');
|
||||
result.append(preservedSpaceCount % TABWIDTH, ' ');
|
||||
currentLineLength = preservedSpaceCount;
|
||||
}
|
||||
result += text.substr(wordStart, wordLength) + ' ';
|
||||
currentLineLength += wordLength + 1;
|
||||
@@ -53,6 +61,9 @@ std::string wrapText(std::string text, size_t width) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tekstā katram rezervētam tekstvienību simbolam pievieno '\' pirms simbola.
|
||||
*/
|
||||
std::string escapeText(std::string text) {
|
||||
std::stringstream ss;
|
||||
for (auto c: text) {
|
||||
@@ -89,6 +100,10 @@ std::string escapeText(std::string text) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*
|
||||
* Transpilē tekstu jautājumos un metadatos.
|
||||
* Veic leksisko analīzi un parsēšanu.
|
||||
* */
|
||||
Result<ParseInfo> transpile(std::string fileContent) {
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
@@ -125,7 +140,9 @@ Result<ParseInfo> transpile(std::string fileContent) {
|
||||
return {questions};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parāda nomērīta laika sekundes un milisekundes.
|
||||
*/
|
||||
std::string showTime(std::string label) {
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
double_t seconds = (double_t) duration.count() / 1000000;
|
||||
|
||||
Reference in New Issue
Block a user