From c2a718075ad321a9cf4678e72645acda5c3471a9 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 22 Feb 2013 12:19:35 +0000 Subject: A load of refactoring of how content selection and input work. Keypresses now go via content interface. Contents don't shove the selection object into browser windows any more. Contents report selection existence by sending message. HTML content keeps track of where selections in it exist. Contents report whether they have input focus via caret setting msg. Caret can be hidden (can still input/paste) or removed. Consolidate textarea selection handling. Make textarea report its selection status changes to client. Various textarea fixes. Changed how we decide when to clear selections, and give focus. --- utils/utf8.c | 39 +++++++++++++++++++++++++++++++++++++++ utils/utf8.h | 2 ++ 2 files changed, 41 insertions(+) (limited to 'utils') diff --git a/utils/utf8.c b/utils/utf8.c index c0f6b106a..b4e308044 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -474,3 +474,42 @@ utf8_convert_ret utf8_to_html(const char *string, const char *encname, } +/** + * Save the given utf8 text to a file, converting to local encoding. + * + * \param utf8_text text to save to file + * \param path pathname to save to + * \return true iff the save succeeded + */ + +bool utf8_save_text(const char *utf8_text, const char *path) +{ + utf8_convert_ret ret; + char *conv; + FILE *out; + + ret = utf8_to_local_encoding(utf8_text, strlen(utf8_text), &conv); + + if (ret != UTF8_CONVERT_OK) { + LOG(("failed to convert to local encoding, return %d", ret)); + return false; + } + + out = fopen(path, "w"); + if (out) { + int res = fputs(conv, out); + if (res < 0) { + LOG(("Warning: writing data failed")); + } + + res = fputs("\n", out); + fclose(out); + free(conv); + return (res != EOF); + } + free(conv); + + return false; +} + + diff --git a/utils/utf8.h b/utils/utf8.h index 22aee1afa..a48d47d55 100644 --- a/utils/utf8.h +++ b/utils/utf8.h @@ -50,6 +50,8 @@ utf8_convert_ret utf8_from_enc(const char *string, const char *encname, utf8_convert_ret utf8_to_html(const char *string, const char *encname, size_t len, char **result); +bool utf8_save_text(const char *utf8_text, const char *path); + /* These two are platform specific */ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, char **result); -- cgit v1.2.3