diff options
author | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2011-03-28 06:59:20 -0400 |
---|---|---|
committer | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2011-03-28 06:59:20 -0400 |
commit | 15cf835cc555018bed865071cb9f5bcdb6b75060 (patch) | |
tree | 69c3312f104e2ff1a60255b63fc7f6ae34cae494 /libarchive/archive_string.h | |
parent | f74c5f05faccec9b0946faa3f3fbe41fab276a26 (diff) | |
download | libarchive-15cf835cc555018bed865071cb9f5bcdb6b75060.tar.gz |
Improve character-set conversion functions.
- Change the interface in order to reduece the comparison of
charset names. Previous version always did it when the functions
were called; it was very inefficient. So I have made a conversion
object, struct archive_string_conv, to resolve that issue.
- Integrate *_from_charset and *_to_charset into *_in_locale because
of above.
- Integrate *_from_utf16be and *_to_utf16be into *in_locale.
- On Windows, Make a codepage from a charset name to know whether
current codepage and specified charset are the same or not.
SVN-Revision: 3108
Diffstat (limited to 'libarchive/archive_string.h')
-rw-r--r-- | libarchive/archive_string.h | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/libarchive/archive_string.h b/libarchive/archive_string.h index b5b6e6da..15e55c82 100644 --- a/libarchive/archive_string.h +++ b/libarchive/archive_string.h @@ -65,6 +65,8 @@ struct archive_wstring { size_t buffer_length; /* Length of malloc-ed storage in bytes. */ }; +struct archive_string_conv; + /* Initialize an archive_string object on the stack or elsewhere. */ #define archive_string_init(a) \ do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0) @@ -77,52 +79,35 @@ archive_strappend_char(struct archive_string *, char); struct archive_wstring * archive_wstrappend_wchar(struct archive_wstring *, wchar_t); -/* Convert a Unicode string to UTF-8 and append the result. */ -int -archive_string_append_from_unicode_to_utf8(struct archive_string *, const wchar_t *, size_t); - /* Convert a Unicode string to current locale and append the result. */ /* Returns -1 if conversion fails. */ int archive_string_append_from_unicode_to_mbs(struct archive *, struct archive_string *, const wchar_t *, size_t); -/* Convert a UTF-16BE string to current locale and copy the result. - * Return -1 if conversion failes. */ -int -archive_strncpy_from_utf16be(struct archive *, - struct archive_string *, const char *, size_t); - -/* Convert a current locale string to UTF-16BE and copy the result. - * Return -1 if conversion failes. */ -int -archive_strncpy_to_utf16be(struct archive *, - struct archive_string *, const char *, size_t); - /* Test that platform support a character-set conversion. * Return -1 and set a error message if the conversion is not supported. */ -int -archive_string_conversion_to_charset(struct archive *, const char *); -int -archive_string_conversion_from_charset(struct archive *, const char *); +struct archive_string_conv * +archive_string_conversion_to_charset(struct archive *, const char *, int); +struct archive_string_conv * +archive_string_conversion_from_charset(struct archive *, const char *, int); +void +archive_string_conversion_free(struct archive *); +const char * +archive_string_conversion_charset_name(struct archive_string_conv *); -/* Convert MBS from specific locale to current locale and copy the result. + +/* Copy one archive_string to another in locale conversion. * Return -1 if conversion failes. */ int -archive_strncat_from_locale(struct archive *, - struct archive_string *, const void *, size_t, const char *); -int -archive_strncpy_from_locale(struct archive *, - struct archive_string *, const void *, size_t, const char *); +archive_strncpy_in_locale(struct archive_string *, const void *, size_t, + struct archive_string_conv *); -/* Convert MBS from current locale to specific locale and copy the result. +/* Copy one archive_string to another in locale conversion. * Return -1 if conversion failes. */ int -archive_strncat_to_locale(struct archive *, - struct archive_string *, const void *, size_t, const char *); -int -archive_strncpy_to_locale(struct archive *, - struct archive_string *, const void *, size_t, const char *); +archive_strncat_in_locale(struct archive_string *, const void *, size_t, + struct archive_string_conv *); /* Copy one archive_string to another */ @@ -162,10 +147,8 @@ archive_wstrcat(struct archive_wstring *, const wchar_t *); archive_strncpy((as), (p), ((p) == NULL ? 0 : strlen(p))) #define archive_wstrcpy(as,p) \ archive_wstrncpy((as), (p), ((p) == NULL ? 0 : wcslen(p))) -#define archive_strcpy_from_locale(a,as,p,lo) \ - archive_strncpy_from_locale((a), (as), (p), ((p) == NULL ? 0 : strlen(p)), (lo)) -#define archive_strcpy_to_locale(a,as,p,lo) \ - archive_strncpy_to_locale((a), (as), (p), ((p) == NULL ? 0 : strlen(p)), (lo)) +#define archive_strcpy_in_locale(as,p,lo) \ + archive_strncpy_in_locale((as), (p), ((p) == NULL ? 0 : strlen(p)), (lo)) /* Copy a C string to an archive_string with limit, resizing as necessary. */ #define archive_strncpy(as,p,l) \ |