Clocale
lastmod 2018-08-17created 2015-05-078 edits
The C language supports localization specific settings, such as culture-specific date formats or country-specific currency symbols.
Category
MBCS vs WCS
This page looks at conversion between character sets. String type conversion is easy to think of as simply converting between char and wchar_t, but you must keep the concept of character sets in mind.
- MBCS is not a single encoding.
- The data type that holds MBCS is char
- UTF-8 is also stored in char, just like MBCS.
- Wide Char is a single encoding scheme. (UTF-16 or UTF-32 depending on the compiler)
- Wide Char is stored in wchar_t.
- In other words, wchar_t holds only strings encoded in UTF-16 or UTF-32.
LC Category
=== LANG=C === In conclusion, setting LANG to "C" means turning off the locale, and "C" is indeed a locale name defined in the standard.
The locale name is "C" because it is specified as follows in 7.11.1.1 The setlocale function of the C language standard. (It seems to be "C" because it comes from the C language standard)
Simple Example
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{
/* Locale is set to "C" before this. This call sets it
to the "current locale" by reading environment variables: */
setlocale(LC_ALL, "");
const struct lconv * const currentlocale = localeconv();
printf("In the current locale, the default currency symbol is: %s\n",
currentlocale->currency_symbol);
return EXIT_SUCCESS;
}
See also
Favorite site
- Wikipedia (en) C localization functions
- cppreference.com: Localization support
- cplusplus.com C localization library
- [Recommended] C/C++: Detecting initial consonants (choseong) in Unicode (UTF-16)
- What exactly is the 'developing with Unicode' that Windows Visual C/C++ developers talk about?
- wchar_t and encoding
- libc 6.1 Introduction to Extended Characters
- Using UTF-8 as the internal representation for strings in C and C++ with Visual Studio 1
- Windows Codepage Interactions with Standard C/C++ filenames?
- UNICODE & MBCS
- Dark Programmer: How to use setlocale
- Locale settings
- C/C++ string type conversion
MSDN
References
-
Using_UTF-8_as_the_internal_representation_for_strings_in_C_and_C++_with_Visual_Studio-Nubaria_Blog.pdf ↩