Show and edit escaped character in QLineEdit - c++

Is there a way to show escaped characters like carriage return line feed "\r\n" characters in a QLineEdit in a human readable (escaped) way automatically?
Alternatively is there an easy method to automatically generate an escaped string.
Also I need to allow the user to edit the escaped string and when reading back the current text from the QLineEdit, storing it in a std::string it has to be non-escaped.
Use case.
I want the user to set a termination string (for example \r\n) for a communication object. Passing \r\n to a QLineEdit without any manual escaping, results in two unvisible characters in the QLineEdit input box.

"\\r\\n" ? You can create an inline stub the calls qstring::replace and return std with .toStdString

Related

Modifying a QString that contains a "\"

I'm trying to modify a QString. The Qstring that I'm trying to modify is
"\002"
However when I try to modify it, the string either gets entirely deleted or shows no change.
I've tried
String.split("\"");
String.remove("\"");
String.remove(QChar('\'');
for some reason Qt requires that I add an extra " or ' in order to compile and not produce errors
What I currently have is this
string = pointer->data.info.get_type();
which according to the debugger returns "\002"
string = string.remove(QChar('\''));
the remove functionality does nothing afterwards.
I'm expecting to remove the \ from the string, but either it gets entirely deleted or nothing happens. What could be the problem and how do I modify the Qstring to just be the numerical values?
You're currently asking Qt to remove " from your string, not \. To remove \, you'll have to escape it, just like you escaped ", i.e. remove("\\").
First of all your string "\002" do not contain any slash, quotes or apostrophes.
Read about C++ string literals. This is escape sequence.
Note \nnn represents arbitrary octal value!
So your literal contains only one character of value decimal value 2! This is ASCII spatial code meaning: STX (start of text)
As a result this code:
String.split("\"");
String.remove("\"");
String.remove(QChar('\'');
won't split or anything since this string do not contain quote characters or apostrophe. It also do not tries split or remove slash character, since again this is an escape sequence, but different kind.
Now remember that debugger shows you this unprintable characters in escaped form to show you actual content. In live application user will see nothing or some strange glyph.

Dot character cancels completion in Sublime Text plugin

I'm working on a Sublime Text 3 plugin, which contains a number of completions for the standard library. Some of these functions (e.g. io.open( filename, mode )) contain the dot character (".").
The problem is, Sublime Text cancels the completion dialog when a "." is typed (word boundary).
To get around this, I've tried using underscores instead of dots in the triggers:
{"trigger": "io_open( filename, mode )", "contents": "io.open( ${1:filename}, ${2:mode} )"}
However, this doesn't work very well at all. If the user tries to type in io.open instead of io_open, Sublime restarts the completion at the dot, and they end up with io.io.open.
Is there any way around this? Having the dot character as word boundary is useful for selecting text, so I'd like to keep that if it is possible.

How to write a QRegExp that will accept only strings made of characters or normal symbols?

Let me clarify the question. I need to process keyboard input on the fly. So if the user presses something like the home button or the delete button I need to ignore the input. But any normal printable symbol I want to catch. I get the input in the text field() method of a QKeyEvent.
I've tried two regexps
The first one was:
QRegExp("[\\S]");
Which did not work as apparently pressing delete is considered a non-whitespace character.
The second one was
QRegExp("[\\w]");
This one was much better as it would only accept letters, number and underscore but no symbols such as + or *. Which I want to accept.
I was thinking of modifying the last expression to include any symbol in my keyboard. But how would I do that? Or how can I write an RegExp for what I want?

QTextEdit changes control characters

I've encountered some feature in Qt widgets QTextEdit, QPlainTextEdit, etc that I wouldn't like to encounter. And I actually have no idea how to change this issue.
I want to cipher some text, replacing one unicode character with another unicode character, even if it is control one.
So I delcare a simple string this way:
QChar ch = (QChar)0x20;
QChar ch2 = (QChar)0xA0;
QString str; str.append(ch); str.append(ch2);
These are usual space (0x20) and some unusual No-Break Space (0xA0). In memory the string is absolutely perfect. But if I set it as a text of QTextEdit with ui->txt_ciphered->setPlainText(str); this No-Break Space (0xA0) becomes usual space. I guess that's because they are for some similar purposes, but I still want to get No-Break Space character in TextEdit so that I could copy it etc. like I can in Notepad++ in example.
How could I change this?
QTextEdit does not accept non-break space, why? How can I
still use non-break space with Qt edit controls?
The problem is that QTextEdit::plainText property expressively prevents non-break space from being inserted and converts it to just space character.
plainText : QString
This property gets and sets the text editor's contents as plain text.
Previous contents are removed and undo/redo history is reset when the
property is set.
If the text edit has another content type, it will not be replaced by
plain text if you call toPlainText(). The only exception to this is
the non-break space, nbsp;, that will be converted into standard
space.
Suggestion: use QTextEdit::setText.
If it still does an unwanted conversion or does not treat that symbol right, you need to choose HTML form of test for QTextEdit::setText by inserting the text containing in an envelope of html tags or <html>My text</html>.

I see a character called xDB on notepad++. What character is this?

What is this character
All I really need to know is what is this character. I have not seen anything like this before.
How do i remove this using Vb.net:
data = data.Replace(Chr(???????), "")
Is there a specific control character decimal number or something to this character that i can use in place of ??
Please help.
I tried looking up all the html, ascii and the regex languages to find this character but i did not find this anywhere.
To prevent possible bugs related to the encoding of your source files, you should use a hex editor (such as this Notepad++ plugin) to find the hexadecimal code of the character, then use that to reference the character in your code:
data = data.Replace((char)0xDB, "")
as opposed to:
data = data.Replace("Û", "")
Note: In this case the hex editor is unnecessary because xDB is already a hex code, but other control characters, such as CR and LF, are not displayed as their hex values [in Notepad++].