Compare commits
2 commits
6db258f59f
...
8a47f3be5d
Author | SHA1 | Date | |
---|---|---|---|
8a47f3be5d | |||
7b6a7c78d2 |
3 changed files with 42 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ compile_commands.commands.json
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.clangd/
|
.clangd/
|
||||||
.cache/
|
.cache/
|
||||||
|
/objects/
|
||||||
|
|
25
Makefile
25
Makefile
|
@ -1,17 +1,34 @@
|
||||||
COMMON_CXXFLAGS = -Wall -Wextra -Wpedantic -std=c++20
|
COMMON_CXXFLAGS = -Wall -Wextra -Wpedantic -std=c++20 \
|
||||||
|
-Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough \
|
||||||
|
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \
|
||||||
|
-D_GLIBCXX_ASSERTIONS \
|
||||||
|
-fstrict-flex-arrays=3 \
|
||||||
|
-fstack-clash-protection -fstack-protector-strong \
|
||||||
|
-Wl,-z,nodlopen -Wl,-z,noexecstack \
|
||||||
|
-Wl,-z,relro -Wl,-z,now
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
CXXFLAGS = -Og -g ${COMMON_CXXFLAGS}
|
CXXFLAGS = -Og -g ${COMMON_CXXFLAGS}
|
||||||
else
|
else
|
||||||
CXXFLAGS = -O3 ${COMMON_CXXFLAGS}
|
CXXFLAGS = -O2 ${COMMON_CXXFLAGS}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
OBJDIR = objects
|
||||||
|
|
||||||
|
SOURCES = src/main.cpp
|
||||||
|
|
||||||
|
OBJECTS = $(addprefix ${OBJDIR}/,$(patsubst %.cpp,%.cpp.o,${SOURCES}))
|
||||||
|
|
||||||
all: KoreanNumbers
|
all: KoreanNumbers
|
||||||
|
|
||||||
KoreanNumbers: src/main.o
|
KoreanNumbers: ${OBJECTS}
|
||||||
$(CXX) $(CXXFLAGS) -o KoreanNumbers $^
|
$(CXX) $(CXXFLAGS) -o KoreanNumbers $^
|
||||||
|
|
||||||
|
${OBJDIR}/%.cpp.o: %.cpp
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f KoreanNumbers
|
rm -f KoreanNumbers
|
||||||
rm -f src/*.o
|
rm -rf ${OBJDIR}
|
||||||
|
|
31
src/main.cpp
31
src/main.cpp
|
@ -3,7 +3,6 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -60,7 +59,7 @@ void help() {
|
||||||
puts(" [-l | --list] - list \"base\" numbers (can combine with --alt)");
|
puts(" [-l | --list] - list \"base\" numbers (can combine with --alt)");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char8_t* digit_to_kword(int n) {
|
const char8_t* digit_to_kword(unsigned long long n) {
|
||||||
switch(n) {
|
switch(n) {
|
||||||
case 9:
|
case 9:
|
||||||
return gu;
|
return gu;
|
||||||
|
@ -89,6 +88,10 @@ std::u8string value_to_korean(unsigned long long value) {
|
||||||
std::u8string s;
|
std::u8string s;
|
||||||
|
|
||||||
unsigned long long temp;
|
unsigned long long temp;
|
||||||
|
|
||||||
|
bool requires_uc = false;
|
||||||
|
bool requires_man = false;
|
||||||
|
|
||||||
if(temp = (value / 1000000000000) % 10; temp > 0) {
|
if(temp = (value / 1000000000000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
|
@ -98,46 +101,52 @@ std::u8string value_to_korean(unsigned long long value) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(chun);
|
s.append(chun);
|
||||||
|
requires_uc = true;
|
||||||
}
|
}
|
||||||
if(temp = (value / 10000000000) % 10; temp > 0) {
|
if(temp = (value / 10000000000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(bec);
|
s.append(bec);
|
||||||
|
requires_uc = true;
|
||||||
}
|
}
|
||||||
if(temp = (value / 1000000000) % 10; temp > 0) {
|
if(temp = (value / 1000000000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(ship);
|
s.append(ship);
|
||||||
|
requires_uc = true;
|
||||||
}
|
}
|
||||||
if(temp = (value / 100000000) % 10; temp > 0) {
|
if(temp = (value / 100000000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if (temp > 0) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(uc);
|
s.append(uc);
|
||||||
} else if(!s.empty()) {
|
} else if (requires_uc) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
s.push_back(' ');
|
||||||
s.append(il);
|
|
||||||
s.append(uc);
|
s.append(uc);
|
||||||
}
|
}
|
||||||
if(temp = (value / 10000000) % 10; temp > 0) {
|
if(temp = (value / 10000000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(chun);
|
s.append(chun);
|
||||||
|
requires_man = true;
|
||||||
}
|
}
|
||||||
if(temp = (value / 1000000) % 10; temp > 0) {
|
if(temp = (value / 1000000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(bec);
|
s.append(bec);
|
||||||
|
requires_man = true;
|
||||||
}
|
}
|
||||||
if(temp = (value / 100000) % 10; temp > 0) {
|
if(temp = (value / 100000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(ship);
|
s.append(ship);
|
||||||
|
requires_man = true;
|
||||||
}
|
}
|
||||||
if(temp = (value / 10000) % 10; temp > 0) {
|
if(temp = (value / 10000) % 10; temp > 0) {
|
||||||
if(!s.empty()) { s.push_back(' '); }
|
if(!s.empty()) { s.push_back(' '); }
|
||||||
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
if(temp != 1) { s.append(digit_to_kword(temp)); }
|
||||||
s.append(man);
|
s.append(man);
|
||||||
} else if(!s.empty()) {
|
} else if (requires_man) {
|
||||||
|
s.push_back(' ');
|
||||||
s.append(man);
|
s.append(man);
|
||||||
}
|
}
|
||||||
if(temp = (value / 1000) % 10; temp > 0) {
|
if(temp = (value / 1000) % 10; temp > 0) {
|
||||||
|
@ -252,7 +261,7 @@ void printValue(unsigned long long value) {
|
||||||
unsigned char count = 0;
|
unsigned char count = 0;
|
||||||
while(temp > 0) {
|
while(temp > 0) {
|
||||||
++count;
|
++count;
|
||||||
s.push_back('0' + temp % 10);
|
s.push_back('0' + (char)(temp % 10));
|
||||||
temp /= 10;
|
temp /= 10;
|
||||||
if(count == 3 && temp > 0) {
|
if(count == 3 && temp > 0) {
|
||||||
s.push_back(',');
|
s.push_back(',');
|
||||||
|
@ -280,13 +289,13 @@ unsigned long long clamp_digits(unsigned int digits, unsigned long long value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream &os, const std::u8string &str) {
|
std::ostream& operator<<(std::ostream &os, const std::u8string &str) {
|
||||||
os.write(reinterpret_cast<const char*>(str.data()), str.size());
|
os.write(reinterpret_cast<const char*>(str.data()), (long)str.size());
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream &os, const char8_t *str8) {
|
std::ostream& operator<<(std::ostream &os, const char8_t *str8) {
|
||||||
const char *cstr = reinterpret_cast<const char*>(str8);
|
const char *cstr = reinterpret_cast<const char*>(str8);
|
||||||
os.write(cstr, strlen(cstr));
|
os.write(cstr, (long)strlen(cstr));
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +410,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
unsigned long long value;
|
unsigned long long value;
|
||||||
{
|
{
|
||||||
std::default_random_engine r_eng(std::chrono::steady_clock::now().time_since_epoch().count());
|
std::default_random_engine r_eng((unsigned long)std::chrono::steady_clock::now().time_since_epoch().count());
|
||||||
if(!isAlt && randomizeDigits) {
|
if(!isAlt && randomizeDigits) {
|
||||||
unsigned int min_digits = 0;
|
unsigned int min_digits = 0;
|
||||||
for (unsigned long long min_copy = min; min_copy > 0; min_copy /= 10) {
|
for (unsigned long long min_copy = min; min_copy > 0; min_copy /= 10) {
|
||||||
|
|
Loading…
Reference in a new issue