locale.h ¶
λ΄λΉ : νμ€μ
location specific information λ₯Ό setting νλλ° μ μ©ν λΌμ΄λΈλ¬λ¦¬
λ§€ν¬λ‘ ¶
#define LC_ALL (integer constant expression) λͺ¨λ μΉ΄ν
κ³ λ¦¬μ λν λ‘μΌμΌ μ€μ μ μν νκ²½λ³μμ΄λ€
#define LC_COLLATE (integer constant expression) μ€νΈλ§(string)μ μ λ ¬ μμ(sort order λλ collation)λ₯Ό μν λ‘μΌμΌ μ€μ μ μν΄ μ¬μ©
#define LC_CTYPE (integer constant expression) λ¬Έμ λΆλ₯(μνλ²³, μ«μ, νκΈ λλ μλ¬Έμ, λλ¬Έμ λ±λ±), λ³ν, λμλ¬Έμ λΉκ΅μ μν λ‘μΌμΌ μ€μ μ μλ―Έ
#define LC_MONETARY (integer constant expression) κΈμ‘ νν(μ²λ¨μ κ΅¬λΆ λ¬Έμ, μμμ λ¬Έμ, κΈμ‘ νμ λ¬Έμ, κ·Έ μμΉ λ±)μ μν λ‘μΌμΌ μ€μ
#define LC_NUMERIC (integer constant expression) κΈμ‘μ΄ μλ μ«μ νν(μ²λ¨μ, μμμ , μ«μ κ·Έλ£Ήν λ±)μ μν λ‘μΌμΌ μ€μ
#define LC_TIME (integer constant expression) μκ°κ³Ό λ μ§μ νν(λ , μ, μΌμ λν λͺ μΉ λ±)μ μν λ‘μΌμΌ μ€μ μλ₯Ό λ€μ΄ strftime(), strptime()
#define NULL (either 0, 0L, or (void*)0) (0 in C++)
#define LC_COLLATE (integer constant expression) μ€νΈλ§(string)μ μ λ ¬ μμ(sort order λλ collation)λ₯Ό μν λ‘μΌμΌ μ€μ μ μν΄ μ¬μ©
#define LC_CTYPE (integer constant expression) λ¬Έμ λΆλ₯(μνλ²³, μ«μ, νκΈ λλ μλ¬Έμ, λλ¬Έμ λ±λ±), λ³ν, λμλ¬Έμ λΉκ΅μ μν λ‘μΌμΌ μ€μ μ μλ―Έ
#define LC_MONETARY (integer constant expression) κΈμ‘ νν(μ²λ¨μ κ΅¬λΆ λ¬Έμ, μμμ λ¬Έμ, κΈμ‘ νμ λ¬Έμ, κ·Έ μμΉ λ±)μ μν λ‘μΌμΌ μ€μ
#define LC_NUMERIC (integer constant expression) κΈμ‘μ΄ μλ μ«μ νν(μ²λ¨μ, μμμ , μ«μ κ·Έλ£Ήν λ±)μ μν λ‘μΌμΌ μ€μ
#define LC_TIME (integer constant expression) μκ°κ³Ό λ μ§μ νν(λ , μ, μΌμ λν λͺ μΉ λ±)μ μν λ‘μΌμΌ μ€μ μλ₯Ό λ€μ΄ strftime(), strptime()
#define NULL (either 0, 0L, or (void*)0) (0 in C++)
lconv ꡬ쑰체 ¶
struct lconv {
ELEMENT "C" LOCALE LOCALE CATEGORY
char* currency_symbol; "" LC_MONETARY
char* decimal_point; "." LC_NUMERIC
char* grouping; "" LC_NUMERIC
char* int_curr_symbol; "" LC_MONETARY
char* mon_decimal_point; "" LC_MONETARY
char* mon_grouping; "" LC_MONETARY
char* mon_thousands_sep; "" LC_MONETARY
char* negative_sign; "" LC_MONETARY
char* positive_sign; "" LC_MONETARY
char* thousands_sep; "" LC_NUMERIC
char frac_digits; CHAR_MAX LC_MONETARY
char int_frac_digits; CHAR_MAX LC_MONETARY
char n_cs_precedes; CHAR_MAX LC_MONETARY
char n_sep_by_space; CHAR_MAX LC_MONETARY
char n_sign_posn; CHAR_MAX LC_MONETARY
char p_cs_precedes; CHAR_MAX LC_MONETARY
char p_sep_by_space; CHAR_MAX LC_MONETARY
char p_sign_posn; CHAR_MAX LC_MONETARY
};
ELEMENT "C" LOCALE LOCALE CATEGORY
char* currency_symbol; "" LC_MONETARY
char* decimal_point; "." LC_NUMERIC
char* grouping; "" LC_NUMERIC
char* int_curr_symbol; "" LC_MONETARY
char* mon_decimal_point; "" LC_MONETARY
char* mon_grouping; "" LC_MONETARY
char* mon_thousands_sep; "" LC_MONETARY
char* negative_sign; "" LC_MONETARY
char* positive_sign; "" LC_MONETARY
char* thousands_sep; "" LC_NUMERIC
char frac_digits; CHAR_MAX LC_MONETARY
char int_frac_digits; CHAR_MAX LC_MONETARY
char n_cs_precedes; CHAR_MAX LC_MONETARY
char n_sep_by_space; CHAR_MAX LC_MONETARY
char n_sign_posn; CHAR_MAX LC_MONETARY
char p_cs_precedes; CHAR_MAX LC_MONETARY
char p_sep_by_space; CHAR_MAX LC_MONETARY
char p_sign_posn; CHAR_MAX LC_MONETARY
};
ν¨μ ¶
ν¨μ | μ€λͺ |
struct lconv* localeconv(void); | lconv ꡬ쑰체λ₯Ό νμ¬μ location setting μ λ§κ² κ°μ μ€μ νλ€. |
char* setlocale(int category, const char* locale); | categoryμ λν΄ λ‘μΌμΌ localeμ μ€μ νκ³ (λ¬Όλ‘ , μ¬μ© κ°λ₯ν λ‘μΌμΌμΈ κ²½μ°), μ€μ λ λ‘μΌμΌκ°μ 리ν΄. |
setLocale μ μ ¶
~cpp #include <stddef.h> #include <locale.h> #include <stdlib.h> #include <string.h> void with_other_locale (char *new_locale, void (*subroutine) (int), int argument) { char *old_locale, *saved_locale; /* νμ¬ λ‘μΌμΌλͺ μ μμλΈλ€. */ old_locale = setlocale (LC_ALL, NULL); /* setlocale()μ μ¬νΈμΆ μν΄ λ³κ²½λ κ²μ λλΉν΄ λ‘μΌμΌ μ΄λ¦μ 미리 볡μ¬ν΄ λλ€. */ saved_locale = strdup (old_locale); if (saved_locale == NULL) fatal ("Out of memory"); /* λ‘μΌμΌμ λ³κ²½νκ³ subroutineμ μννλ€. */ setlocale (LC_ALL, new_locale); (*subroutine) (argument); /* μλμ λ‘μΌμΌλ‘ 볡κ·νλ€. */ setlocale (LC_ALL, saved_locale); free (saved_locale); }