flString.c

Go to the documentation of this file.
00001 #if FL_STRING != 0
00002 
00003 #if FL_INCLUDE_ALL_C == 0
00004 #include "flString.h"
00005 #include "flMemory.h"
00006 
00007 #if FL_DEBUG != 0
00008 #include "flDebug.h"
00009 #endif
00010 #endif
00011 
00012 u32 ustrLen(u16* inStr) {
00013      if(!inStr)
00014           return 0;
00015      u32 tempOut, i;
00016      for(i = 0, tempOut = 0; inStr[i]; i++)
00017           tempOut++;
00018      return tempOut;
00019 }
00020 
00021 u32 strLen(u8* inStr) {
00022      if(!inStr)
00023           return 0;
00024      u32 tempOut, i;
00025      for(i = 0, tempOut = 0; inStr[i]; i++)
00026           tempOut++;
00027      return tempOut;
00028 }
00029 
00030 u16* strToUstr(u8* inStr) {
00031      if(!inStr)
00032           return NULL;
00033      u16* tempOut = (u16*)memAlloc((strLen(inStr) + 1) << 1);
00034      if(!tempOut) {
00035           #if FL_DEBUG_WARNING != 0
00036           debugWarning("Cannot convert string to unicode.\nProbably out of memory.");
00037           #endif
00038           return NULL;
00039      }
00040      u32 i;
00041      for(i = 0; inStr[i]; i++)
00042           tempOut[i] = (u16)inStr[i];
00043      tempOut[i] = 0;
00044      return tempOut;
00045 }
00046 
00047 u8* ustrToStr(u16* inStr) {
00048      if(!inStr)
00049           return NULL;
00050      u8* tempOut = (u8*)memAlloc(ustrLen(inStr) + 1);
00051      if(!tempOut) {
00052           #if FL_DEBUG_WARNING != 0
00053           debugWarning("Cannot convert string to ascii.\nProbably out of memory.");
00054           #endif
00055           return NULL;
00056      }
00057      u32 i;
00058      for(i = 0; inStr[i]; i++)
00059           tempOut[i] = (u8)(inStr[i] & 0x00FF);
00060      tempOut[i] = 0;
00061      return tempOut;
00062 }
00063 
00064 u8* strCopy(u8* inStr) {
00065      if(!inStr)
00066           return NULL;
00067      u8* tempOut = (u8*)memAlloc(strLen(inStr) + 1);
00068      if(!tempOut) {
00069           #if FL_DEBUG_WARNING != 0
00070           debugWarning("Cannot copy string.\nProbably out of memory.");
00071           #endif
00072           return NULL;
00073      }
00074      memCopy(tempOut, inStr, (strLen(inStr) + 1));
00075      return tempOut;
00076 }
00077 
00078 u8* strCopyTo(u8* inStrDest, u8* inStrSrc) {
00079      if(!inStrSrc) {
00080           #if FL_DEBUG_WARNING != 0
00081           debugWarning("Trying to copy NULL string.");
00082           #endif
00083           return NULL;
00084      }
00085      if(!inStrDest) {
00086           #if FL_DEBUG_WARNING != 0
00087           debugWarning("Trying to copy string to a NULL destination.");
00088           #endif
00089           return NULL;
00090      }
00091      memCopy(inStrDest, inStrSrc, (strLen(inStrSrc) + 1));
00092      return inStrDest;
00093 }
00094 
00095 u16* ustrCopy(u16* inStr) {
00096      if(!inStr)
00097           return NULL;
00098      u16* tempOut = (u16*)memAlloc((ustrLen(inStr) + 1)  << 1);
00099      if(!tempOut) {
00100           #if FL_DEBUG_WARNING != 0
00101           debugWarning("Cannot copy unicode string.\nProbably out of memory.");
00102           #endif
00103           return NULL;
00104      }
00105      memCopy(tempOut, inStr, ((ustrLen(inStr) + 1) << 1));
00106      return tempOut;
00107 }
00108 
00109 u16* ustrCopyTo(u16* inStrDest, u16* inStrSrc) {
00110      if(!inStrSrc) {
00111           #if FL_DEBUG_WARNING != 0
00112           debugWarning("Trying to copy NULL string.");
00113           #endif
00114           return NULL;
00115      }
00116      if(!inStrDest) {
00117           #if FL_DEBUG_WARNING != 0
00118           debugWarning("Trying to copy string to a NULL destination.");
00119           #endif
00120           return NULL;
00121      }
00122      memCopy(inStrDest, inStrSrc, ((ustrLen(inStrSrc) + 1) << 1));
00123      return inStrDest;
00124 }
00125 
00126 u8* strLCase(u8* inStr) {
00127      u32 i;
00128      for(i = 0; inStr[i]; i++) {
00129           if((inStr[i] >= 'A') && (inStr[i] <= 'Z'))
00130                inStr[i] += ('a' - 'A');
00131      }
00132      return inStr;
00133 }
00134 
00135 u8* strUCase(u8* inStr) {
00136      u32 i;
00137      for(i = 0; inStr[i]; i++) {
00138           if((inStr[i] >= 'a') && (inStr[i] <= 'z'))
00139                inStr[i] -= ('a' - 'A');
00140      }
00141      return inStr;
00142 }
00143 
00144 u16* ustrLCase(u16* inStr) {
00145      u32 i;
00146      for(i = 0; inStr[i]; i++) {
00147           if((inStr[i] >= 'A') && (inStr[i] <= 'Z'))
00148                inStr[i] += ('a' - 'A');
00149      }
00150      return inStr;
00151 }
00152 
00153 u16* ustrUCase(u16* inStr) {
00154      u32 i;
00155      for(i = 0; inStr[i]; i++) {
00156           if((inStr[i] >= 'a') && (inStr[i] <= 'z'))
00157                inStr[i] -= ('a' - 'A');
00158      }
00159      return inStr;
00160 }
00161 
00162 s32 strCmp(u8* inStr0, u8* inStr1) {
00163      if(inStr0 == inStr1)
00164           return 0;
00165      if(!inStr0) {
00166           if(!inStr1)
00167                return 0;
00168           return (0 - (s32)inStr1[0]);
00169      }
00170      if(!inStr1)
00171           return ((s32)inStr1[1]);
00172      u32 i = 0;
00173      while((inStr0[i] == inStr1[i]) && inStr0[i])
00174           i++;
00175      return ((s32)inStr0[i] - (s32)inStr1[i]);
00176 }
00177 
00178 s32 ustrCmp(u16* inStr0, u16* inStr1) {
00179      if(inStr0 == inStr1)
00180           return 0;
00181      if(!inStr0) {
00182           if(!inStr1)
00183                return 0;
00184           return (0 - (s32)inStr1[0]);
00185      }
00186      if(!inStr1)
00187           return ((s32)inStr1[1]);
00188      u32 i = 0;
00189      while((inStr0[i] == inStr1[i]) && inStr0[i])
00190           i++;
00191      return ((s32)inStr0[i] - (s32)inStr1[i]);
00192 }
00193 
00194 int strToInt(u8* inStr) {
00195      if(!inStr || (inStr[0] == 0))
00196           return 0;
00197      int tempOut = 0;
00198      u8* tempStrPtr = inStr;
00199      bool tempNeg = false;
00200      if(tempStrPtr[0] == '-') {
00201           tempNeg = true;
00202           tempStrPtr++;
00203      } else if(tempStrPtr[0] == '+') {
00204           tempStrPtr++;
00205      }
00206      while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9')) {
00207            tempOut *= 10;
00208            tempOut += (int)(tempStrPtr[0] - '0');
00209            tempStrPtr++;
00210      }
00211      if(tempNeg)
00212            return -tempOut;
00213      return tempOut;
00214 }
00215 
00216 float strToFloat(u8* inStr) {
00217      if(!inStr || (inStr[0] == 0))
00218           return 0.0f;
00219      float tempOut = 0.0f;
00220      u8* tempStrPtr = inStr;
00221      bool tempNeg = false;
00222      if(tempStrPtr[0] == '-') {
00223           tempNeg = true;
00224           tempStrPtr++;
00225      } else if(tempStrPtr[0] == '+') {
00226           tempStrPtr++;
00227      }
00228      while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9')) {
00229            tempOut *= 10.0f;
00230            tempOut += (float)(tempStrPtr[0] - '0');
00231            tempStrPtr++;
00232      }
00233      if(tempStrPtr[0] == '.') {
00234           tempStrPtr++;
00235           int i = 1;
00236           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9')) {
00237                 if(tempStrPtr[0] != '0')
00238                      tempOut += ((float)(tempStrPtr[0] - '0') / powf(10.0f, (float)i));
00239                 tempStrPtr++; i++;
00240           }
00241      }
00242      if((tempStrPtr[0] == 'e') || (tempStrPtr[0] == 'E')) {
00243           tempStrPtr++;
00244           bool tempExpNeg = false;
00245           int tempExp = 0;
00246           if(tempStrPtr[0] == '-') {
00247                tempStrPtr++;
00248                tempExpNeg = true;
00249           } else if(tempStrPtr[0] == '+') {
00250                tempStrPtr++;
00251           }
00252           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9')) {
00253                tempExp *= 10;
00254                tempExp += (int)(tempStrPtr[0] - '0');
00255                tempStrPtr++;
00256           }
00257           if(tempExpNeg)
00258                tempOut /= powf(10.0f, (float)tempExp);
00259           else
00260                tempOut *= powf(10.0f, (float)tempExp);
00261      }
00262      if(tempNeg)
00263            return -tempOut;
00264      return tempOut;
00265 }
00266 
00267 vect2f strToVect2f(u8* inStr) {
00268      vect2f tempOut;
00269      tempOut.x = 0.0f;
00270      tempOut.y = 0.0f;
00271      
00272      if(!inStr || (inStr[0] == 0))
00273           return tempOut;
00274 
00275      u8* tempStrPtr = inStr;
00276      
00277      while((tempStrPtr[0] == ' ') || (tempStrPtr[0] == ASCII_TAB) || (tempStrPtr[0] == '('))
00278           tempStrPtr++;
00279      if(tempStrPtr[0] == 0)
00280           return tempOut;
00281      tempOut.x = strToFloat(tempStrPtr);
00282      if((tempStrPtr[0] == '+') || (tempStrPtr[0] == '-'))
00283           tempStrPtr++;
00284      while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00285           tempStrPtr++;
00286      if(tempStrPtr[0] == '.') {
00287           tempStrPtr++;
00288           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00289                tempStrPtr++;
00290      }
00291      if((tempStrPtr[0] == 'e') || (tempStrPtr[0] == 'E')) {
00292           tempStrPtr++;
00293           if((tempStrPtr[0] == '-') || (tempStrPtr[0] == '+'))
00294                tempStrPtr++;
00295           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00296                tempStrPtr++;
00297      }
00298      
00299      while((tempStrPtr[0] == ' ') || (tempStrPtr[0] == ASCII_TAB) || (tempStrPtr[0] == ','))
00300           tempStrPtr++;
00301      if(tempStrPtr[0] == 0)
00302           return tempOut;
00303      tempOut.y = strToFloat(tempStrPtr);
00304      
00305      return tempOut;
00306 }
00307 
00308 vect3f strToVect3f(u8* inStr) {
00309      vect3f tempOut;
00310      tempOut.x = 0.0f;
00311      tempOut.y = 0.0f;
00312      tempOut.z = 0.0f;
00313      
00314      if(!inStr || (inStr[0] == 0))
00315           return tempOut;
00316      
00317      u8* tempStrPtr = inStr;
00318      
00319      while((tempStrPtr[0] == ' ') || (tempStrPtr[0] == ASCII_TAB) || (tempStrPtr[0] == '('))
00320           tempStrPtr++;
00321      if(tempStrPtr[0] == 0)
00322           return tempOut;
00323      tempOut.x = strToFloat(tempStrPtr);
00324      if((tempStrPtr[0] == '+') || (tempStrPtr[0] == '-'))
00325           tempStrPtr++;
00326      while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00327           tempStrPtr++;
00328      if(tempStrPtr[0] == '.') {
00329           tempStrPtr++;
00330           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00331                tempStrPtr++;
00332      }
00333      if((tempStrPtr[0] == 'e') || (tempStrPtr[0] == 'E')) {
00334           tempStrPtr++;
00335           if((tempStrPtr[0] == '-') || (tempStrPtr[0] == '+'))
00336                tempStrPtr++;
00337           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00338                tempStrPtr++;
00339      }
00340      
00341      while((tempStrPtr[0] == ' ') || (tempStrPtr[0] == ASCII_TAB) || (tempStrPtr[0] == ','))
00342           tempStrPtr++;
00343      if(tempStrPtr[0] == 0)
00344           return tempOut;
00345      tempOut.y = strToFloat(tempStrPtr);
00346      if((tempStrPtr[0] == '+') || (tempStrPtr[0] == '-'))
00347           tempStrPtr++;
00348      while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00349           tempStrPtr++;
00350      if(tempStrPtr[0] == '.') {
00351           tempStrPtr++;
00352           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00353                tempStrPtr++;
00354      }
00355      if((tempStrPtr[0] == 'e') || (tempStrPtr[0] == 'E')) {
00356           tempStrPtr++;
00357           if((tempStrPtr[0] == '-') || (tempStrPtr[0] == '+'))
00358                tempStrPtr++;
00359           while((tempStrPtr[0] >= '0') && (tempStrPtr[0] <= '9'))
00360                tempStrPtr++;
00361      }
00362      
00363      while((tempStrPtr[0] == ' ') || (tempStrPtr[0] == ASCII_TAB) || (tempStrPtr[0] == ','))
00364           tempStrPtr++;
00365      if(tempStrPtr[0] == 0)
00366           return tempOut;
00367      tempOut.z = strToFloat(tempStrPtr);
00368      
00369      return tempOut;
00370 }
00371 
00372 #endif

Generated on Wed Sep 5 19:04:01 2007 for funcLib by  doxygen 1.5.1