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