diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2016-10-22 11:31:49 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2016-10-22 11:31:49 +0200 |
commit | 23ad94073f4c2f7131fa0c95b6202f2f9027db41 (patch) | |
tree | 4f4e1e27a22ace8fea49b63030d4462db7cb68a1 /src/lib | |
parent | 255bf78b316a9dc9e4c53a65143000471a6927d3 (diff) |
use standard types uintptr_t, char16_t and char32_t instead of FPTR, utf16_char, unicode_char (nw)
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/util/corefile.cpp | 4 | ||||
-rw-r--r-- | src/lib/util/un7z.cpp | 4 | ||||
-rw-r--r-- | src/lib/util/unicode.cpp | 30 | ||||
-rw-r--r-- | src/lib/util/unicode.h | 30 |
4 files changed, 29 insertions, 39 deletions
diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 54dbca51813..699ef91027b 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -410,8 +410,8 @@ int core_text_file::getc() } // fetch the next character - utf16_char utf16_buffer[UTF16_CHAR_MAX]; - unicode_char uchar = unicode_char(~0); + char16_t utf16_buffer[UTF16_CHAR_MAX]; + char32_t uchar = char32_t(~0); switch (m_text_type) { default: diff --git a/src/lib/util/un7z.cpp b/src/lib/util/un7z.cpp index 33a9c3f51db..7af3e7f78ce 100644 --- a/src/lib/util/un7z.cpp +++ b/src/lib/util/un7z.cpp @@ -184,7 +184,7 @@ private: std::uint32_t m_curr_crc; // current file crc std::vector<UInt16> m_utf16_buf; - std::vector<unicode_char> m_uchar_buf; + std::vector<char32_t> m_uchar_buf; std::vector<char> m_utf8_buf; CFileInStream m_archive_stream; @@ -479,7 +479,7 @@ void m7z_file_impl::make_utf8_name(int index) out_pos = 0; for (std::size_t in_pos = 0; in_pos < (len - 1); ) { - const int used = uchar_from_utf16(&m_uchar_buf[out_pos], &m_utf16_buf[in_pos], len - in_pos); + const int used = uchar_from_utf16(&m_uchar_buf[out_pos], (char16_t *)&m_utf16_buf[in_pos], len - in_pos); if (used < 0) { in_pos++; diff --git a/src/lib/util/unicode.cpp b/src/lib/util/unicode.cpp index 65936e10b48..a6c5515fbf6 100644 --- a/src/lib/util/unicode.cpp +++ b/src/lib/util/unicode.cpp @@ -16,7 +16,7 @@ // character is a legitimate unicode character //------------------------------------------------- -bool uchar_isvalid(unicode_char uchar) +bool uchar_isvalid(char32_t uchar) { return (uchar < 0x110000) && !((uchar >= 0xd800) && (uchar <= 0xdfff)); } @@ -27,7 +27,7 @@ bool uchar_isvalid(unicode_char uchar) // char is printable //------------------------------------------------- -bool uchar_is_printable(unicode_char uchar) +bool uchar_is_printable(char32_t uchar) { return !(0x0001f >= uchar) && // C0 control @@ -43,7 +43,7 @@ bool uchar_is_printable(unicode_char uchar) // char is a digit //------------------------------------------------- -bool uchar_is_digit(unicode_char uchar) +bool uchar_is_digit(char32_t uchar) { return uchar >= '0' && uchar <= '9'; } @@ -54,9 +54,9 @@ bool uchar_is_digit(unicode_char uchar) // into a unicode character //----------------------------------------------- -int uchar_from_utf8(unicode_char *uchar, const char *utf8char, size_t count) +int uchar_from_utf8(char32_t *uchar, const char *utf8char, size_t count) { - unicode_char c, minchar; + char32_t c, minchar; int auxlen, i; char auxchar; @@ -149,7 +149,7 @@ int uchar_from_utf8(unicode_char *uchar, const char *utf8char, size_t count) // into a unicode character //------------------------------------------------- -int uchar_from_utf16(unicode_char *uchar, const utf16_char *utf16char, size_t count) +int uchar_from_utf16(char32_t *uchar, const char16_t *utf16char, size_t count) { int rc = -1; @@ -184,9 +184,9 @@ int uchar_from_utf16(unicode_char *uchar, const utf16_char *utf16char, size_t co // byte order //------------------------------------------------- -int uchar_from_utf16f(unicode_char *uchar, const utf16_char *utf16char, size_t count) +int uchar_from_utf16f(char32_t *uchar, const char16_t *utf16char, size_t count) { - utf16_char buf[2] = {0}; + char16_t buf[2] = {0}; if (count > 0) buf[0] = flipendian_int16(utf16char[0]); if (count > 1) @@ -200,7 +200,7 @@ int uchar_from_utf16f(unicode_char *uchar, const utf16_char *utf16char, size_t c // into a UTF-8 sequence //------------------------------------------------- -int utf8_from_uchar(char *utf8string, size_t count, unicode_char uchar) +int utf8_from_uchar(char *utf8string, size_t count, char32_t uchar) { int rc = 0; @@ -278,7 +278,7 @@ int utf8_from_uchar(char *utf8string, size_t count, unicode_char uchar) // into a UTF-8 sequence //------------------------------------------------- -std::string utf8_from_uchar(unicode_char uchar) +std::string utf8_from_uchar(char32_t uchar) { char buffer[UTF8_CHAR_MAX]; auto len = utf8_from_uchar(buffer, ARRAY_LENGTH(buffer), uchar); @@ -291,7 +291,7 @@ std::string utf8_from_uchar(unicode_char uchar) // into a UTF-16 sequence //------------------------------------------------- -int utf16_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) +int utf16_from_uchar(char16_t *utf16string, size_t count, char32_t uchar) { int rc; @@ -304,7 +304,7 @@ int utf16_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) // single word case if (count < 1) return -1; - utf16string[0] = (utf16_char) uchar; + utf16string[0] = (char16_t) uchar; rc = 1; } else if (uchar < 0x100000) @@ -330,10 +330,10 @@ int utf16_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) // into a UTF-16 sequence with flipped endianness //------------------------------------------------- -int utf16f_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) +int utf16f_from_uchar(char16_t *utf16string, size_t count, char32_t uchar) { int rc; - utf16_char buf[2] = { 0, 0 }; + char16_t buf[2] = { 0, 0 }; rc = utf16_from_uchar(buf, count, uchar); @@ -390,7 +390,7 @@ bool utf8_is_valid_string(const char *utf8string) while (*utf8string != 0) { - unicode_char uchar = 0; + char32_t uchar = 0; int charlen; // extract the current character and verify it diff --git a/src/lib/util/unicode.h b/src/lib/util/unicode.h index 152e76826c2..5cc6db383ee 100644 --- a/src/lib/util/unicode.h +++ b/src/lib/util/unicode.h @@ -73,39 +73,29 @@ #define UTF8_DOWN "\xe2\x86\x93" /* cursor down */ - -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -typedef UINT16 utf16_char; -typedef UINT32 unicode_char; - - - /*************************************************************************** FUNCTION PROTOTYPES ***************************************************************************/ // tests to see if a unicode char is a valid code point -bool uchar_isvalid(unicode_char uchar); +bool uchar_isvalid(char32_t uchar); // tests to see if a unicode char is printable -bool uchar_is_printable(unicode_char uchar); +bool uchar_is_printable(char32_t uchar); // tests to see if a unicode char is a digit -bool uchar_is_digit(unicode_char uchar); +bool uchar_is_digit(char32_t uchar); // converting strings to 32-bit Unicode chars -int uchar_from_utf8(unicode_char *uchar, const char *utf8char, size_t count); -int uchar_from_utf16(unicode_char *uchar, const utf16_char *utf16char, size_t count); -int uchar_from_utf16f(unicode_char *uchar, const utf16_char *utf16char, size_t count); +int uchar_from_utf8(char32_t *uchar, const char *utf8char, size_t count); +int uchar_from_utf16(char32_t *uchar, const char16_t *utf16char, size_t count); +int uchar_from_utf16f(char32_t *uchar, const char16_t *utf16char, size_t count); // converting 32-bit Unicode chars to strings -int utf8_from_uchar(char *utf8string, size_t count, unicode_char uchar); -std::string utf8_from_uchar(unicode_char uchar); -int utf16_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar); -int utf16f_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar); +int utf8_from_uchar(char *utf8string, size_t count, char32_t uchar); +std::string utf8_from_uchar(char32_t uchar); +int utf16_from_uchar(char16_t *utf16string, size_t count, char32_t uchar); +int utf16f_from_uchar(char16_t *utf16string, size_t count, char32_t uchar); // misc UTF-8 helpers const char *utf8_previous_char(const char *utf8string); |