20 #include "../tools/Lexer.h" 27 std::string first_name;
29 std::string last_name;
32 static Lexer & GetFormatLexer() {
35 lexer.
AddToken(
"type",
"[FMLfmlPSx]");
36 lexer.
AddToken(
"spacing",
"[- ,.:]+");
41 Author(
const std::string & first,
const std::string & middle,
const std::string & last)
42 : first_name(first), last_name(last) { middle_names.
push_back(middle); }
43 Author(
const std::string & first,
const std::string & last)
44 : first_name(first), last_name(last) { ; }
46 : last_name(last) { ; }
52 return (prefix == other.prefix) && (first_name == other.first_name) &&
53 (middle_names == other.middle_names) &&
54 (last_name == other.last_name) && (suffix == other.suffix);
58 if (last_name != other.last_name)
return (last_name < other.last_name);
59 if (first_name != other.first_name)
return (first_name < other.first_name);
60 for (
size_t i = 0; i < middle_names.
size(); i++) {
61 if (other.middle_names.
size() <= i)
return false;
62 if (middle_names[i] != other.middle_names[i]) {
63 return (middle_names[i] < other.middle_names[i]);
66 if (middle_names.
size() < other.middle_names.
size())
return true;
67 if (suffix != other.suffix)
return (suffix < other.suffix);
68 if (prefix != other.prefix)
return (prefix < other.prefix);
81 const std::string &
GetPrefix()
const {
return prefix; }
85 return middle_names[id];
88 const std::string &
GetSuffix()
const {
return suffix; }
91 std::string full_name(prefix);
92 if (full_name.size() &&
HasFirstName()) full_name +=
" ";
93 full_name += first_name;
94 for (
const auto & middle_name : middle_names) {
95 if (full_name.size()) full_name +=
" ";
96 full_name += middle_name;
98 if (full_name.size() &&
HasLastName()) full_name +=
" ";
99 full_name += last_name;
100 if (full_name.size() &&
HasSuffix()) full_name +=
" ";
105 std::string full_name(last_name);
106 if (full_name.size() &&
HasFirstName()) full_name +=
", ";
107 full_name += first_name;
108 for (
const auto & middle_name : middle_names) {
109 if (full_name.size()) full_name +=
" ";
110 full_name += middle_name;
112 if (full_name.size() &&
HasSuffix()) full_name +=
", ";
122 for (
const auto & m : middle_names) out += m[0];
156 std::string
GetName(std::string pattern=
"FML") {
157 std::string out_name;
158 Lexer & lexer = GetFormatLexer();
164 prefix=
""; first_name=
""; last_name=
""; middle_names.
resize(0); suffix=
"";
168 Author &
SetLast(
const std::string & str) { last_name = str;
return *
this; }
static const std::string & empty_string()
Definition: string_utils.h:29
Author(const std::string &last)
Definition: Author.h:45
bool HasPrefix() const
Definition: Author.h:75
std::string GetInitials() const
Definition: Author.h:128
std::string GetName(std::string pattern="FML")
Definition: Author.h:156
std::string GetMiddleInitials() const
Definition: Author.h:120
std::string to_string(ALL_TYPES &&...all_values)
Definition: string_utils.h:511
size_t GetNumTokens() const
How many types of tokens can be identified in this Lexer?
Definition: Lexer.h:82
Author & SetFirst(const std::string &str)
Definition: Author.h:167
std::string GetLastInitial() const
Definition: Author.h:125
bool operator>=(const Author &other) const
Definition: Author.h:72
void push_back(PB_Ts &&...args)
Definition: vector.h:189
const std::string & GetPrefix() const
Definition: Author.h:81
A lexer with a set of token types (and associated regular expressions)
Definition: Lexer.h:64
Author & SetLast(const std::string &str)
Definition: Author.h:168
size_t size() const
Definition: vector.h:151
Author & AddMiddle(const std::string &str)
Definition: Author.h:169
Token Process(std::istream &is)
Get the next token found in an input stream.
Definition: Lexer.h:133
bool operator>(const Author &other) const
Definition: Author.h:71
Author(const std::string &first, const std::string &middle, const std::string &last)
Definition: Author.h:41
const std::string & GetMiddleName(size_t id=0) const
Definition: Author.h:83
const std::string & GetLastName() const
Definition: Author.h:87
std::string GetFullName() const
Definition: Author.h:90
bool HasSuffix() const
Definition: Author.h:79
bool operator<=(const Author &other) const
Definition: Author.h:73
Author & Clear()
Definition: Author.h:163
std::string GetFirstInitial() const
Definition: Author.h:117
void resize(size_t new_size)
Definition: vector.h:161
std::string GetReverseName() const
Definition: Author.h:104
Author(const std::string &first, const std::string &last)
Definition: Author.h:43
~Author()
Definition: Author.h:48
If we are in emscripten, make sure to include the header.
Definition: array.h:37
bool operator<(const Author &other) const
Definition: Author.h:57
bool operator==(const Author &other) const
Definition: Author.h:51
Author & operator=(const Author &)=default
bool HasMiddleName() const
Definition: Author.h:77
bool HasFirstName() const
Definition: Author.h:76
const std::string & GetFirstName() const
Definition: Author.h:82
const std::string & GetSuffix() const
Definition: Author.h:88
bool operator!=(const Author &other) const
Definition: Author.h:56
bool HasLastName() const
Definition: Author.h:78
size_t AddToken(const std::string &in_name, const std::string &in_regex)
Add a new token, specified by a name and the regex used to identify it.
Definition: Lexer.h:85