summaryrefslogtreecommitdiff
path: root/src/mmo/strs.hpp
blob: 16e524aa1c51c23c579fdab71c858c21b296539e (plain) (blame)
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
#ifndef TMWA_MMO_STRS_HPP
#define TMWA_MMO_STRS_HPP
//    strs.hpp - common string types
//
//    Copyright © ????-2004 Athena Dev Teams
//    Copyright © 2004-2011 The Mana World Development Team
//    Copyright © 2011-2014 Ben Longbons <b.r.longbons@gmail.com>
//
//    This file is part of The Mana World (Athena server)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# include "fwd.hpp"

# include "../strings/vstring.hpp"


namespace tmwa
{
// affects CharName
# define NAME_IGNORING_CASE 1

struct AccountName : VString<23> {};
struct AccountPass : VString<23> {};
struct AccountCrypt : VString<39> {};
struct AccountEmail : VString<39> {};
struct ServerName : VString<19> {};
struct PartyName : VString<23> {};
struct VarName : VString<31> {};

# define DEFAULT_EMAIL stringish<AccountEmail>("a@a.com"_s)

// It is decreed: a mapname shall not contain an extension
class MapName : public strings::_crtp_string<MapName, MapName, strings::ZPair>
{
    VString<15> _impl;
public:
    MapName() = default;
    MapName(VString<15> v) : _impl(v.xislice_h(std::find(v.begin(), v.end(), '.'))) {}

    iterator begin() const { return &*_impl.begin(); }
    iterator end() const { return &*_impl.end(); }
    const char *c_str() const { return _impl.c_str(); }

    operator RString() const { return _impl; }
    operator AString() const { return _impl; }
    operator TString() const { return _impl; }
    operator SString() const { return _impl; }
    operator ZString() const { return _impl; }
    operator XString() const { return _impl; }
};
template<>
inline
MapName stringish<MapName>(VString<15> iv)
{
    return iv;
}
inline
const char *decay_for_printf(const MapName& vs) { return vs.c_str(); }

// It is decreed: a charname is sometimes case sensitive
struct CharName
{
private:
    VString<23> _impl;
public:
    CharName() = default;
    explicit CharName(VString<23> name)
    : _impl(name)
    {}

    VString<23> to__actual() const
    {
        return _impl;
    }
    VString<23> to__lower() const
    {
        return _impl.to_lower();
    }
    VString<23> to__upper() const
    {
        return _impl.to_upper();
    }
    VString<23> to__canonical() const
    {
# if NAME_IGNORING_CASE == 0
        return to__actual();
# endif
# if NAME_IGNORING_CASE == 1
        return to__lower();
# endif
    }

    friend bool operator == (const CharName& l, const CharName& r)
    { return l.to__canonical() == r.to__canonical(); }
    friend bool operator != (const CharName& l, const CharName& r)
    { return l.to__canonical() != r.to__canonical(); }
    friend bool operator < (const CharName& l, const CharName& r)
    { return l.to__canonical() < r.to__canonical(); }
    friend bool operator <= (const CharName& l, const CharName& r)
    { return l.to__canonical() <= r.to__canonical(); }
    friend bool operator > (const CharName& l, const CharName& r)
    { return l.to__canonical() > r.to__canonical(); }
    friend bool operator >= (const CharName& l, const CharName& r)
    { return l.to__canonical() >= r.to__canonical(); }

    friend
    VString<23> convert_for_printf(const CharName& vs) { return vs.to__actual(); }
};
template<>
inline
CharName stringish<CharName>(VString<23> iv)
{
    return CharName(iv);
}
} // namespace tmwa

#endif // TMWA_MMO_STRS_HPP