Skip to content

Clocale

The C language supports localization specific settings, such as culture-specific date formats or country-specific currency symbols.

Category

MBCS vs WCS

이 문서에서는 문자셋 간의 변환에 대해서 살펴보도록 하겠습니다. 문자열 타입 변환 이라하면 단순히 char와 wchar_t간의 변환이라고 생각하기 쉬운데 문자셋이란 개념을 꼭 생각하셔야 합니다.

  • MBCS는 한가지 인코딩이 아니다.
  • MBCS를 담는 자료형은 char다
  • UTF-8도 MBCS와 같은 char에 저장한다.
  • Wide Char는 한가지 인코딩 방식이다. (컴파일러에 따라 UTF-16이거나 UTF-32)
  • Wide Char는 wchar_t에 담는다.
  • 다시 말하면 wchar_t에는 UTF-16이나 UTF-32로 인코딩 된 문자열만 담긴다.

LC Category

=== LANG=C === 결론은 LANG 을 "C" 로 설정하는건 locale 을 끄는 의미이고 "C" 는 표준에 있는 locale name 이 맞다고 한다.

locale name 이 "C" 인것은 C 언어 표준중 7.11.1.1 The setlocale function 에 다음과 같이 지정되어 있기때문이다. (C 언어 표준에 있는 내용이라 "C" 인것 같다)

"A value of "C" for locale specifies the minimal environment for C translation;"

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

MSDN

References


  1. Using_UTF-8_as_the_internal_representation_for_strings_in_C_and_C++_with_Visual_Studio-Nubaria_Blog.pdf