001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024:
025:
026:
027:
028:
029:
030:
031:
032:
033:
034:
035:
036:
037:
038:
039:
040:
041:
042:
043:
044:
045:
046:
047:
048:
049:
050:
051:
052:
053:
054:
055:
056:
057:
058:
059:
060:
061:
062:
063:
064:
065:
066:
067:
068:
069:
070:
071:
072:
073:
074:
075:
076:
077:
078:
079:
080:
081:
082:
083:
084:
085:
086:
087:
088:
089:
090:
091:
092:
093:
094:
095:
096:
097:
098:
099:
100:
101:
102:






































































































/*
* Copyright (c), Zeriph Enterprises
* All rights reserved.
*
* Contributor(s):
* Zechariah Perez, omni (at) zeriph (dot) com
*
* THIS SOFTWARE IS PROVIDED BY ZERIPH AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ZERIPH AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(OMNI_CHAR_T_HPP)
#define OMNI_CHAR_T_HPP 1
#include <omni/defs/global.hpp>
#include <cctype>
#include <cwctype>
#include <cstdlib>

// defines the string types to use for different string processing
#if defined(OMNI_UNICODE)
    #define OMNI_CHAR_T wchar_t     // Defines a wide character type
#else
    #define OMNI_CHAR_T char     // Defines a standard character type
#endif

namespace omni {
    typedef OMNI_CHAR_T char_t;

    namespace char_util {
        inline bool is_digit(char c)
        { return (std::isdigit(c) != 0); }
        
        inline bool is_digit(wchar_t c)
        { return (std::iswdigit(c) != 0); }
        
        inline bool is_alpha(char c)
        { return (std::isalpha(c) != 0); }
        
        inline bool is_alpha(wchar_t c)
        { return (std::iswalpha(c) != 0); }
        
        template < typename std_char_t >
        std_char_t to_lower(std_char_t c)
        { OMNI_ERR_RETV_FW("Invalid template parameter specified.", omni::exceptions::invalid_template_type(), c) }
        
        template <>
        inline char to_lower<char>(char c)
        { return static_cast<char>(std::tolower(c)); }
        
        template <>
        inline wchar_t to_lower<wchar_t>(wchar_t c)
        { return std::towlower(c); }
        
        template < typename std_char_t >
        std_char_t to_upper(std_char_t c)
        { OMNI_ERR_RETV_FW("Invalid template parameter specified.", omni::exceptions::invalid_template_type(), c) }
        
        template <>
        inline char to_upper<char>(char c)
        { return static_cast<char>(std::toupper(c)); }
        
        template <>
        inline wchar_t to_upper<wchar_t>(wchar_t c)
        { return std::towupper(c); }
        
        namespace helpers {
            inline bool is_1or0(char v)
            { return v == '0' || v == '1'; }
            
            inline bool is_1or0(wchar_t v)
            { return v == L'0' || v == L'1'; }
            
            inline bool is_nde(char v)
            { return (v == '-' || v == '.' || v == ','); }
            
            inline bool is_nde(wchar_t v)
            { return (v == L'-' || v == L'.' || v == L','); }
            
            inline bool is_de(char v)
            { return (v == '.' || v == ','); }
            
            inline bool is_de(wchar_t v)
            { return (v == L'.' || v == L','); }
            
            inline bool is_neg(char v)
            { return (v == '-'); }
            
            inline bool is_neg(wchar_t v)
            { return (v == L'-'); }
        }
    }
}

#endif // OMNI_CHAR_T_HPP