aboutsummaryrefslogtreecommitdiff
path: root/source/Host
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-06 20:14:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-06 20:14:12 +0000
commita4092fcbfb39b4d32a8e152a110d20132779d538 (patch)
tree37c84fe56b8ec43e3b08de27d76f53e259ddb0c7 /source/Host
parentcce7c2b0d24e364b1907670cf6f843531e5fe052 (diff)
Notes
Diffstat (limited to 'source/Host')
-rw-r--r--source/Host/common/Editline.cpp47
-rw-r--r--source/Host/windows/EditLineWin.cpp15
2 files changed, 44 insertions, 18 deletions
diff --git a/source/Host/common/Editline.cpp b/source/Host/common/Editline.cpp
index a600c61c8e6b..1c5c0ffe902b 100644
--- a/source/Host/common/Editline.cpp
+++ b/source/Host/common/Editline.cpp
@@ -526,17 +526,8 @@ int Editline::GetCharacter(EditLineCharType *c) {
}
if (read_count) {
-#if LLDB_EDITLINE_USE_WCHAR
- // After the initial interruptible read, this is guaranteed not to block
- ungetc(ch, m_input_file);
- *c = fgetwc(m_input_file);
- if (*c != WEOF)
- return 1;
-#else
- *c = ch;
- if (ch != (char)EOF)
+ if (CompleteCharacter(ch, *c))
return 1;
-#endif
} else {
switch (status) {
case lldb::eConnectionStatusSuccess: // Success
@@ -1367,3 +1358,39 @@ void Editline::PrintAsync(Stream *stream, const char *s, size_t len) {
MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
}
}
+
+bool Editline::CompleteCharacter(char ch, EditLineCharType &out) {
+#if !LLDB_EDITLINE_USE_WCHAR
+ if (ch == (char)EOF)
+ return false;
+
+ out = ch;
+ return true;
+#else
+ std::codecvt_utf8<wchar_t> cvt;
+ llvm::SmallString<4> input;
+ for (;;) {
+ const char *from_next;
+ wchar_t *to_next;
+ std::mbstate_t state = std::mbstate_t();
+ input.push_back(ch);
+ switch (cvt.in(state, input.begin(), input.end(), from_next, &out, &out + 1,
+ to_next)) {
+ case std::codecvt_base::ok:
+ return out != WEOF;
+
+ case std::codecvt_base::error:
+ case std::codecvt_base::noconv:
+ return false;
+
+ case std::codecvt_base::partial:
+ lldb::ConnectionStatus status;
+ size_t read_count = m_input_connection.Read(
+ &ch, 1, std::chrono::seconds(0), status, nullptr);
+ if (read_count == 0)
+ return false;
+ break;
+ }
+ }
+#endif
+}
diff --git a/source/Host/windows/EditLineWin.cpp b/source/Host/windows/EditLineWin.cpp
index 124104b00067..133cd6225467 100644
--- a/source/Host/windows/EditLineWin.cpp
+++ b/source/Host/windows/EditLineWin.cpp
@@ -13,6 +13,7 @@
#include "lldb/Host/windows/windows.h"
#include "lldb/Host/windows/editlinewin.h"
+#include "llvm/Support/ErrorHandling.h"
#include <assert.h>
#include <vector>
@@ -285,11 +286,10 @@ void el_end(EditLine *el) {
// assert( !"Not implemented!" );
}
-void el_reset(EditLine *) { assert(!"Not implemented!"); }
+void el_reset(EditLine *) { llvm_unreachable("Not implemented!"); }
int el_getc(EditLine *, char *) {
- assert(!"Not implemented!");
- return 0;
+ llvm_unreachable("Not implemented!");
}
void el_push(EditLine *, const char *) {}
@@ -297,8 +297,7 @@ void el_push(EditLine *, const char *) {}
void el_beep(EditLine *) { Beep(1000, 500); }
int el_parse(EditLine *, int, const char **) {
- assert(!"Not implemented!");
- return 0;
+ llvm_unreachable("Not implemented!");
}
int el_get(EditLine *el, int code, ...) {
@@ -311,7 +310,7 @@ int el_get(EditLine *el, int code, ...) {
*dout = clientData;
} break;
default:
- assert(!"Not implemented!");
+ llvm_unreachable("Not implemented!");
}
return 0;
}
@@ -322,7 +321,7 @@ int el_source(EditLine *el, const char *file) {
return 0;
}
-void el_resize(EditLine *) { assert(!"Not implemented!"); }
+void el_resize(EditLine *) { llvm_unreachable("Not implemented!"); }
const LineInfo *el_line(EditLine *el) { return 0; }
@@ -331,7 +330,7 @@ int el_insertstr(EditLine *, const char *) {
return 0;
}
-void el_deletestr(EditLine *, int) { assert(!"Not implemented!"); }
+void el_deletestr(EditLine *, int) { llvm_unreachable("Not implemented!"); }
History *history_init(void) {
// return dummy handle