cel_misc.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00004 //
00005 // (C) 2003-2006 Celartem Technology Inc. All rights reserved.
00006 //----------------------------------------------------------------------------
00007 
00008 #ifndef _cel_misc_h_
00009 #define _cel_misc_h_
00010 
00011 #include "cel_types.h"
00012 #include "cel_memory.h"
00013 #include "cel_exception.h"
00014 #include "cel_unicode.h"
00015 
00016 namespace Celartem
00017 {
00018     class String;
00019 
00023     enum YesNo
00024     {
00025         no = 0,  
00026         yes = 1  
00027     };
00028 
00029     struct Decimal
00030     {
00039         static inline int _1digit(int n)
00040         {
00041             return n + '0';
00042         }
00043         
00050         static inline int _1char(int chr)
00051         {
00052             if(chr >= '0' && chr <= '9') return chr - '0';
00053             return -10000;
00054         }
00055         
00066         static int fromStrToInt(const UChar1 *str, size_t length)
00067         {
00068             int n = 0;
00069             for(size_t i = 0; i < length; i++)
00070             {
00071                 n = n * 10 + _1char(*str++);
00072                 if(n < 0)
00073                     celThrow(errDataBroken);
00074             }
00075             return n;
00076         }
00077     };
00078 
00082     struct Hex
00083     {
00092         static inline int _1digit(int n)
00093         {
00094             return n < 10 ? n + '0' : n - 10 + 'a';
00095         }
00096 
00103         static inline int _1char(int chr)
00104         {
00105             if(chr >= '0' && chr <= '9') return chr - '0';
00106             if(chr >= 'a' && chr <= 'f') return chr - 'a' + 10;
00107             if(chr >= 'A' && chr <= 'F') return chr - 'A' + 10;
00108             return -10000;
00109         }
00110 
00121         static int fromStrToInt(const UChar1 *str, size_t length)
00122         {
00123             int n = 0;
00124             for(size_t i = 0; i < length; i++)
00125             {
00126                 n = n * 16 + _1char(*str++);
00127                 if(n < 0)
00128                     celThrow(errDataBroken);
00129             }
00130             return n;
00131         }
00132 
00140         static inline void fromByte(UChar1 *buffer, u8 n)
00141         {
00142             buffer[0] = _1digit(n >> 4);
00143             buffer[1] = _1digit(n & 15);
00144         }
00145 
00159         static String toString(const u8 *bin, size_t size, const String& sep);
00160         
00169         static void fromString(SimpleArray<u8>& outBin, const String& str);
00170         
00183         static size_t fromString(
00184             u8* outBin, size_t inSize, const String& str);
00185     };
00186 
00187 }  // namespace Celartem
00188 
00189 #endif // _cel_misc_h_

This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:21:54 2008.