-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathUwxEscape.cpp
93 lines (88 loc) · 3.5 KB
/
UwxEscape.cpp
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
/******************************************************************************
** Copyright (C) 2016-2023 Laird Connectivity
**
** Project: UwTerminalX
**
** Module: UwxEscape.h
**
** Notes:
**
** License: 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, version 3.
**
** 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/
**
** SPDX-License-Identifier: GPL-3.0
**
*******************************************************************************/
/******************************************************************************/
// Include Files
/******************************************************************************/
#include "UwxEscape.h"
/******************************************************************************/
// Local Functions or Private Members
/******************************************************************************/
//=============================================================================
//=============================================================================
void
UwxEscape::EscapeCharacters(
QByteArray *baData
)
{
//Escapes character sequences
qint32 Next = baData->indexOf("\\");
while (Next != -1)
{
if (baData->length() <= Next+1)
{
//No more string length, ignore
break;
}
else if (baData->at(Next+1) == '\\')
{
//This is a \\ so remove one of the slashes and ignore the conversion
baData->remove(Next, 1);
}
else if (baData->at(Next+1) == 'r' || baData->at(Next+1) == 'R')
{
//This is a \r or \R
baData->insert(Next, "\r");
baData->remove(Next+1, 2);
}
else if (baData->at(Next+1) == 'n' || baData->at(Next+1) == 'N')
{
//This is a \n or \N
baData->insert(Next, "\n");
baData->remove(Next+1, 2);
}
else if (baData->at(Next+1) == 't' || baData->at(Next+1) == 'T')
{
//This is a \t or \T
baData->insert(Next, "\t");
baData->remove(Next+1, 2);
}
else if (baData->length() <= Next+2)
{
//No more string length, ignore
break;
}
else if (((baData->at(Next+1) >= '0' && baData->at(Next+1) <= '9') || (baData->at(Next+1) >= 'a' && baData->at(Next+1) <= 'f') || (baData->at(Next+1) >= 'A' && baData->at(Next+1) <= 'F')) && ((baData->at(Next+2) >= '0' && baData->at(Next+2) <= '9') || (baData->at(Next+2) >= 'a' && baData->at(Next+2) <= 'f') || (baData->at(Next+2) >= 'A' && baData->at(Next+2) <= 'F')))
{
//Character to escape
baData->insert(Next, (char)baData->mid(Next+1, 2).toInt(NULL, 16));
baData->remove(Next+1, 3);
}
//Search for the next instance
Next = baData->indexOf("\\", Next+1);
}
}
/******************************************************************************/
// END OF FILE
/******************************************************************************/