Re: Caseless String
Lourens Veen wrote:
Why not
enum Language {
EN_gb,
EN_us,
DE_de,
/* ... */
DE_ch,
ES_es,
FR_fr,
NL_nl
};
class LString {
public:
LString(Language l, const std::wstring & s);
/* ... */
private:
Language l;
std::wstring s;
};
Or alternatively, use narrow characters and add an encoding.
Of course, the real fun is in these two:
LString translate(const LString & s, Language l);
bool operator==(const LString & s1, const LString & s2);
It is intuitively apparent that your method is better - it solves the
issue of intercontext transfer of strings via serialization. If the
spoken language is encoded only as a compile-time type, the string
cannot carry this with. But if the language is encoded in the string
itself, then the string becomes self-descriptive. This also eliminates
a lot of code-bloat from templates/namespaces/etc. Encoding the type
will also help with James Kanze's ?==SS example, as well as umlauted
versus expanded-and-naked sequences, etc.
I am still in favor of operator == over a separate comparison function.
All of my (non-STL) containers require operator == to be defined for
elements. For embedded language encoding, this case, operator == would
have to be hefty.
The question then becomes: "What state is required for a string to be
completely self-descriptive while allowing for meaningful operations
with other strings?"
On the matter of encoding the language: I was thinking about 32-bits
not being enough for 1-bit per language, but a simple
one-code-per-language being not ideal either. Certainly, it would give
2^32=4,294,967,296 codes for languages, but there might be cases where
you'd want to ask if the language is "derived from Latin", etc. This
situation would be an opportunity where prime numbers for taxonomic
indication might be used. See:
http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/755
34d6b8bfd1e54/43354be8708ba77c?lnk=st&q=prime+numbers+for+taxonomic&rnum=1&h
l=en#43354be8708ba77c
For example:
enum Language
{ GREEK = 2, LATIN = 3, SANSKRIT=7, ITALIAN = LATIN*31, etc.}
You tempt me to revisit this problem, but I know my limits. However,
if someone else were to pursue this, I would enthusiastically provide
beer and cheer!;)
Regards,
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]