Ascii.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Ascii.hpp 2938 2011-10-23 19:39:11Z yanweignss $"
00002 
00008 #ifndef GPSTK_ASCII_HPP
00009 #define GPSTK_ASCII_HPP
00010 
00011 //============================================================================
00012 //
00013 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //
00029 //  Wei Yan - Chinese Academy of Sciences . 2011
00030 //
00031 //============================================================================
00032 
00033 #include "gpstkplatform.h"
00034 
00035 namespace gpstk
00036 {
00051    class Ascii    
00052    {
00053    public:
00054       enum CharacterProperties
00056       {
00057          ACP_CONTROL  = 0x0001,
00058          ACP_SPACE    = 0x0002,
00059          ACP_PUNCT    = 0x0004,
00060          ACP_DIGIT    = 0x0008,
00061          ACP_HEXDIGIT = 0x0010,
00062          ACP_ALPHA    = 0x0020,
00063          ACP_LOWER    = 0x0040,
00064          ACP_UPPER    = 0x0080,
00065          ACP_GRAPH    = 0x0100,
00066          ACP_PRINT    = 0x0200
00067       };
00068 
00069       static int properties(int ch);
00070 
00071       static bool hasSomeProperties(int ch, int properties);
00072 
00073       static bool hasProperties(int ch, int properties);
00074 
00075       static bool isAscii(int ch);
00076 
00077       static bool isSpace(int ch);
00078 
00079       static bool isDigit(int ch);
00080 
00081       static bool isHexDigit(int ch);
00082 
00083       static bool isPunct(int ch);
00084 
00085       static bool isAlpha(int ch);
00086 
00087       static bool isAlphaNumeric(int ch);
00088 
00089       static bool isLower(int ch);
00090 
00091       static bool isUpper(int ch);
00092 
00093       static int toLower(int ch);
00094 
00095       static int toUpper(int ch);
00096 
00097    private:
00098       static const int CHARACTER_PROPERTIES[128];
00099 
00100    }; // End of class 'Ascii'
00101 
00102 
00103    //
00104    // inlines
00105    //
00106    inline int Ascii::properties(int ch)
00107    {
00108       if (isAscii(ch)) 
00109          return CHARACTER_PROPERTIES[ch];
00110       else
00111          return 0;
00112    }
00113 
00114 
00115    inline bool Ascii::isAscii(int ch)
00116    {
00117       return (static_cast<UInt32>(ch) & 0xFFFFFF80) == 0;
00118    }
00119 
00120 
00121    inline bool Ascii::hasProperties(int ch, int props)
00122    {
00123       return (properties(ch) & props) == props;
00124    }
00125 
00126 
00127    inline bool Ascii::hasSomeProperties(int ch, int props)
00128    {
00129       return (properties(ch) & props) != 0;
00130    }
00131 
00132 
00133    inline bool Ascii::isSpace(int ch)
00134    {
00135       return hasProperties(ch, ACP_SPACE);
00136    }
00137 
00138 
00139    inline bool Ascii::isDigit(int ch)
00140    {
00141       return hasProperties(ch, ACP_DIGIT);
00142    }
00143 
00144 
00145    inline bool Ascii::isHexDigit(int ch)
00146    {
00147       return hasProperties(ch, ACP_HEXDIGIT);
00148    }
00149 
00150 
00151    inline bool Ascii::isPunct(int ch)
00152    {
00153       return hasProperties(ch, ACP_PUNCT);
00154    }
00155 
00156 
00157    inline bool Ascii::isAlpha(int ch)
00158    {
00159       return hasProperties(ch, ACP_ALPHA);
00160    }
00161 
00162 
00163    inline bool Ascii::isAlphaNumeric(int ch)
00164    {
00165       return hasSomeProperties(ch, ACP_ALPHA | ACP_DIGIT);
00166    }
00167 
00168 
00169    inline bool Ascii::isLower(int ch)
00170    {
00171       return hasProperties(ch, ACP_LOWER);
00172    }
00173 
00174 
00175    inline bool Ascii::isUpper(int ch)
00176    {
00177       return hasProperties(ch, ACP_UPPER);
00178    }
00179 
00180 
00181    inline int Ascii::toLower(int ch)
00182    {
00183       if (isUpper(ch)) return ch + 32;
00184       else return ch;
00185    }
00186 
00187 
00188    inline int Ascii::toUpper(int ch)
00189    {
00190       if (isLower(ch)) return ch - 32;
00191       else return ch;
00192    }
00193 
00194 }   // End of namespace gpstk
00195 
00196 
00197 #endif  //GPSTK_ASCII_HPP
00198 

Generated on Tue May 22 03:30:56 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1