diff options
author | Vincent Sanders <vince@kyllikki.org> | 2014-02-01 22:17:36 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2014-02-01 22:17:36 +0000 |
commit | 886a3106db6d6a60d2d706d2caad3e883dd70b14 (patch) | |
tree | 0fcd0fb9c8821f06d47e7e20e8c796e085e8aa2b /desktop/gui_factory.c | |
parent | 427f127fa9d42cdf9005d06813c580d18d5e0d6a (diff) | |
download | netsurf-886a3106db6d6a60d2d706d2caad3e883dd70b14.tar.gz netsurf-886a3106db6d6a60d2d706d2caad3e883dd70b14.tar.bz2 |
move utf8 local conversion operations to table
Diffstat (limited to 'desktop/gui_factory.c')
-rw-r--r-- | desktop/gui_factory.c | 83 |
1 files changed, 70 insertions, 13 deletions
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index b61fdf0be..8996ab5d6 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -272,6 +272,11 @@ static void gui_default_set_clipboard(const char *buffer, size_t length, { } +static struct gui_clipboard_table default_clipboard_table = { + .get = gui_default_get_clipboard, + .set = gui_default_set_clipboard, +}; + /** verify clipboard table is valid */ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) { @@ -290,6 +295,54 @@ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) return NSERROR_OK; } +/** + * The default utf8 conversion implementation. + * + * The default implementation assumes the local encoding is utf8 + * allowing the conversion to be a simple copy. + * + * @param [in] string The source string. + * @param [in] len The \a string length or 0 to compute it. + * @param [out] result A pointer to the converted string. + * @result NSERROR_OK or NSERROR_NOMEM if memory could not be allocated. + */ +static nserror gui_default_utf8(const char *string, size_t len, char **result) +{ + assert(string && result); + + if (len == 0) + len = strlen(string); + + *result = strndup(string, len); + if (!(*result)) + return NSERROR_NOMEM; + + return NSERROR_OK; +} + +static struct gui_utf8_table default_utf8_table = { + .utf8_to_local = gui_default_utf8, + .local_to_utf8 = gui_default_utf8, +}; + +/** verify clipboard table is valid */ +static nserror verify_utf8_register(struct gui_utf8_table *gut) +{ + /* check table is present */ + if (gut == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* mandantory operations */ + if (gut->utf8_to_local == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gut->local_to_utf8 == NULL) { + return NSERROR_BAD_PARAMETER; + } + return NSERROR_OK; +} + static nsurl *gui_default_get_resource_url(const char *path) { return NULL; @@ -370,6 +423,13 @@ static void gui_default_401login_open(nsurl *url, const char *realm, cb(false, cbpw); } +static struct gui_download_table default_download_table = { + .create = gui_default_download_create, + .data = gui_default_download_data, + .error = gui_default_download_error, + .done = gui_default_download_done, +}; + /** verify browser table is valid */ static nserror verify_browser_register(struct gui_browser_table *gbt) { @@ -406,19 +466,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) } - -static struct gui_download_table default_download_table = { - .create = gui_default_download_create, - .data = gui_default_download_data, - .error = gui_default_download_error, - .done = gui_default_download_done, -}; - -static struct gui_clipboard_table default_clipboard_table = { - .get = gui_default_get_clipboard, - .set = gui_default_set_clipboard, -}; - /* exported interface documented in desktop/gui_factory.h */ nserror gui_factory_register(struct gui_table *gt) { @@ -472,6 +519,16 @@ nserror gui_factory_register(struct gui_table *gt) return err; } + /* utf8 table */ + if (gt->utf8 == NULL) { + /* set default clipboard table */ + gt->utf8 = &default_utf8_table; + } + err = verify_utf8_register(gt->utf8); + if (err != NSERROR_OK) { + return err; + } + guit = gt; return NSERROR_OK; |