Skip to content

Commit 42b9f97

Browse files
committed
Interpreting escape sequence only for string typing
1 parent e1ed12e commit 42b9f97

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

keymapper.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ ScrollLock >> Boss
138138
BracketLeft >> '['
139139
Shift{BracketRight} >> '}'
140140
BracketRight >> ']'
141-
Shift{Backquote} >> Equal Space # '` '
141+
Shift{Backquote} >> '`'
142142
Backquote >> '~'
143143
Shift{2} >> '@'
144144
Shift{3} >> '#'
145-
Shift{6} >> !Shift Backquote Space # '^ '
145+
Shift{6} >> '^'
146146
Shift{7} >> '&'
147147
Shift{8} >> '*'
148148
Shift{9} >> '('

src/client/unix/StringTyperImpl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ StringTyper::Modifiers get_xkb_modifiers(uint32_t mask) {
106106
//-------------------------------------------------------------------------
107107

108108
void StringTyperImpl::type(std::string_view string, const AddKey& add_key) const {
109-
for (auto character : utf8_to_utf32(string))
109+
auto characters = utf8_to_utf32(string);
110+
replace_all<char32_t>(characters, U"\\n", U"\r");
111+
replace_all<char32_t>(characters, U"\\r", U"\r");
112+
replace_all<char32_t>(characters, U"\\t", U"\t");
113+
114+
for (auto character : characters)
110115
if (auto it = m_dictionary.find(character); it != m_dictionary.end())
111116
add_key(it->second.key, it->second.modifiers);
112117
}

src/client/windows/StringTyper.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ class StringTyperImpl {
130130
}
131131

132132
void type(std::string_view string, const AddKey& add_key) const {
133-
for (auto character : utf8_to_wide(string)) {
134-
135-
if (character == '\n')
136-
character = '\r';
133+
auto characters = utf8_to_wide(string);
134+
replace_all<wchar_t>(characters, L"\\n", L"\r");
135+
replace_all<wchar_t>(characters, L"\\r", L"\r");
136+
replace_all<wchar_t>(characters, L"\\t", L"\t");
137137

138+
for (auto character : characters) {
138139
if (auto it = m_dictionary.find(character); it != m_dictionary.end()) {
139140
const auto& [dead_key, key] = it->second;
140141
if (dead_key.key != Key::none)

src/config/ParseConfig.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -408,28 +408,10 @@ std::string ParseConfig::preprocess(It it, const It end) const {
408408
if (!skip_until(&it, end, mark))
409409
error("Unterminated string");
410410

411-
// interpret escape sequence
412-
auto prev = char{ };
413-
std::for_each(begin, it, [&](char c) {
414-
if (prev == '\\') {
415-
c = [&]() {
416-
switch (c) {
417-
case 'n': return '\n';
418-
case 't': return '\t';
419-
}
420-
result.push_back('\\');
421-
return c;
422-
}();
423-
prev = { };
424-
}
425-
else {
426-
prev = c;
427-
}
428-
result.push_back(c);
429-
});
411+
result.append(begin, it);
430412
}
431413
else {
432-
// output single character
414+
// single character
433415
result.append(begin, ++it);
434416
}
435417
}

src/config/StringTyper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ class StringTyper {
2626
private:
2727
std::unique_ptr<class StringTyperImpl> m_impl;
2828
};
29+
30+
template<typename T>
31+
void replace_all(std::basic_string<T>& str, std::basic_string_view<T> from, std::basic_string_view<T> to) {
32+
auto start_pos = size_t{ };
33+
while((start_pos = str.find(from, start_pos)) != std::basic_string<T>::npos) {
34+
str.replace(start_pos, from.size(), to);
35+
start_pos += to.size();
36+
}
37+
}

0 commit comments

Comments
 (0)