GUAC-584: Implement UTF8 read and write. Add basic identity test.
This commit is contained in:
parent
dfc18e14a4
commit
ccc2526282
@ -23,16 +23,43 @@
|
||||
#include "config.h"
|
||||
#include "guac_iconv.h"
|
||||
|
||||
#include <guacamole/unicode.h>
|
||||
|
||||
void guac_iconv(guac_iconv_read* reader, char** input, int in_remaining,
|
||||
guac_iconv_write* writer, char** output, int out_remaining) {
|
||||
/* STUB */
|
||||
|
||||
while (in_remaining > 0 && out_remaining > 0) {
|
||||
|
||||
int value;
|
||||
char* read_start;
|
||||
char* write_start;
|
||||
|
||||
/* Read character */
|
||||
read_start = *input;
|
||||
value = reader(input, in_remaining);
|
||||
in_remaining -= *input - read_start;
|
||||
|
||||
/* Write character */
|
||||
write_start = *output;
|
||||
writer(output, out_remaining, value);
|
||||
out_remaining -= *output - write_start;
|
||||
|
||||
/* Stop if null terminator reached */
|
||||
if (value == 0)
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int GUAC_READ_UTF8(char** input, int remaining) {
|
||||
/* STUB */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int value;
|
||||
|
||||
*input += guac_utf8_read(*input, remaining, &value);
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
int GUAC_READ_UTF16(char** input, int remaining) {
|
||||
/* STUB */
|
||||
@ -40,7 +67,7 @@ int GUAC_READ_UTF16(char** input, int remaining) {
|
||||
}
|
||||
|
||||
void GUAC_WRITE_UTF8(char** output, int remaining, int value) {
|
||||
/* STUB */
|
||||
*output += guac_utf8_write(value, *output, remaining);
|
||||
}
|
||||
|
||||
void GUAC_WRITE_UTF16(char** output, int remaining, int value) {
|
||||
|
@ -29,6 +29,20 @@
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
void test_guac_iconv() {
|
||||
/* STUB */
|
||||
|
||||
char output[4096];
|
||||
char input[4096] = "hello";
|
||||
|
||||
char* current_output = output;
|
||||
char* current_input = input;
|
||||
|
||||
/* Test identity conversion of UTF8 */
|
||||
guac_iconv(GUAC_READ_UTF8, ¤t_input, 4096,
|
||||
GUAC_WRITE_UTF8, ¤t_output, 4096);
|
||||
|
||||
CU_ASSERT_EQUAL(6, current_output - output);
|
||||
CU_ASSERT_EQUAL(6, current_input - input);
|
||||
CU_ASSERT_EQUAL(0, memcmp("hello", output, 6));
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user