00001 #ifdef WIN32
00002 #pragma warning(disable : 4786 )
00003 #endif
00004 #include "CSHelper.h"
00005
00006
00007 int CSHelper::convert(const char* start_string, int radix)
00008 {
00009 char* string;
00010 char *pointer;
00011 int value=0;
00012 int tmp=0;
00013 int multiplier;
00014 int loop;
00015 int exponent=0;
00016 if ((start_string==0)||(radix==0))
00017 {
00018 return 0;
00019 }
00020 pointer=string=strdup(start_string);
00021
00022
00023
00024 while (*pointer!=(char)0)
00025 {
00026 if ((*pointer>='a')&&(*pointer<='z'))
00027 {
00028 *pointer+=('A'-'a');
00029 }
00030 pointer++;
00031 }
00032
00033
00034 pointer = string;
00035 while (*(pointer+1)!=0)
00036 {
00037 pointer++;
00038 }
00039
00040 do
00041 {
00042 tmp=*pointer;
00043 if (tmp>'9')
00044 {
00045 tmp-=('A'-10);
00046 }
00047 else
00048 {
00049 tmp-='0';
00050 }
00051
00052 if (tmp>=radix)
00053 {
00054 free(string);
00055 return 0;
00056 }
00057
00058
00059 multiplier=1;
00060 for (loop=0;loop<exponent;loop++)
00061 {
00062 multiplier*=radix;
00063 }
00064 value+=tmp*multiplier;
00065
00066
00067 exponent++;
00068 }
00069 while(pointer--!=string);
00070
00071 free(string);
00072 return value;
00073 }
00074
00075
00076 bool CSHelper::replace(std::string &text, const std::string &oldValue, const std::string &newValue)
00077 {
00078 std::string newText;
00079 std::string rest;
00080 int posStart = strstr(text.c_str(), oldValue.c_str()) - text.c_str();
00081 if (posStart != -(int) (text.c_str()))
00082 {
00083 newText = text.substr(0, posStart);
00084 }
00085 else
00086 {
00087 return false;
00088 }
00089 newText = newText + newValue;
00090
00091 int len = oldValue.size();
00092 if (posStart+len < text.size())
00093 {
00094 newText = newText + text.substr(posStart + len, text.size() - (posStart + len) );
00095 }
00096 text = newText;
00097 return true;
00098 }
00099
00100
00101
00102
00103
00104 int CSHelper::colorPercent(int color, int percent)
00105 {
00106 int r = (((color)&0xff0000)>>16);
00107 int g = (((color)&0x00ff00)>>8);
00108 int b = (((color)&0x0000ff));
00109 int colorPercent;
00110 colorPercent = (((r*percent)/100)<<16);
00111 colorPercent += (((g*percent)/100)<<8);
00112 colorPercent += ( (b*percent)/100);
00113 return colorPercent;
00114 }
00115