|
I've posted this question to the tokenizer class itself.. but the article is pretty old and the author put an updated version on boost (i don't want to want any discussions on boost.. it is a great lib.. but i don't wanna use the whole shebang just for string tokenization).. but i want to use the version, which is downloadable on codeproject..
my problem:
i want to use the tokenizer in some classes in my project.. if i include the header a second time the linker says that the symbols:
const char* WT_Whitespace = " \t\n";
const char* WT_Punctuation1 = "/?.>,<\'\";:\\|]}[{=+-_)(*&^%$#@!`~";
const char* WT_Punctuation2 = "/?.>,<\";:\\|]}[{=+_)(*&^%$#@!`~";
are already defined in another obj file (the first file i've included the header.
(those are constants he put in his namespace.. the tokenizer is just one single header file)
any quick ideas (without using the whole boost stuff, otherwise i start using strtok again)?
bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
The problem is that all files that include this header will define space for these constants. I would make my own cpp file and put the constants in there as they are in the header and in the header put an extern before constant and remove the everything between the = and the ;
John
|
|
|
|
|
I am reading a text file using the ReadFile API into a char buffer.
I need to support ANSI and UNICODE (UTF, etc)
When the file is unicode it needs to be convered to ANSI.
I did not find any functions which I could use to detect if the file I am reading is an ANSI or UNICODE.
Are there any such functions? If not, what is the best way to detect this?
Thanks
Jeremy Pullicino
C++ Developer
Homepage
|
|
|
|
|
I've been looking for something like this too.
Notepad (on W2k) adds 0xFF, 0xFE to a UNICODE file, so if your files are created by it (or by something you can change to prepend that to the file) you can look for that.
Otherwise, the only good method I know is if you know that the codepage is ANSI, then you can check if the first 10 (or more) even bytes are 0 or not. That should give you an idea if its unicode or not.
Jonas
“Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002
|
|
|
|
|
As far as I know, there are no functions to do this. Most applications that have text conversions require the user to manually specify what type the file is. You could scan the file and try and detect some ANSI sequences, and you can generally tell if a file is unicode by looking at the first 4 bytes, but this is optional and a file may not adhere to it.
|
|
|
|
|
How about the IsTextUnicode function - I just came across it... it might do the trick...
Jeremy Pullicino
C++ Developer
Homepage
|
|
|
|
|
Aha, an interesting function! Although it does say 'uses statistical analysis... these tests are not foolproof' - even Microsoft are at a loss sometimes! It will certainly be easier than writing your own though, provided you dont want to support Win9x
|
|
|
|
|
I also use the WinAPI function IsTextUnicode to test if a given text is unicode encoded or not.
There is no full proof detection method, also as pointed out by the reply below, it is HIGHLY recommended that all unicode text be prefixed by the 0xFEFF (or 0xFFFE) header to indicate the encoding. But this may not always be the case (for misbehaving progs).
The IsTextUnicode function, can then use a combination of statistical methods to give a probability estimate on the likely-hood of the given text being unicode.
I've used it in my programs and have had good results.
The best you could probably do is in addition to using these detection method, is to have a fallback in your program to force treating any known file as UNICODE or ANSI encoded.
"..Even my comments have bugs!"
Inspired by Toni78
|
|
|
|
|
The accepted UNICODE convention is that a UNICODE file begins with the bytes 0xff,0xfe or 0xfe,0xff depending on whether it was produced on a big-endian or little-endian platform.
It's not a standard, but is endorsed by the UNICODE consortium and is practically an industry standard.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
However, I will need to put the text that I read into a string so that I could perform string manipulation on it.
So I will need to know if it is ansi or unicode in order to perform the appropriate conversion to ansi if it is unicode.
... correct me if I am wrong!
Jeremy Pullicino
C++ Developer
Homepage
|
|
|
|
|
OpenStreamOnFile is a MAPI function - I would not like to use MAPI - is there an equivalent function that is not part of MAPI?
Jeremy Pullicino
C++ Developer
Homepage
|
|
|
|
|
It seems to happen quite frequently in my MFC projects that the dropdown list in ClassWizard has only a subset of the classes in the project, for example if I have multiple Views, most of them are missing. The ClassView of VC6 shows all of them correctly. This makes it a pain to add message handlers etc, although I can do it by right-clicking on the ClassView.
Does anyone understand this - is it a bug or a feature? Can I fix it?
thanks for any help.
|
|
|
|
|
There are several things to consider. Make sure you have all the //{{AFX_VIRTUAL and //{{AFX_MSG blocks filled in correctly. If your project does not have a lot of files in different directories you may want to rebuild the .clw file. You can do this by deleting the .clw file and then clicking ctrl-w. One think that I do is open the .clw file in a text editor and add the missing classes. After a quick inspection you should figure out what is needed.
John
|
|
|
|
|
John,
thanks very much, deleting the .clw file and rebuilding the ClassWizard data did the trick.
regards
Andrew
|
|
|
|
|
I have an MFC app and I want to use a dialog to filter data in the document. But how do I get hold of GetDocument()? All I can find that almost works is to use in OnInitDialog
CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument();
ie I try to get it via my View, but this fails with
error C2352: 'CView::GetDocument' : illegal call of non-static member function
Which seems to be saying that OnInitDialog() is a static function. It is declared normally
virtual BOOL OnInitDialog();
How do I sort this out? And where is this kind of nonsense explained? Thanks in advance for any help.
|
|
|
|
|
Mister Transistor wrote:
CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument();
You are calling GetDocument as a static function (shown by the ::GetDocument). What you need to do here is get pointer to the class that contains the docuement, and call the GetDocument from that pointer. So it'd be something like this:
CLeftPaneView *pLeftView;
CTransistDoc *pDoc;
CWnd* pWnd;
pWnd = m_wndSplitter.GetPane(0, 1);
pLeftView = DYNAMIC_DOWNCAST(CLeftPaneView, pWnd);
pLeftView = pDoc->GetDocument();
This is how I get my document pointers in order to manipulate my docuement information.
Hope this helps!
|
|
|
|
|
that's very interesting thank you ...
I think you mean
pDoc = pLeftView->GetDocument();
I'll try that shortly. Thanks again.
Andrew
|
|
|
|
|
Create another constructor in your dialog class that accepts a CDocument pointer. Then construct your dialog object like:
CMyDialog dlg(this);<br />
dlg.DoModal();
Now your dialog class can communicate with the document class with the saved pointer.
|
|
|
|
|
Ooo.
That's quick and easy. I like that! Thanks Dave!
|
|
|
|
|
will1383,
DavidCrow has a good idea, but remember that the default constructor for a dialog is:
CMyDialog(CWnd *pParent);
So you should create it like this:
CMyDialog dlg(this);
The this parameter being a pointer to the parent window. It is good practice to always set the parent for a dialog. Don't create them like this:
CMyDialog dlg;
If you do dialogs can sometimes not come to the top or fall behind other windows. So define your new constructor like so:
CMyDialog(CWnd *pParent, CMyDoc *pDoc);
Now create your dialog like this:
CMyDialog dlg(this, GetDocument());
Now you have the best of both.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Do you know of performance difference between new vs. CoTaskMemAlloc with explicit constructor call?
Reason is, I have to pass around CoTaskMemAlloc'ed arrays quite often, so I'm basically managing two different array classes (a legacy new one, and a CoTaskMemAlloc one). I seriously thing of changing the legacy one to use CoTaskMemAlloc, so I can Detach() a counted array.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
hello, I'm trying to implement drag and drop in my program, i'm using the drag nd drop classes by Leon Finker on CP. I had it working then noticed it now doesn't work, i have old source where it does work, but apart from things i changed in ftp classes etc there is not differnces, i've even copied the to window classes that implement drag and drop to the new src, and compiled it but still drag and drop fails. it fails on RegisterDragDrop the code i use is:
<br />
dropTarget = new DropTarget(m_hWnd);<br />
if (dropTarget == NULL)<br />
return false;<br />
<br />
dropTarget->AddRef();<br />
<br />
if (FAILED(RegisterDragDrop(m_hWnd, dropTarget))) {<br />
dropTarget = NULL;<br />
return false;<br />
}<br />
...<br />
This is from the drag and drop example Leon provides. and RegisterDragDrop always fails, but not in the other source, really annoying me. Anyone got any ideas of what this could be from? been trying to figure it out for ages!
thanks in advance for any help.
Luke
EDIT: I'm using the WTL framework if that helps or matters
|
|
|
|
|
Ok, very strange I have 2 list views that are trying to do the drag and drop, i also have a RichEditCtrl and in its create method it calls its SetReadOnly(TRUE); method. which makes RegisterDragDrop fail. So i put the readonly bit in the RichEdit.create(..., ES_READONLY) bit but that makes RegisterDragDrop fail. I think this is very weird, the RichEdit.create method gets called before the to listview get created, i'll try swaping them but, still this shouldn't be happening. any ideas?
Luke.
|
|
|
|
|
Hello,
I'm searching for a good explanation for Thread Safety and Brute Force Locking.
Mybe someone knows a good one or has an example.
Thanks, aenima
|
|
|
|
|
Hi all,
I need to know is there any windows API call avialable to query the Network Interface Cards in my pc. I also need to know what are the IP Address and subnet mask assigned to a particular NIC.
Thanks in advance.
|
|
|
|