19LipsumMiscInlFind(
int count,
const std::string& str,
const std::string& check)
22 while ((pos = str.find(check, pos)) != std::string::npos)
40 return {
"Lorem ipsum dolor sit amet, consectetur adipiscing elit."};
48 char lastLetter =
'\0';
49 for (
const char& letter : str)
62 std::isalnum(
static_cast<unsigned char>(letter))) ||
63 (letter ==
'-' && lastLetter !=
'\n' &&
65 (letter ==
'+' && lastLetter !=
'\n' &&
67 (letter ==
'\'' && lastLetter !=
'\n' && lastLetter !=
' ');
71 if (isWordChar && !inWord)
96 char lastLetter =
'\0';
97 for (
const char& letter : str)
111 if (letter ==
',' || letter ==
';' || letter ==
':' ||
112 letter ==
'.' || letter ==
'?' || letter ==
'!')
116 if (letter ==
'-' && lastLetter !=
'\n')
131 for (
const char& letter : str)
141 if ((letter ==
'.' || letter ==
'?' || letter ==
'!') &&
157 return static_cast<int>(
158 std::count(str.begin(), str.end(),
'\t'));
160 case Format::Markdown:
162 int count = LipsumMiscInlFind(0, str,
"\n\n");
167 int count = LipsumMiscInlFind(0, str,
"<p>");
168 count = LipsumMiscInlFind(count, str,
"<ol>");
169 count = LipsumMiscInlFind(count, str,
"<ul>");
170 count = LipsumMiscInlFind(count, str,
"<h1>");
171 count = LipsumMiscInlFind(count, str,
"<h2>");
172 count = LipsumMiscInlFind(count, str,
"<h3>");
173 count = LipsumMiscInlFind(count, str,
"<h4>");
174 count = LipsumMiscInlFind(count, str,
"<h5>");
175 count = LipsumMiscInlFind(count, str,
"<h6>");
181 "lpsm::CountParagraphs(): invalid format for "
183 static_cast<int>(format));
192 auto plainConvs = [&]() -> std::string
195 "Format is Plain. Attempting conversion...");
197 ret.reserve(str.size());
205 case Format::Markdown:
207 for (
const auto& letter : str)
225 ret += R
"(<?xml version="1.0" encoding="UTF-8"?>)";
231 for (
const auto& letter : str)
248 ret += R
"({"text": ")";
249 for (
const auto& letter : str)
259 "lpsm::ConvertFormat(): Format option ",
260 static_cast<int>(format2),
261 " is out of range.");
277 "lpsm::ConvertFormat(): Unknown route from "
279 static_cast<int>(format1),
281 static_cast<int>(format2));
#define LPSM_VERBOSE_LOG(type,...)
Verbose log messages.
Definition core.hpp:49
Declaration of lipsum::internal.
void LogWarn(LogType type, const Args &... args)
Log a warning.
Definition internal.hpp:126
LIPSUM_API std::string HandleHTMLEntity(char letter, Format format=Format::HTML)
Handle HTML entities.
Definition argvec2.inl:56
This is the main namespace of lipsum-cpp.
LIPSUM_API int CountSentences(const std::string &str)
Count the number of sentences in a string.
Definition misc.inl:127
LIPSUM_API int CountSentenceFragments(const std::string &str)
Count the number of sentence fragments in a string.
Definition misc.inl:88
LIPSUM_API int CountWords(const std::string &str)
Count the number of words in a string.
Definition misc.inl:43
LIPSUM_API std::string ConvertFormat(const std::string &str, Format format1=Format::Plain, Format format2=Format::HTML)
Convert a string between two formats.
Definition misc.inl:190
Format
Types of formats.
Definition misc.hpp:33
LIPSUM_API int CountParagraphs(const std::string &str, Format format=Format::Plain)
Count the number of paragraphs or elements in a string.
Definition misc.inl:151
LIPSUM_API std::string GenerateDefaultLipsumSentence()
Generate the beginning Lorem Ipsum sentence.
Definition misc.inl:38