Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Locale.cc

Go to the documentation of this file.
00001 /*
00002  * Locale.cc
00003  *
00004  * Smalltalk like class library for C++
00005  * System locale accessor.
00006  *
00007  * Copyright (c) 2006 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #include <stlib/Locale.h>
00025 #include <stlib/Character.h>
00026 #include <stlib/String.h>
00027 
00028 #include <langinfo.h>
00029 #include <stdio.h>
00030 
00031 namespace Core {
00032 
00033 Locale *Locale::_current = nil;
00034 
00035 Locale::Locale(locale_t cLocale)
00036 {
00037     locale_def = cLocale;
00038 }
00039 
00040 /* Instance accessing protocol */
00041 Locale *Locale::current(void)
00042 {
00043     if (_current == nil) {
00044         /* In case the requested locale doesn't exist, setlocale
00045          * (and newlocale respectively) returns NULL.
00046          */
00047         _current = new Locale(newlocale(LC_ALL_MASK, setlocale(LC_ALL, ""), NULL));
00048     }
00049     return _current;
00050 }
00051 
00052 /* Class accessing protocol */
00053 String *Locale::className(void) const
00054 {
00055     return new String("Locale");
00056 }
00057 
00058 /* Accessing protocol */
00059 Character *Locale::decimalPoint(void)
00060 {
00061     if (locale_def == NULL) return Character::value('.');
00062     return Character::value(nl_langinfo_l(DECIMAL_POINT, locale_def)[0]);
00063 }
00064 
00065 String *Locale::encoding(void)
00066 {
00067     if (locale_def == NULL) return new String("ISO-8859-1");
00068     return new String(nl_langinfo_l(CODESET, locale_def));
00069 }
00070 
00071 }; /* namespace Core */

Generated on Mon Nov 27 09:47:55 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2