aboutsummaryrefslogtreecommitdiff
path: root/src/aopacket.cpp
blob: 4a89e9804b40cf5c87aedfd6f0ab4c0c23506017 (plain)
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
#include "aopacket.h"

QString AOPacket::to_string(bool encoded)
{
  QStringList contents = m_contents;
  if (encoded) {
    escape(contents);
  }
  // Our packet is just the header by itself
  if (contents.isEmpty()) {
    return m_header + "#%";
  }
  return m_header + "#" + contents.join("#") + "#%";
}

void AOPacket::net_encode()
{
  escape(m_contents);
}

void AOPacket::net_decode()
{
  unescape(m_contents);
}

void AOPacket::escape(QStringList &contents)
{
  contents.replaceInStrings("#", "<num>")
    .replaceInStrings("%", "<percent>")
    .replaceInStrings("$", "<dollar>")
    .replaceInStrings("&", "<and>");

}

void AOPacket::unescape(QStringList &contents)
{
  contents.replaceInStrings("<num>", "#")
    .replaceInStrings("<percent>", "%")
    .replaceInStrings("<dollar>", "$")
    .replaceInStrings("<and>", "&");

}