How to convert Cardinal numbers into Ordinal ones - c++

Is there an easy way to convert the number 1, 2, 3, ... to "1st", "2nd", "3rd", ..., and in such a way that I can give the function a language and have it return me the correct form for the language I'm targeting? Either standard C++ (stl or boost OK), MFC or ATL, win32 api or a small, single-purpose and free library that I can download from somewhere. Thanks.

I doubt whether it is possible at all, since in many languages this form will depend on the context, like gender or case of the noun it describes and different languages will require different kind of context information to allow to determine the correct form.
EDIT: E.g. in Polish it is "5-ta klasa" (5th class) vs. "5-ty miesiąc" (5th month) vs. "w 5-tym miesiącu" (in the 5th month).

I've spend quite some time researching this, because it's too large a project to get right myself. It looks like the ICU library is the only one that provides this functionality in a somewhat comprehensive way (http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html). I'm not too keen on incorporating a huge library like that, though. I'll keep on looking and I'm still open to suggestions.

Did you look up the CLDR repository on the Unicode site? I don't know if they have this kind of thing but since it's probably the most comprehensive locale data repository out there, it's probably worth a look.
http://www.unicode.org/cldr/

Since you use C++, I assume you could use GNU gettext (there's a Windows port as well) for all the translations, or at least get the idea how they solved it. Here's the relevant manual page on plural forms that explains the problem (which you already found, but in more detail) and their solution:
http://www.gnu.org/software/automake/manual/gettext/Plural-forms.html

Here is the piece of code on CodeProject that does the job. Haven't tried it on my own.

Related

Where are `Malformed and `Uchar defined?

NB: This question is more about how to navigate through/decipher OCaml source code, than about the specifics of the items listed below.1
I've come across the expressions
`Malformed
`Uchar
in some OCaml source code, but I can't find definitions for them.
Are they somehow built-in, i.e. part of the standard language?
If not, where does one go when one wants to find out such definitions? (Actually, it's not clear to me whether the leading backtick is part of the name or is a separate operator.)
1I'm having a horrible time making sense of OCaml source code. Usually I have no problem picking up new programming languages, but with OCaml I can't find anything where I expect to find it, and when I do find something it comes along with 100x more undefined/differently-defined/outright bizarre names/concepts, so it's a losing battle.
It's a polymorphic variant, you can read about it in the OCaml manual here
For other basic language features you would not understand, well, you should first read the whole part 1 of the manual
Here is how the manual is organized:
Quick introduction through the language
The whole language (two parts: first the legacy language, then the features added through time)
The standards shell tools manpages (compilers, interprets, ocamlbuild etc.)
The standard libraries
I noted from your previous questions that you use non-standard tools, such as opam and several libraries, make sure to check their documentations and note that some can extend your syntax.
I have to admit that the doc generally assumes people reading it already know about the concepts presented but you don't need to use them at first to master the language.
Happy hacking !
It is a polymorhic variant, that do bot need to be defined before usage. It is something between lisp's symbols and common ADT's. You think of it as a syntactically lighter version version of common ADTs.
I would suggest you to use utop as a playing ground to learn OCaml. Indeed, it is a damn easy language, it looks like to me that you have atacked it from a wrong side, or working with a program that is obfuscated.

C++ logging library that allows HTML/CSS output?

i'm looking for a C++ library, like boost.log or pantheios that easily allows for html/css-formatted log output, maybe with some fancy jquery. i'm sure this can be done with boost.log, but i suppose in that case i'd have to spend days until understanding how to program one owns sink, programming and then debugging it.
i wonder if there is some library that already can produce a html log directly from c++. apart from this it must work cross-platform and support utf-16 (or something alike to allow for non-english output).
any good suggestions?
I haven't used this, though I've seen people reference it. It has threading support and has an HTML layout class, not sure if the latter is sufficient.
log4cxx
http://www.codeproject.com/Articles/3297/HTML-logger-portable-and-thread-safe
Or, somewhat less robust--not easily portable--and something I haven't used, but with a slightly different feature set:
http://www.kikijiki.com/en/2012/01/10/cpp-html-log-class/

replace c++ with go + swig

I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's a mistake in my question: I assumed cgo could also be used to access c++ code but that's not possible. Instead you need to use SWIG.
The go faq says "The cgo program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries. "
my question:
Is it possible to access high-level c++ frameworks such as QT with SWIG + Go and get productive? I'd like to use Go as a "scripting language" to utilize c++ libraries.
Have you any experience with go and swig? Are there pitfalls I have to be aware of?
Update/Answer: I've asked this over IRC too and I think the question is solved:
SWIG is a rather clean way of interfacing c++ code from other languages. Sadly matching the types of c++ to something like go can be very complex and in most cases you have to specify the mapping yourself. That means that SWIG is a good way to leverage an existing codebase to reuse already written algorithms. However mapping a library like Qt to go will take you ages. Mind it's surely possible but you don't want to do it.
Those of you that came here for gui programming with go might want try go-gtk or the go version of wxWidgets.
Is it possible? Yes.
Can it be done in a reasonably short period of time? No.
If you go back and look at other projects that have taken large frameworks and tried to put an abstraction layer on it, you'll find most are "incomplete". You can probably make a fairly good start and get some initial wrappers in place, but generally even the work to get the simple cases solved takes time when there is a lot of underlying code to wrap, even with automated tools (which help, but are never a complete solution). And then... you get to the nasty remaining 10% that will take you forever (ok, a really really long time at least). And then think about how it's a changing target in the first place. Qt, for example, is about to release the next major rewrite.
Generally, it's safest to stick to the framework language that the framework was designed for. Though many have language extensions within the project itself. For example, for Qt you should check out QML, which provides (among many other things) a javascript binding to Qt. Sort of. But it might meet your "scripting" requirement.
A relevant update on this issue: it is now possible to interact with C++ using cgo with this CL, which is merged for Go 1.2. It is limited, however, to C-like functions calls, and classes, methods and C++ goodies are not supported (yet, I hope).

What Linux Full Text Indexing Tool Has A Good C++ API?

I'm looking to add full text indexing to a Linux desktop application written in C++. I am thinking that the easiest way to do this would be to call an existing library or utility. This article reviews various open source utilities available for the Gnome and KDE desktops; metatracker, recoll and stigi are all written in C++ so they each seem reasonable. But I cannot find any notable documentation on how to use them as libraries or through an API. I could, instead, use something like Clucene or Xapian, which are generic full text indexing libraries. They seem more straightforward but if I used them, I'd have to implement my own indexing daemon, an unappealing prospect.
Also, Xesam seems to be the latest thing, does anyone have any evidence that it works?
So, does anyone have experience using any of the applications or libraries? How did you use it and what documentation was useful?
I used CLucene, which you mentioned (and also Lucene.NET), and found it to be pretty good.
There's also Strigi which AFAIK works with Xesam and is the default used in KDE.
After further looking around, I found and worked with Recol. It believe that it has the best C++ interface to a full text search engine, in this case Xapian.
It is important to realize that clucene and Xapian are both highly complex libraries designed primarily for multi-user server applications. Cutting them down to a level appropriate for a client-system is not easy. If I remember correctly, Strigi has a complex, pure C interface which isn't adapted.
Clucene also doesn't seem to be that actively maintained currently and Xapian seems to be maintained. But the thing is the existence of recol, which allows you to index particular files without the massive, massive setup that raw Xapian or clucene requires - creating your own "stemming" set is not normally desirable, etc.

Applications development with D language

For those who had developed applications with D,
which libraries did you use to build your application?
those libraries were good documented?
did you use Tango?
do you feel that D is ready to build big applications?
which IDE did you use? Descent maybe?
Note that any C library can be used with D, as D fully supports the C ABI. D has some limited support for C++ libraries, though not C++ template libraries.
I used tango libraries + dfl and a bit of my own.
Tango documentation is excellent. DFL not bad.
Yes I did use tango then but tried phobos at first.
Ready for big apps? depends on what you mean. In production use I have only used it for frontends and updaters.
So far I've only used vim to code and entice to design gui because I couldn't find the right ide for me.
I generally don't work on top of libs (aside from the std lib) as I tend to do very low level stuff, so "none"
I use Phobos, but that's because I'm lazy and that's all that was around when I started.
I'm using it in a commercial app. But we are very much in the early adopter segment.
Descent is really making good progress. However for the stuff I do (very heavy template work) it is not up to the task. However for most things that should not be nearly as much of an issue.
Tango
Yes, albeit a little more examples could be good
Yes
Yes, I think so. But if the programmers are used to full-fledged IDEs (MS Visual Studio), they probably wouldn't like D,
I use a small custom-made Scintilla-based editor, with options to build applications using bud, dsss or dmd.
I use Tango, Jive stacktrace, dconstructor, dunit, and selfmock. I maintain the last three of those, though.
Tango has reasonable documentation. I've run into a few places where it had less documentation than I needed; in these cases, I've made tickets requesting better documentation. Jive doesn't require documentation. I hope the others I use have reasonable documentation; I've been working on that a fair bit.
Yes, I use Tango.
You can create large applications in FORTRAN; D is better. The main issue is library support. Things like cryptography aren't well supported in D, as far as I know. But it's been pretty easy to find everything that I have needed. Anything else, you can probably write a wrapper around an existing library in C without much trouble.
I usually use vim, but now I'm switching to Descent. Its autocompletion is far better than Vim's.
DFL (GUI), Decent (for OpenGL), CUDA (GPGPU)
DFL was decently documented, but lacked cross referencing. Decent/ CUDA are mainly C wrappers, though D made making nice internal API for CUDA very easy.
No, I've been using Phobos
Yes, though there are certain types of big applications which would be much faster to write in another language.
I've been using Code::blocks for my principal IDE and Entice for GUI design.
Other than the core library (in my case, Tango), I'm not using any external libs.
Tango documentation is decent. It's a large library, and I'd say there's documentation for about 80% of it, off the top of my head. And, of those documented classes, I'd say about 80% of them are complete and correct. Given the size of the library, the amount of documentation is impressive. But it's still not quite where it needs to be. In order to really use Tango right now, you have to read the source code (which is clean and well-written).
I don't know whether D is ready for big applications. My application is pretty small, and I'm pretty happy with it. From a language-design perspective, I prefer C# (or Java, to a lesser extent). In comparison, the D language design strikes me as somewhat clunky and awkward. Really, the only reason I chose D for this project was because A) I needed to be able to compile my code to a DLL which could be linked by an arbitrary third party; B) I needed my code to be portable between Win, Lin, and Mac; and C) I didn't want to write in C/C++.
I'm using Descent (an Eclipse IDE plugin). It provides reasonably good syntax highlighting and project navigation. Auto-complete still leaves much to be desired, and the integration with a "builder" like dsss is still lacking. But it's better than notepad :)
Mainly those I develop myself - SDWF and Stewart's Utility Library.
I hope so.
No.
Yes, though I'm not sure that libraries and IDE support are quite ready yet. And D isn't quite ready for significant third-party implementation, which might play a part in reaching this stage.
I do most of my editing in TextPad. Which admittedly isn't fully compatible with D (two missing syntax highlighting features, and doesn't support Unicode), but it works.
Code blocks seems to support D.