|
I am looking for a way to correctly sort CStrings under Unicode.
Input:
Zéro
Ça
Cabane
Ouptut I get:
Cabane
Zéro
Ça
Output should be:
Cabane
Ça
Zéro
I have seen articles on the Unicode Collation Algorithm - Unicode Technical Standard #10, but how can I implement correct sorting with existing tools in Microsoft C++ MFC in a Unicode project? CompareNoCase and CollateNoCase do not give the expected correct result.
__________________
Peter M.C. Werner
Siscad SA
Route de l'Etraz 2
1183 Bursins, Switzerland
www.cadelec.com
|
|
|
|
|
Are the CString sorting functions as Compare() buggy ???
Greetings from Germany
|
|
|
|
|
Whether you call it a bug is open to interpretation. I would indeed call it a bug, as they do not yield the results we should expect.
|
|
|
|
|
Each language has its own collection rules, just look at phonebooks for different countries or entries in a (book) dictionary. The machine sorting provided by the MFC functions is useless for human readers of languages other than English. The whole point about Unicode is its adaptability to different languages, but evidently Microsoft has not implemented the unicode collection rules.
|
|
|
|
|
It would surprise me if CString was implementing Unicode Technical Standard #10 - remember, it is just a template CStringT that gets specialized for char or wchar_t.
Can you use ICU[^]? It should have the functionallity you are looking for.
|
|
|
|
|
Thank you for the link. String comparison in the ICU Collation Demo works as I would expect. Questions:
- At first sight, ICU seems to be a Java tool
- How to implement their collation engine into a MFC C++ application. Has anybody got some hands-on experience?
|
|
|
|
|
petermcwerner wrote: - At first sight, ICU seems to be a Java tool
There is a C version, and a C++ one as well - see here[^]. Frankly, it is not the most elegant C++ code I have ever seen, but you can always wrap it into something better.
petermcwerner wrote: How to implement their collation engine into a MFC C++ application.
Here[^] is a sample.
|
|
|
|
|
Thank you Nemanja, I am going to study the links you provided.
Has somebody already implemented an MFC version so that I do not have to re-invent the wheel?
|
|
|
|
|
How are you currently sorting them?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
So have you stepped into the CSortableStringArray::Compare() method to see how it is comparing Ça and Zéro (e.g., returning -1 when it should be returning 1)?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have not gone into it, as it clearly does not do the job, not only in the small example I showed, but on larger data sets. From the results I would think that it works like this:
Z = U+005A
Ç = U+00C7
Thus Ç > Z
This is a purely machine sorting, what I need is a lexical sorting. The ICU Collator seems to work correctly, it seems the way to go. What I am looking for now is for some tips and/or example on how to implement it in MFC. If somebody has already done the job I would be glad for a complete example in order not to re-invent the wheel.
|
|
|
|
|
CollateNoCase calls (through the traits object in MFC 7.0 and later) _wcsicoll for a Unicode project. That uses the C locale set with setlocale. My understanding is that this defaults to the "C" locale, rather than the user's currently selected locale.
As far as I know, no Microsoft product truly implements the Unicode Collation Algorithm. Instead they are compatible with their own previous implementations, which ultimately predate UTS #10. It may be better to be compatible with other applications on the system, however.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
My first try using a Modeless dialog.
Say a pointer called m_pModelessDlg is used and after I allocate memory and construct this dialog,
I call
m_pModelessDlg->Create(ModelessDlg::IDD, this);
m_pModelessDlg->ShowWindow(SW_SHOW);
The blank dialog is displayed but all other controls on the dialog are not. Shouldn't all resources of that dialog be collected and constructed when Create is called?
I also tried to use DoModal to create a modal dialog using the same resources and everything was fine then.
Thanks in advance.
_Pinux_
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
|
Thanks.
I did read it before posting my question here but I didn't find any reason for my error.
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
Probably you have to post the relevant code.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Another dialog hosts a pointer as a private data member:
ModelessDlg * m_pModelessDlg;
When creating the modeless dialog:
if(m_pModelessDlg)<br />
{<br />
m_pModelessDlg->SetForegroundWindow();<br />
}<br />
else<br />
{<br />
m_pModelessDlg = new ModelessDlg(this);<br />
m_pModelessDlg->Create(ModelessDlg::IDD, this);<br />
m_pModelessDlg->ShowWindow(SW_SHOW);<br />
}
There is a CProgressCtrl on this dialog. Does it matter if I create and display the modeless dialog without initializing the progress control? I think I should be able to see an empty progress bar on that dialog.
As an alternative, instead of using ShowWindow, I tried to set the Visible property of this modeless dialog to Yes. Then I got the modeless dialog displayed correctly (With all controls displayed including the progress ctrl). BUT another error has occurred: the modeless dialog was kind of in a No responding state for 3 seconds. Then I could move the dialog around but could not switch the focus to the parent dialog. In addition when moving the dialog around, a great number of fake dialogs were made like a tail to the original one(When happening, the available memory of my computer was still big enough)
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
Are you doing anything in the dialog's OnInitDialog() method?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
No. I even didn't override the OnInitDialog method. I have tried to override it and only do CDialog::OnInitDialog(); in it. The situation has not been changed. The modeless dialog is stuck in a no respond state. I can't get the focus of the parent dialog.
Toe the line
Thread the needle
Think outside of the box
|
|
|
|
|
Hi,
I wrote a simple program uisng CEvent Synchronization if execute my application. the threade upto 1986 after it shows the following error
unhandled exception at 0x00418552 in WorkerThreads.exe: 0xC0000005: Access violation writing location 0x00000028.
may i know the reason
Regards
Jothi.G
|
|
|
|
|
Use your debugger to find the exact readon. It can be for so many reasons that it is impossible to tell you.
Jothi.G81 wrote: the threade upto 1986
What do you mean, you have 1986 threads in your application ?
|
|
|
|
|
Wow, 1900 threads
Why do you create so much threads ? This will bring your system to its knees and your application will spend more time switching between the threads instead of doing actual work.
And, BTW, you really should use your debugger (press F5 to start and F9 to set breakpoints).
|
|
|
|
|
with lots of threads I don't expect a debugger to be useful at all; I would make sure
ALL error conditions get checked everywhere, all anomalies and some tracing get logged,
then compare the logs of a couple of runs. That should create the possibility to
formulate some hypothesis.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Before execut my application the task manager shown 498 threads
after that my application will create upto 2448 exactly, so totally 248-498 = 1950 threads created by my application.
then it shown a message like this
Unhandled exception at 0x00418552 in WorkerThreads.exe: 0xC0000005: Access violation writing location 0x00000028.
May i know the reason about this error
Regards
Jothi.G
|
|
|
|