Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
issue on NullLoader class
Jenna:
--- Quote from: blueshake on December 04, 2009, 06:00:57 am ---
--- Quote ---Nevertheless this code should be changed to something that works correctly (or removed), but I think it can make sense to have it.
--- End quote ---
Waiting for your good news.
--- End quote ---
To make it clear: the code to change is not the NullLoader code (in my opinion), but the code that uses it.
But I don't think I find the time to dig into it soon.
blueshake:
it is Ok if NullLoader class can load the text from the Editor when I set the args to true.
Anyway thanks your effort.
Jenna:
This snippet (FileManager::Load) copies the bytes, m_pchData points to, into NullLoader's data, so no crash anymore (I'm not sure if everything is correct, as written before I have no time, to work on it seriously).
--- Code: --- if(ed && fileName == ed->GetFilename())
{
wxString s(ed->GetControl()->GetText());
int len = s.length() + 1;
NullLoader *nl = new NullLoader(file, (char*)wxStrcpy(new wxChar[len], s.c_str()), len * sizeof(wxChar));
return nl;
}
--- End code ---
But you get a problem here:
If I see it correctly, FileLoader loads the content of the files into data (byte by byte from disk), but the editors hold a widechar-string (at least in unicode-builds), so loading a file from disk or via fileloader does not lead to the same content automatically and parsing might fail (happens here for example).
blueshake:
hi,jens:
just as what visualFc do ,what about using this way?
NullLoader *nl = new NullLoader(file, strcpy(new char[len* sizeof(wxChar)], (const char*)s.mb_str()), len * sizeof(wxChar));
thomas:
--- Quote from: blueshake on December 04, 2009, 11:18:35 am ---it is Ok if NullLoader class can load the text from the Editor when I set the args to true.
--- End quote ---
No, because then it is not a NullLoader any more. However, if you insist of doing a fix on loader level, you can write a class like this:
class EditorReuser : public LoaderBase
{
EditorReuser(cbEditor const& e)
{
wxString s(e.GetControl()->GetText());
fileName = e.GetFilename();
data = new char[s.length() * sizeof(wxChar)];
len = s.length() * sizeof(wxChar);
Ready();
}
void operator()(){};
};
Then use a EditorReuser instead of a NullLoader.
Note: not checked for typos or correctness.
Edit: also note that you may have to convert the editor's text, since that will be Unicode characters, not UTF-8 or some Windows codepage (which the parser might expect). Or, you will have to tell the parser that the encoding is Unicode.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version