add Win32 API Unicode converter, other small changes
Qt Example: add file.close() (consistency between GTK example) RagePhoto: saveFile() checks for good(), more data() -> c_str()
This commit is contained in:
parent
85ab850895
commit
05890541dc
6 changed files with 122 additions and 21 deletions
|
@ -59,5 +59,8 @@ int main(int argc, char *argv[])
|
|||
};
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
|
||||
std::string photoString = convert.to_bytes(reinterpret_cast<char16_t*>(photoHeader));
|
||||
if (convert.converted() == 0) {
|
||||
return -1;
|
||||
}
|
||||
return strcmp(photoString.c_str(), "PHOTO - 02/01/17 08:42:44");
|
||||
}
|
||||
|
|
|
@ -56,18 +56,18 @@ int main(int argc, char *argv[])
|
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
char photoString[256];
|
||||
char photoHeader_string[256];
|
||||
iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE");
|
||||
if (iconv_in == (iconv_t)-1)
|
||||
return -1;
|
||||
size_t src_s = sizeof(photoHeader);
|
||||
size_t dst_s = sizeof(photoString);
|
||||
size_t dst_s = sizeof(photoHeader_string);
|
||||
char *src = photoHeader;
|
||||
char *dst = photoString;
|
||||
char *dst = photoHeader_string;
|
||||
const size_t ret = iconv(iconv_in, &src, &src_s, &dst, &dst_s);
|
||||
iconv_close(iconv_in);
|
||||
if (ret == static_cast<size_t>(-1)) {
|
||||
return -1;
|
||||
}
|
||||
return strcmp(photoString, "PHOTO - 02/01/17 08:42:44");
|
||||
return strcmp(photoHeader_string, "PHOTO - 02/01/17 08:42:44");
|
||||
}
|
||||
|
|
64
tests/WincvtTest.cpp
Normal file
64
tests/WincvtTest.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*****************************************************************************
|
||||
* libragephoto RAGE Photo Parser
|
||||
* Copyright (C) 2021 Syping
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* This software is provided as-is, no warranties are given to you, we are not
|
||||
* responsible for anything with use of the software, you are self responsible.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <cstring>
|
||||
#include <stringapiset.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char photoHeader[256] = {
|
||||
0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00,
|
||||
0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00,
|
||||
0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00,
|
||||
0x31, 0x00, 0x2f, 0x00, 0x31, 0x00, 0x37, 0x00,
|
||||
0x20, 0x00, 0x30, 0x00, 0x38, 0x00, 0x3a, 0x00,
|
||||
0x34, 0x00, 0x32, 0x00, 0x3a, 0x00, 0x34, 0x00,
|
||||
0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
char photoHeader_string[256];
|
||||
const int converted = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<wchar_t*>(photoHeader), -1, photoHeader_string, 256, NULL, NULL);
|
||||
if (converted == 0) {
|
||||
return -1;
|
||||
}
|
||||
return strcmp(photoHeader_string, "PHOTO - 02/01/17 08:42:44");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue