std::string_view
Posted: Tue Mar 30 2021 9:16 pm
All,
I'm porting Scintilla to CopperSpice for use in RedDiamond. Scintilla is really robust and many editors like Notepadqq and Juffed use it.
I'm down to the last source file and two compilation errors in the input method, both with code like this.
I know the intent here. InsertCharacter() is ultimately handing this off to some Python stuff. There is no changing that. We should be able to do something like this:
I've got a strong suspicion this code doesn't work on with Unicode sets where a single UTF16 doesn't old the character value.
So, given my complete inability to focus right now, what is the solution? It __has__ to be something simple that I'm walking right past.
I'm porting Scintilla to CopperSpice for use in RedDiamond. Scintilla is really robust and many editors like Notepadqq and Juffed use it.
I'm down to the last source file and two compilation errors in the input method, both with code like this.
Code: Select all
if ( !event->commitString().isEmpty() )
{
const QString commitStr = event->commitString();
const unsigned int commitStrLen = commitStr.length();
for ( unsigned int i = 0; i < commitStrLen; )
{
const unsigned int ucWidth = commitStr.at( i ).isHighSurrogate() ? 2 : 1;
const QString oneCharUTF16 = commitStr.mid( i, ucWidth );
const QByteArray oneChar = sqt->BytesForDocument( oneCharUTF16 );
sqt->InsertCharacter( std::string_view( oneChar.data(), oneChar.length() ), EditModel::CharacterSource::directInput );
i += ucWidth;
}
}
Code: Select all
for ( QChar32 oneChar : commitStr)
{
sqt->InsertCharacter( oneChar.toStdStringView(), EditModel::CharacterSource::directInput );
}
So, given my complete inability to focus right now, what is the solution? It __has__ to be something simple that I'm walking right past.