comparison irccdctl/alias.cpp @ 0:1158cffe5a5e

Initial import
author David Demelier <markand@malikania.fr>
date Mon, 08 Feb 2016 16:43:14 +0100
parents
children 9bc2da03dbe1
comparison
equal deleted inserted replaced
-1:000000000000 0:1158cffe5a5e
1 /*
2 * alias.cpp -- create irccdctl aliases
3 *
4 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <cassert>
20 #include <regex>
21
22 #include "alias.h"
23
24 namespace irccd {
25
26 AliasArg::AliasArg(std::string value)
27 {
28 assert(!value.empty());
29
30 if ((m_isPlaceholder = std::regex_match(value, std::regex("^%\\d+$"))))
31 m_value = value.substr(1);
32 else
33 m_value = std::move(value);
34 }
35
36 unsigned AliasArg::index() const noexcept
37 {
38 assert(isPlaceholder());
39
40 return std::stoi(m_value);
41 }
42
43 const std::string &AliasArg::value() const noexcept
44 {
45 assert(!isPlaceholder());
46
47 return m_value;
48 }
49
50 std::ostream &operator<<(std::ostream &out, const AliasArg &arg)
51 {
52 if (arg.m_isPlaceholder)
53 out << "%" << arg.m_value;
54 else
55 out << arg.m_value;
56
57 return out;
58 }
59
60 } // !irccd