Add CSNAP pattern#532
Conversation
|
Hello, I looked at the pattern and downloaded you app. I have some questions and suggestions that in my opinion will make it easier to maintain and expand the pattern to include more types of data. For that purpose you can swap the function to convert ids to formats with an enumeration. The enumeration format automatically defaults to the enumeration names which makes the translation both practical and faster except for two differences with your code. The default format includes the enumeration name as e.g. First the enum is much simpler and easier to add new entries. enum ID : u32 {
CF_TEXT = 1,
CF_BITMAP,
CF_METAFILEPICT,
CF_SYLK,
CF_DIF,
CF_TIFF,
CF_OEMTEXT,
CF_DIB,
CF_PALETTE,
CF_PENDATA,
CF_RIFF,
CF_WAVE,
CF_UNICODETEXT,
CF_ENHMETAFILE,
CF_HDROP,
CF_LOCALE,
CF_DIBV5,
CF_OWNERDISPLAY = 0x80,
CF_DSPTEXT,
CF_DSPBITMAP,
CF_DSPMETAFILEPICT,
CF_DSPENHMETAFILE = 0x8E,
};The rest of the code is the same except for the format function. fn id_to_format(auto v) {
ID id = v;
str result = std::format("{}",id);
u32 resultLength = std::string::length(result)-4;
result = std::string::substr(result,4,resultLength);
if (result == "???")
return std::format("{:#X} {}",v,v);
return result;
};The function converts the u32 value to an enum then converts that to a string that has the extra stuff trimmed. Finally the function formats values that end up as question marks. Again these are only suggestions that you don't need to accept if you don't want to. The questions are two, First about the reason why you are calculating all the time formats from scratch when the pattern language provides types and functions to do it for you and do it faster in c++ compiled code. The following three lines are equivalent to all the date and time code you added and it results in better looking format. type::FILETIME filetimeTakenUtc[[format("to_utc")]];
fn to_utc(auto v) {
type::time64_t unix_time = std::time::filetime_to_unix(v);
return type::impl::format_time_t(unix_time);
};This prints the date/time as If you decide you want to use these suggestions you will need some imports as well: import std.io;
import std.core;
import std.time;
import type.time;
import std.string;The final question is about the file uploaded as a test input for the pattern. I had to download your app to create a test file because the file uploaded seems to be a copy of the pattern instead of a valid csnap file. Your app ran very well and it looks like it would be useful and it is well done. If you could please upload a valid test file then the pattern can be added to the library right away. Thanks! |
|
yes, i mention that in the write-up and showed how to resolve it. Perhaps you missed that part? It is not important, but wanted to make that clear. I'll merge it as soon as the tests pass. Thanks again. |
|
Your pattern is failing unit tests. Based on the error message it looks like it is missing a required pragma description that all patterns in the library must have. |
|
Ok, now the formats use an enum, and I also added the required #pragmas. |
Adds the pattern for the clipboard snapshot format from my new app ClipboardEdit