Sorry, does anybody know if wxFileConfig can be forced to use UTF-8 (assuming it uses system locale) and if APIs accepts C-strings, then is it possible to avoid wxString::FromUTF8 by communicating that C-strings are UTF8? If so, how? If not, C-strings are not so useful I guess.
I suppose any Unicode format is acceptable. I'm worried about loss on the config file front.
Also (sorry) is there a systemwide switch (similar to locale) to control the format of file paths? Like to request paths as URLs or to not use backslashes?
Best: wxFileConfig encoding, wxString UTF8 C-strings
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
Pass wxConvUTF8 as "conv" parameter to its ctor.does anybody know if wxFileConfig can be forced to use UTF-8 (assuming it uses system locale)
No. It only takes wxString as parameters. If you were to pass a C string if would be implicitly converted to wxString using locale encoding.if APIs accepts C-strings
No. As paths are usually not shared across platforms, that should not be an issue though. What exactly is the problem? wxFileName has a few methods that should help to build paths for the current platform, e.g. wxFileName::GetPathSeparator()is there a systemwide switch (similar to locale) to control the format of file paths? Like to request paths as URLs or to not use backslashes?
Use the source, Luke!
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
Thanks. I was hoping for a tip on how to override the locale. On the other point, it's just simpler to work with standard paths, or URLs like I say, that are standard.
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
Off-topic: I think SetRecordDefaults is not working. I dunno. The INI file only has values that are modified by Set APIs.
Code: Select all
const wxString &_ = wxEmptyString;
if(i==cfg.size())
cfg.push_back(std::make_pair(name,new wxFileConfig(name,_,_,_,wxCONFIG_USE_LOCAL_FILE,wxConvUTF8)));
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
I don't see how this comment is related to the code you posted. Can you elaborate?I think SetRecordDefaults is not working. I dunno. The INI file only has values that are modified by Set APIs.
Use the source, Luke!
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
SetRecordDefaults is a method of wxFileConfig's. I don't want to make a post about this, but thought someone might see it and take mercy on me.
It seems to be a feature that is unimplemented.
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
Looking into the sources, i'd say it is implemented. But maybe this method does not what you think it does.It seems to be a feature that is unimplemented.
What it does is: SetRecordDefaults() just sets an internal flag. If you make a wxConfig::Read() call and the record does not exist and this flag is set, the record will be created with the default value passed to the Read() call.
Use the source, Luke!
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
I actually have two INI files, and I just noticed the second is working as expected. As near as I tell it is likely not implemented for most implementations of Read. There are several overloads, maybe 10s. The ones that deal with binary data types don't seem to work with this feature. The secondary INI file saves hotkeys, and always uses a string version of Read. That seems to be the only version that works (with SetRecordDefaults) that I'm using.doublemax wrote: ↑Fri Sep 06, 2019 12:26 pmLooking into the sources, i'd say it is implemented. But maybe this method does not what you think it does.It seems to be a feature that is unimplemented.
What it does is: SetRecordDefaults() just sets an internal flag. If you make a wxConfig::Read() call and the record does not exist and this flag is set, the record will be created with the default value passed to the Read() call.
Code: Select all
void configure::_get(const char *key, void *val, int lt)
{
wxFileConfig *s = xcv_cfg(name).second; switch(lt)
{
default: assert(0); break;
case ui_live_int: s->Read(key,(int*)val); break;
case ui_live_float: s->Read(key,(float*)val); break;
case ui_live_double: s->Read(key,(double*)val); break;
case 0: //case ui_live_text:
//TODO: Is FromUTF8 required in this case?
//https://forums.wxwidgets.org/viewtopic.php?f=1&t=46272&p=193659
temporary = s->Read(key,wxString::FromUTF8((char*)val)).ToUTF8();
break;
case ui_live_char:
const char buf[2] = {*(char*)val}; //const is required.
*(char*)val = (char)s->Read(key,buf)[0]; break;
}
}
EDITED: If I had to guess (in hindsight) I suppose the semantics of these is that the value pointed to is only to receive the read value, and so it's not considered a default. I went to look them up in the code, with reverse search, and I see there are versions that accept a default in addition to the pointer. Kind of a mess.
Re: Best: wxFileConfig encoding, wxString UTF8 C-strings
Hi,
Did you post the code that is working, ro the one you think it does not?
Also, what type of data do you save in the "non-working" INI file? The fact that you store pointer to some data doesn't help much...
Thank you.
Did you post the code that is working, ro the one you think it does not?
Also, what type of data do you save in the "non-working" INI file? The fact that you store pointer to some data doesn't help much...
Thank you.