1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | /*
filename: list_sorter.cpp
- This program opens a textfile pathname passed in as the first command-line
argument; otherwise, it presumes a textfile named 'the_list' located within the
same dir as the executable.
- Upon success, it leaves a sorted textfile pathname passed in as the second
command-line argument; otherwise, it leaves a 'sorted_list' textfile in the same
dir as the executable.
Minimal build & run:
g++ list_sorter.cpp -std=c++14 -o list_sorter && ./list_sorter
*/
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using std::cerr;
using std::equal;
using std::getline;
using std::ifstream;
using std::invalid_argument;
using std::ofstream;
using std::puts;
using std::remove;
using std::sort;
using std::stable_sort;
using std::string;
using std::to_string;
using std::unique;
using std::vector;
/** ensure length of string @c str is <= @c sz count of characters
* @param str
* @param sz the size limit
* @return true if within size limit; throws @c invalid_argument otherwise
*/
bool chk_str_len(std::string const& str, std::size_t const sz)
{
if (str.length() > sz)
// NOTE: could use std::format here; if ever moving to a higher C++ std
throw invalid_argument{str.substr(0, sz) + "...\n length is beyond " +
to_string(sz) + "char limit"};
return true;
}
/** ensure string @c str 's chars are within valid ASCII character range values
* [32 to 127]
* @param str
* @return true if all chars within range; throws @c invalid_argument otherwise
*/
bool chk_ascii_rng(std::string const& str)
{
for (auto const ch : str) {
auto const val = static_cast<int>(ch);
if (val < 32 || val > 127)
// NOTE: could use std::format here; if ever moving to a higher C++ std
throw invalid_argument{str + " ;\n ' " + string{ch} + " ' : (" +
to_string(val) +
") char outside of valid ASCII range"};
}
return true;
}
/** perform case-insensitive comparison on two strings
* @param str1
* @param str2
* @return true if strings are otherwise identical, apart from casing
*/
bool lower_compare(std::string const& str1, std::string const& str2)
{
return equal(
str1.cbegin(), str1.cend(), str2.cbegin(), str2.cend(),
[](auto const a, auto const b) { return tolower(a) == tolower(b); });
}
int main(int argc, char* argv[])
{
puts("reading the list...");
ifstream ifs;
if (argc > 1)
ifs.open(argv[1]);
else
ifs.open("the_list");
vector<string> list;
for (string line; getline(ifs, line);)
list.push_back(line);
ifs.close();
puts("cleaning the list...");
for (auto& line : list) {
static vector<char> const rm_chars{'>', '<', '>'};
for (auto const ch : rm_chars) {
line.erase(remove(line.begin(), line.end(), ch), line.cend());
}
try {
chk_str_len(line, 120);
chk_ascii_rng(line);
} catch (invalid_argument const& e) {
cerr << e.what() << "\n ...list entry ignored\n";
continue;
}
}
puts("sorting the list by alpha...");
sort(list.begin(), list.end());
puts("sorting the list by size...");
stable_sort(list.begin(), list.end(),
[](auto const& a, auto const& b) { return a.size() < b.size(); });
puts("removing list duplicates...");
list.erase(unique(list.begin(), list.end(), lower_compare), list.cend());
puts("titlecasing the list...");
for (auto& line : list) { // For each line in the list,
line[0] = toupper(line[0]); // transform first char to upper case.
for (auto& ch : line) { // For each char in the line,
if (*(&ch - sizeof(char)) == ' ') // if previous char was a space,
ch = toupper(ch); // transform curr char to upper case.
}
}
puts("writing sorted list...");
ofstream ofs;
if (argc > 2)
ofs.open(argv[2]);
else
ofs.open("sorted_list");
for (auto const& line : list)
ofs << '>' << line << '\n';
ofs << "\n>No Further Description Of The Attackers Has Been Published.\n";
ofs.close();
}
// version 1.4
// written July 2025 by Anon
|
THE LIST:
https://rentry.co/anything_but_niggers