|
10 | 10 | #include <iomanip> |
11 | 11 | #include <optional> |
12 | 12 |
|
13 | | -#include "lldb/Host/Editline.h" |
14 | | - |
15 | 13 | #include "lldb/Host/ConnectionFileDescriptor.h" |
| 14 | +#include "lldb/Host/Editline.h" |
16 | 15 | #include "lldb/Host/FileSystem.h" |
17 | 16 | #include "lldb/Host/Host.h" |
18 | 17 | #include "lldb/Utility/CompletionRequest.h" |
|
23 | 22 | #include "lldb/Utility/StreamString.h" |
24 | 23 | #include "lldb/Utility/StringList.h" |
25 | 24 | #include "lldb/Utility/Timeout.h" |
| 25 | +#include "llvm/Support/ConvertUTF.h" |
26 | 26 |
|
27 | 27 | #include "llvm/Support/FileSystem.h" |
28 | 28 | #include "llvm/Support/Locale.h" |
@@ -444,7 +444,9 @@ StringList Editline::GetInputAsStringList(int line_count) { |
444 | 444 | if (line_count == 0) |
445 | 445 | break; |
446 | 446 | #if LLDB_EDITLINE_USE_WCHAR |
447 | | - lines.AppendString(m_utf8conv.to_bytes(line)); |
| 447 | + std::string buffer; |
| 448 | + llvm::convertWideToUTF8(line, buffer); |
| 449 | + lines.AppendString(buffer); |
448 | 450 | #else |
449 | 451 | lines.AppendString(line); |
450 | 452 | #endif |
@@ -636,7 +638,9 @@ unsigned char Editline::BreakLineCommand(int ch) { |
636 | 638 | if (m_fix_indentation_callback) { |
637 | 639 | StringList lines = GetInputAsStringList(m_current_line_index + 1); |
638 | 640 | #if LLDB_EDITLINE_USE_WCHAR |
639 | | - lines.AppendString(m_utf8conv.to_bytes(new_line_fragment)); |
| 641 | + std::string buffer; |
| 642 | + llvm::convertWideToUTF8(new_line_fragment, buffer); |
| 643 | + lines.AppendString(buffer); |
640 | 644 | #else |
641 | 645 | lines.AppendString(new_line_fragment); |
642 | 646 | #endif |
@@ -684,8 +688,9 @@ unsigned char Editline::EndOrAddLineCommand(int ch) { |
684 | 688 | m_input_lines.clear(); |
685 | 689 | for (unsigned index = 0; index < lines.GetSize(); index++) { |
686 | 690 | #if LLDB_EDITLINE_USE_WCHAR |
687 | | - m_input_lines.insert(m_input_lines.end(), |
688 | | - m_utf8conv.from_bytes(lines[index])); |
| 691 | + std::wstring wbuffer; |
| 692 | + llvm::ConvertUTF8toWide(lines[index], wbuffer); |
| 693 | + m_input_lines.insert(m_input_lines.end(), wbuffer); |
689 | 694 | #else |
690 | 695 | m_input_lines.insert(m_input_lines.end(), lines[index]); |
691 | 696 | #endif |
@@ -869,7 +874,9 @@ unsigned char Editline::FixIndentationCommand(int ch) { |
869 | 874 | currentLine = currentLine.erase(0, -indent_correction); |
870 | 875 | } |
871 | 876 | #if LLDB_EDITLINE_USE_WCHAR |
872 | | - m_input_lines[m_current_line_index] = m_utf8conv.from_bytes(currentLine); |
| 877 | + std::wstring wbuffer; |
| 878 | + llvm::ConvertUTF8toWide(currentLine, wbuffer); |
| 879 | + m_input_lines[m_current_line_index] = wbuffer; |
873 | 880 | #else |
874 | 881 | m_input_lines[m_current_line_index] = currentLine; |
875 | 882 | #endif |
@@ -1502,7 +1509,7 @@ bool Editline::GetLine(std::string &line, bool &interrupted) { |
1502 | 1509 | } else { |
1503 | 1510 | m_history_sp->Enter(input); |
1504 | 1511 | #if LLDB_EDITLINE_USE_WCHAR |
1505 | | - line = m_utf8conv.to_bytes(SplitLines(input)[0]); |
| 1512 | + llvm::convertWideToUTF8(SplitLines(input)[0], line); |
1506 | 1513 | #else |
1507 | 1514 | line = SplitLines(input)[0]; |
1508 | 1515 | #endif |
@@ -1574,25 +1581,22 @@ bool Editline::CompleteCharacter(char ch, EditLineGetCharType &out) { |
1574 | 1581 | out = (unsigned char)ch; |
1575 | 1582 | return true; |
1576 | 1583 | #else |
1577 | | - LLDB_DEPRECATED_WARNING_DISABLE |
1578 | | - std::codecvt_utf8<wchar_t> cvt; |
1579 | | - LLDB_DEPRECATED_WARNING_RESTORE |
1580 | 1584 | llvm::SmallString<4> input; |
1581 | 1585 | for (;;) { |
1582 | | - const char *from_next; |
1583 | | - wchar_t *to_next; |
1584 | | - std::mbstate_t state = std::mbstate_t(); |
1585 | 1586 | input.push_back(ch); |
1586 | | - switch (cvt.in(state, input.begin(), input.end(), from_next, &out, &out + 1, |
1587 | | - to_next)) { |
1588 | | - case std::codecvt_base::ok: |
| 1587 | + auto *cur_ptr = reinterpret_cast<const llvm::UTF8 *>(input.begin()); |
| 1588 | + auto *end_ptr = reinterpret_cast<const llvm::UTF8 *>(input.end()); |
| 1589 | + llvm::UTF32 code_point = 0; |
| 1590 | + llvm::ConversionResult cr = llvm::convertUTF8Sequence( |
| 1591 | + &cur_ptr, end_ptr, &code_point, llvm::lenientConversion); |
| 1592 | + switch (cr) { |
| 1593 | + case llvm::conversionOK: |
| 1594 | + out = code_point; |
1589 | 1595 | return out != (EditLineGetCharType)WEOF; |
1590 | | - |
1591 | | - case std::codecvt_base::error: |
1592 | | - case std::codecvt_base::noconv: |
| 1596 | + case llvm::targetExhausted: |
| 1597 | + case llvm::sourceIllegal: |
1593 | 1598 | return false; |
1594 | | - |
1595 | | - case std::codecvt_base::partial: |
| 1599 | + case llvm::sourceExhausted: |
1596 | 1600 | lldb::ConnectionStatus status; |
1597 | 1601 | size_t read_count = m_input_connection.Read( |
1598 | 1602 | &ch, 1, std::chrono::seconds(0), status, nullptr); |
|
0 commit comments