Skip to content

Commit

Permalink
Port new shlex code to Go
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 4, 2023
1 parent 04eafbe commit a1f2a7d
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 433 deletions.
5 changes: 4 additions & 1 deletion kittens/ssh/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func TestParseSSHArgs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(ans) == 0 {
ans = []string{}
}
return ans
}

Expand All @@ -39,7 +42,7 @@ func TestParseSSHArgs(t *testing.T) {
check := func(a, b any) {
diff := cmp.Diff(a, b)
if diff != "" {
t.Fatalf("Unexpected value for args: %s\n%s", args, diff)
t.Fatalf("Unexpected value for args: %#v\n%s", args, diff)
}
}
check(split(expected_ssh_args), ssh_args)
Expand Down
7 changes: 1 addition & 6 deletions kitty/shlex.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,16 @@ next_word(Shlex *self, PyObject *args UNUSED) {
switch(ch) {
case STRING_WITHOUT_ESCAPES_DELIM:
set_state(self, WORD);
if (self->buf_pos && self->state == NORMAL) return get_word(self);
break;
default: write_ch(self, ch); break;
} break;
case STRING_WITH_ESCAPES:
switch(ch) {
case STRING_WITH_ESCAPES_DELIM:
set_state(self, WORD);
if (self->buf_pos && self->state == NORMAL) return get_word(self);
break;
case ESCAPE_CHAR:
if (self->src_pos < self->src_sz) {
Py_UCS4 nch = PyUnicode_READ(self->kind, self->src_data, self->src_pos); self->src_pos++;
write_ch(self, nch);
}
write_escape_ch(self);
break;
default: write_ch(self, ch); break;
} break;
Expand Down
Loading

0 comments on commit a1f2a7d

Please sign in to comment.