#include "util_utf.h"
+#include <cassert>
#include <cstring>
#define DSTATE_FIRST 0
* returns: true or false
*/
-bool UtfDecodeSession::DecodeUTF16LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF16LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
int* bytes_copied)
{
- const char* src_index = src;
- char* dst_index = dst;
+ const uint8_t* src_index = src;
+ uint8_t* dst_index = dst;
bool result = true;
while ((src_index < (src + src_len)) &&
dstate.state = DSTATE_SECOND;
break;
case DSTATE_SECOND:
- if (*src_index++ > 0)
+ if (*src_index++ != 0)
result = false;
dstate.state = DSTATE_FIRST;
break;
default:
- return false;
+ assert(false);
}
}
* returns: true or false
*/
-bool UtfDecodeSession::DecodeUTF16BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF16BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
int* bytes_copied)
{
- const char* src_index = src;
- char* dst_index = dst;
+ const uint8_t* src_index = src;
+ uint8_t* dst_index = dst;
bool result = true;
while ((src_index < (src + src_len)) &&
switch (dstate.state)
{
case DSTATE_FIRST:
- if (*src_index++ > 0)
+ if (*src_index++ != 0)
result = false;
dstate.state = DSTATE_SECOND;
break;
dstate.state = DSTATE_FIRST;
break;
default:
- return false;
+ assert(false);
}
}
* returns: true or false
*/
-bool UtfDecodeSession::DecodeUTF32LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF32LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
int* bytes_copied)
{
- const char* src_index = src;
- char* dst_index = dst;
+ const uint8_t* src_index = src;
+ uint8_t* dst_index = dst;
bool result = true;
while ((src_index < (src + src_len)) &&
case DSTATE_SECOND:
case DSTATE_THIRD:
case DSTATE_FOURTH:
- if (*src_index++ > 0)
+ if (*src_index++ != 0)
result = false;
if (dstate.state == DSTATE_FOURTH)
dstate.state = DSTATE_FIRST;
dstate.state++;
break;
default:
- return false;
+ assert(false);
}
}
* returns: true or false
*/
-bool UtfDecodeSession::DecodeUTF32BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len,
+bool UtfDecodeSession::DecodeUTF32BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len,
int* bytes_copied)
{
- const char* src_index = src;
- char* dst_index = dst;
+ const uint8_t* src_index = src;
+ uint8_t* dst_index = dst;
bool result = true;
while ((src_index < (src + src_len)) &&
case DSTATE_FIRST:
case DSTATE_SECOND:
case DSTATE_THIRD:
- if (*src_index++ > 0)
+ if (*src_index++ != 0)
result = false;
dstate.state++;
break;
dstate.state = DSTATE_FIRST;
break;
default:
- return false;
+ assert(false);
}
}
return result;
}
-void UtfDecodeSession::determine_charset(const char** src, unsigned int *src_len)
+void UtfDecodeSession::determine_charset(const uint8_t** src, unsigned int *src_len)
{
CharsetCode charset;
if (dstate.charset == CHARSET_UNKNOWN)
/* Wrapper function for DecodeUTF{16,32}{LE,BE} */
bool UtfDecodeSession::decode_utf(
- const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied)
+ const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied)
{
*bytes_copied = 0;
void set_decode_utf_state_charset(CharsetCode charset);
CharsetCode get_decode_utf_state_charset();
bool is_utf_encoding_present();
- bool decode_utf(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
+ bool decode_utf(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
private:
decode_utf_state_t dstate;
- bool DecodeUTF16LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
- bool DecodeUTF16BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
- bool DecodeUTF32LE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
- bool DecodeUTF32BE(const char* src, unsigned int src_len, char* dst, unsigned int dst_len, int* bytes_copied);
- void determine_charset(const char** src, unsigned int *src_len);
+ bool DecodeUTF16LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+ bool DecodeUTF16BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+ bool DecodeUTF32LE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+ bool DecodeUTF32BE(const uint8_t* src, unsigned int src_len, uint8_t* dst, unsigned int dst_len, int* bytes_copied);
+ void determine_charset(const uint8_t** src, unsigned int *src_len);
};
#endif