Skip to content

Commit

Permalink
Add EditStringASCII(), that is relevant for editing URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mywave82 committed Dec 14, 2024
1 parent dccc671 commit 1399d23
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions boot/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ struct console_t Console =
try_open_png,
EditStringUTF8z,
EditStringUTF8,
EditStringASCII,
80, /* TextHeight */
25, /* TextWidth */
0, /* TextGUIOverlay */
Expand Down
1 change: 1 addition & 0 deletions stuff/poutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct console_t
int (*EditStringUTF8z)(unsigned int y, unsigned int x, unsigned int w, int l, char *s);
/* zero-terminated, forever long dynamic buffer */
int (*EditStringUTF8)(unsigned int y, unsigned int x, unsigned int w, char **s);
int (*EditStringASCII)(unsigned int y, unsigned int x, unsigned int w, char **s);

/* console resolution */
unsigned int TextHeight; /* range 25..inifinity */
Expand Down
18 changes: 17 additions & 1 deletion stuff/utf-8.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ int EditStringUTF8z (unsigned int y, unsigned int x, unsigned int w, int l, char
}


int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s)
static int _EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s, int ASCIIonly)
{
/* problems:
each UTF-8 noun might be 1-4 bytes per character <- use utf8_decode in a loop to cycle positions
Expand Down Expand Up @@ -592,6 +592,13 @@ int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s)
continue;
}
input_buffer_fill = 0;
if (ASCIIonly)
{
if (codepoint > 127)
{
continue;
}
}

if ( insmode || ( curpos == workstring_length ) ) /* insert / append */
{
Expand Down Expand Up @@ -702,6 +709,15 @@ int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s)
return 1;
}

int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s)
{
return _EditStringUTF8 (y, x, w, s, 0);
}

int EditStringASCII(unsigned int y, unsigned int x, unsigned int w, char **s)
{
return _EditStringUTF8 (y, x, w, s, 1);
}

#if 0

Expand Down
4 changes: 4 additions & 0 deletions stuff/utf-8.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ int EditStringUTF8z(unsigned int y, unsigned int x, unsigned int w, int l, char
/* zero-terminated, forever long dynamic buffer */
int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s);

/* zero-terminated, forever long dynamic buffer */
int EditStringASCII(unsigned int y, unsigned int x, unsigned int w, char **s);


#endif

0 comments on commit 1399d23

Please sign in to comment.