inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/tosu
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_tosu
00005 #define inlib_tosu
00006 
00007 // have a "sprintf(%u)" without #include.
00008 // It is used in os.
00009 
00010 namespace inlib {
00011 
00012 inline void toss(const char* a_from,char a_s[],unsigned int& a_l) {
00013   char* s = (char*)a_from;
00014   a_l = 0;
00015   char* pos = a_s;
00016   while(*s) {
00017     *pos++ = *s;
00018     a_l++;
00019     s++;
00020   }
00021   *pos++ = 0;
00022 }
00023 
00024 template <class T>  //T must be an unsigned number type.
00025 inline void tosu(T a_i,char a_s[],unsigned int& a_l) {
00026   //assume a_s is sufficently allocated (32 is ok).
00027   a_l = 0;
00028  {char* pos = a_s;
00029   T i = a_i;
00030   while(true) {
00031     if(i<=9) {*pos++ = '0'+i;a_l++;*pos++=0;break;}
00032     T r = i % 10;
00033     *pos++ = '0'+r;
00034     a_l++;
00035     i = i/10;
00036   }}
00037   //strrev(s);
00038  {unsigned int hl = a_l/2;
00039   char* beg = a_s;
00040   char* end = a_s+a_l-1;
00041   for(unsigned int i=0;i<hl;i++) {
00042     char c = *end;
00043     *end = *beg;      
00044     *beg = c;
00045     beg++;end--;  
00046   }}
00047 }
00048 
00049 }
00050 
00051 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines