Replace non-alphanumeric with underscore - #4166
Conversation
Added option to replace non-alphanumeric characters in column name with underscore. SQL editor does not complete correctly column names containing space, column and etc.
| // Take field name from CSV | ||
| fieldname = std::string(rowData.fields[i].data, rowData.fields[i].data_length); | ||
|
|
||
| // Replace any non-nlphanumeric characters with an underscore |
There was a problem hiding this comment.
| // Replace any non-nlphanumeric characters with an underscore | |
| // Replace any non-alphanumeric character with an underscore |
| // Replace any non-nlphanumeric characters with an underscore | ||
| if(ui->checkReplaceNonAlnum->isChecked()) | ||
| { | ||
| std::regex pattern("[^a-zA-Z0-9_]"); |
There was a problem hiding this comment.
This will treat international letters as non-valid. Is that what we want?
This alternative will support Unicode letters:
for (QChar &c : fieldname)
if (!c.isLetterOrNumber() && c != '_')
c = '_';What I saw is that the special characters don't trigger the completion list (if present in the first characters), but can be completed if the first 3 characters are ASCII. Not sure what we should do; maybe your simple approach is the best option.
There was a problem hiding this comment.
This will treat international letters as non-valid. Is that what we want?
This alternative will support Unicode letters:
for (QChar &c : fieldname) if (!c.isLetterOrNumber() && c != '_') c = '_';What I saw is that the special characters don't trigger the completion list (if present in the first characters), but can be completed if the first 3 characters are ASCII. Not sure what we should do; maybe your simple approach is the best option.
As fieldname is std::string I used conversion to/from QString.
What I saw is that the special characters don't trigger the completion list (if present in the first characters), but can be completed if the first 3 characters are ASCII. Not sure what we should do; maybe your simple approach is the best option.
The problem with QScintilla which inserts text up to first space. I have tried to change behavior, but it was complex and came to this idea (replace non_alnum by _)
|
Perfect, @kor44, thanks for the contribution. |
|
@mgrojo There is currently an issue with the CI workflow, and I will fix it by this morning. :) |
Added option to replace non-alphanumeric characters in column name with underscore. SQL editor does not complete correctly column names containing space, column and etc. This is example CSV
Option location
