338 lines
6.9 KiB
Zig
338 lines
6.9 KiB
Zig
const std = @import("std");
|
|
const rand = std.crypto.random;
|
|
|
|
pub const LOREM_COMMON_P =
|
|
\\Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
|
\\tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
|
\\veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
|
\\commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
|
\\velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
|
\\occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
|
\\mollit anim id est laborum.
|
|
;
|
|
|
|
pub const LOREM_WORDS = [182][]const u8{
|
|
"exercitationem",
|
|
"perferendis",
|
|
"perspiciatis",
|
|
"laborum",
|
|
"eveniet",
|
|
"sunt",
|
|
"iure",
|
|
"nam",
|
|
"nobis",
|
|
"eum",
|
|
"cum",
|
|
"officiis",
|
|
"excepturi",
|
|
"odio",
|
|
"consectetur",
|
|
"quasi",
|
|
"aut",
|
|
"quisquam",
|
|
"vel",
|
|
"eligendi",
|
|
"itaque",
|
|
"non",
|
|
"odit",
|
|
"tempore",
|
|
"quaerat",
|
|
"dignissimos",
|
|
"facilis",
|
|
"neque",
|
|
"nihil",
|
|
"expedita",
|
|
"vitae",
|
|
"vero",
|
|
"ipsum",
|
|
"nisi",
|
|
"animi",
|
|
"cumque",
|
|
"pariatur",
|
|
"velit",
|
|
"modi",
|
|
"natus",
|
|
"iusto",
|
|
"eaque",
|
|
"sequi",
|
|
"illo",
|
|
"sed",
|
|
"ex",
|
|
"et",
|
|
"voluptatibus",
|
|
"tempora",
|
|
"veritatis",
|
|
"ratione",
|
|
"assumenda",
|
|
"incidunt",
|
|
"nostrum",
|
|
"placeat",
|
|
"aliquid",
|
|
"fuga",
|
|
"provident",
|
|
"praesentium",
|
|
"rem",
|
|
"necessitatibus",
|
|
"suscipit",
|
|
"adipisci",
|
|
"quidem",
|
|
"possimus",
|
|
"voluptas",
|
|
"debitis",
|
|
"sint",
|
|
"accusantium",
|
|
"unde",
|
|
"sapiente",
|
|
"voluptate",
|
|
"qui",
|
|
"aspernatur",
|
|
"laudantium",
|
|
"soluta",
|
|
"amet",
|
|
"quo",
|
|
"aliquam",
|
|
"saepe",
|
|
"culpa",
|
|
"libero",
|
|
"ipsa",
|
|
"dicta",
|
|
"reiciendis",
|
|
"nesciunt",
|
|
"doloribus",
|
|
"autem",
|
|
"impedit",
|
|
"minima",
|
|
"maiores",
|
|
"repudiandae",
|
|
"ipsam",
|
|
"obcaecati",
|
|
"ullam",
|
|
"enim",
|
|
"totam",
|
|
"delectus",
|
|
"ducimus",
|
|
"quis",
|
|
"voluptates",
|
|
"dolores",
|
|
"molestiae",
|
|
"harum",
|
|
"dolorem",
|
|
"quia",
|
|
"voluptatem",
|
|
"molestias",
|
|
"magni",
|
|
"distinctio",
|
|
"omnis",
|
|
"illum",
|
|
"dolorum",
|
|
"voluptatum",
|
|
"ea",
|
|
"quas",
|
|
"quam",
|
|
"corporis",
|
|
"quae",
|
|
"blanditiis",
|
|
"atque",
|
|
"deserunt",
|
|
"laboriosam",
|
|
"earum",
|
|
"consequuntur",
|
|
"hic",
|
|
"cupiditate",
|
|
"quibusdam",
|
|
"accusamus",
|
|
"ut",
|
|
"rerum",
|
|
"error",
|
|
"minus",
|
|
"eius",
|
|
"ab",
|
|
"ad",
|
|
"nemo",
|
|
"fugit",
|
|
"officia",
|
|
"at",
|
|
"in",
|
|
"id",
|
|
"quos",
|
|
"reprehenderit",
|
|
"numquam",
|
|
"iste",
|
|
"fugiat",
|
|
"sit",
|
|
"inventore",
|
|
"beatae",
|
|
"repellendus",
|
|
"magnam",
|
|
"recusandae",
|
|
"quod",
|
|
"explicabo",
|
|
"doloremque",
|
|
"aperiam",
|
|
"consequatur",
|
|
"asperiores",
|
|
"commodi",
|
|
"optio",
|
|
"dolor",
|
|
"labore",
|
|
"temporibus",
|
|
"repellat",
|
|
"veniam",
|
|
"architecto",
|
|
"est",
|
|
"esse",
|
|
"mollitia",
|
|
"nulla",
|
|
"a",
|
|
"similique",
|
|
"eos",
|
|
"alias",
|
|
"dolore",
|
|
"tenetur",
|
|
"deleniti",
|
|
"porro",
|
|
"facere",
|
|
"maxime",
|
|
"corrupti",
|
|
};
|
|
|
|
pub const LOREM_COMMON_WORDS = [19][]const u8{
|
|
"lorem",
|
|
"ipsum",
|
|
"dolor",
|
|
"sit",
|
|
"amet",
|
|
"consectetur",
|
|
"adipisicing",
|
|
"elit",
|
|
"sed",
|
|
"do",
|
|
"eiusmod",
|
|
"tempor",
|
|
"incididunt",
|
|
"ut",
|
|
"labore",
|
|
"et",
|
|
"dolore",
|
|
"magna",
|
|
"aliqua",
|
|
};
|
|
|
|
pub fn sentence(allocator: std.mem.Allocator) ![]const u8 {
|
|
const num_sections = rand.intRangeAtMost(u32, 1, 4);
|
|
|
|
var parts = std.ArrayList([]u8){};
|
|
defer {
|
|
for (parts.items) |p| allocator.free(p);
|
|
parts.deinit(allocator);
|
|
}
|
|
|
|
var i: u32 = 0;
|
|
while (i < num_sections) : (i += 1) {
|
|
const num_words = rand.intRangeAtMost(u32, 3, 12);
|
|
|
|
var wds = std.ArrayList([]const u8){};
|
|
defer wds.deinit(allocator);
|
|
try wds.ensureTotalCapacity(allocator, num_words);
|
|
|
|
var j: u32 = 0;
|
|
while (j < num_words) : (j += 1) {
|
|
const idx = rand.intRangeAtMost(usize, 0, LOREM_WORDS.len - 1);
|
|
try wds.append(allocator, LOREM_WORDS[idx]);
|
|
}
|
|
|
|
const section = try std.mem.join(allocator, " ", wds.items);
|
|
try parts.append(allocator, section);
|
|
}
|
|
|
|
const text = try std.mem.join(allocator, ", ", parts.items);
|
|
defer allocator.free(text);
|
|
|
|
var result = try allocator.alloc(u8, text.len + 1);
|
|
if (text.len > 0) {
|
|
result[0] = std.ascii.toUpper(text[0]);
|
|
@memcpy(result[1..text.len], text[1..]);
|
|
}
|
|
result[text.len] = if (rand.boolean()) '.' else '?';
|
|
|
|
return result;
|
|
}
|
|
|
|
pub fn paragraph(allocator: std.mem.Allocator) ![]const u8 {
|
|
const num_sentences = rand.intRangeAtMost(u32, 1, 4);
|
|
var sentences = std.ArrayList([]const u8){};
|
|
defer sentences.deinit(allocator);
|
|
|
|
for (0..num_sentences) |_| {
|
|
try sentences.append(allocator, try sentence(allocator));
|
|
}
|
|
|
|
return try std.mem.join(allocator, ". ", sentences.items);
|
|
}
|
|
|
|
pub fn paragraphs(allocator: std.mem.Allocator, count: u32, random: bool) ![]const u8 {
|
|
var pa = std.ArrayList([]const u8){};
|
|
defer pa.deinit(allocator);
|
|
|
|
if (count == 0) return "";
|
|
|
|
if (random == true) {
|
|
for (0..count) |_| {
|
|
const pg = try paragraph(allocator);
|
|
if (pg.len > 0) {
|
|
try pa.append(allocator, try std.fmt.allocPrint(allocator, "<p>{s}</p>", .{pg}));
|
|
}
|
|
}
|
|
|
|
return try std.mem.join(allocator, "\n", pa.items);
|
|
}
|
|
|
|
const first = try std.fmt.allocPrint(allocator, "<p>{s}</p>", .{LOREM_COMMON_P});
|
|
if (count == 1) {
|
|
return first;
|
|
}
|
|
|
|
const ncount: u32 = count - 1;
|
|
try pa.append(allocator, first);
|
|
|
|
for (0..ncount) |_| {
|
|
const pg = try paragraph(allocator);
|
|
if (pg.len > 0) {
|
|
try pa.append(allocator, try std.fmt.allocPrint(allocator, "<p>{s}</p>", .{pg}));
|
|
}
|
|
}
|
|
|
|
return try std.mem.join(allocator, "\n", pa.items);
|
|
}
|
|
|
|
pub fn words(allocator: std.mem.Allocator, count: u32, random: bool) ![]const u8 {
|
|
var wd = std.ArrayList([]const u8){};
|
|
defer wd.deinit(allocator);
|
|
|
|
if (random == true) {
|
|
for (0..count) |_| {
|
|
const idx = rand.intRangeAtMost(usize, 0, LOREM_COMMON_WORDS.len - 1);
|
|
try wd.append(allocator, LOREM_COMMON_WORDS[idx]);
|
|
}
|
|
return try std.mem.join(allocator, " ", wd.items);
|
|
}
|
|
|
|
var inc: u32 = 0;
|
|
|
|
for (LOREM_COMMON_WORDS) |word| {
|
|
try wd.append(allocator, word);
|
|
inc += 1;
|
|
if (inc >= count or inc >= 20) break;
|
|
}
|
|
|
|
if (count >= 20) {
|
|
const ncount = count - inc;
|
|
|
|
for (0..ncount) |_| {
|
|
const idx = rand.intRangeAtMost(usize, 0, LOREM_COMMON_WORDS.len - 1);
|
|
try wd.append(allocator, LOREM_COMMON_WORDS[idx]);
|
|
}
|
|
}
|
|
|
|
return try std.mem.join(allocator, " ", wd.items);
|
|
}
|